- <template>
- <div>
- <v-btn
- v-show="
- getProfile &&
- getProfile.bluemediaPaymentConfig.gpay.redirect &&
- !applePayAvailable()
- "
- :disabled="!isOnline"
- outlined
- class="googleButton text-none pr-2 pl-4 mb-1"
- x-large
- @click="send(GOOGLE)"
- >
- <div class="content_button_wrapper">
- <img
- src="@/assets/donation/google_pay-mark_800_gray.svg"
- alt="Logo Google Pay"
- />
- Google Pay
- </div>
- <v-icon>chevron_right</v-icon>
- </v-btn>
- <v-btn
- v-show="
- getProfile &&
- getProfile.bluemediaPaymentConfig.apple.redirect &&
- applePayAvailable()
- "
- outlined
- class="googleButton text-none pr-2 pl-4"
- :disabled="!isOnline"
- x-large
- @click="send(APPLE)"
- >
- <div class="content_button_wrapper">
- <img
- src="@/assets/donation/apple_pay_payment_mark.svg"
- alt="Apple Pay"
- />
- Apple Pay
- </div>
- <v-icon>chevron_right</v-icon>
- </v-btn>
- <v-btn
- v-if="getProfile && getProfile.bluemediaPaymentConfig.card.redirect"
- :outlined="canMakePayment"
- :disabled="!isOnline"
- width="100%"
- large
- class="f-payment f-normal-case card_button text-none pr-2 pl-4 my-4"
- :class="canMakePayment ? 'f-outlined' : 'f-normal'"
- x-large
- @click="makePaymentInFrame()"
- >
- <div class="content_button_wrapper">
- <div class="icon_wrapper mr-6">
- <v-icon class="ma-0" color="#3c4043" left>credit_card</v-icon>
- </div>
- {{ $t(`${userPath}.donateWithCard`) }}
- </div>
- <v-icon>chevron_right</v-icon>
- </v-btn>
- <v-btn
- :disabled="!isOnline"
- outlined
- class="googleButton text-none pr-2 pl-4"
- x-large
- @click="send(BM)"
- >
- <div class="content_button_wrapper">
- <img
- class="bm_icon"
- src="@/assets/donation/bluemedia/logo_blue_media.png"
- alt="Logo Bluemedia"
- />
- {{ $t(`${userPath}.donateWithBm`) }}
- </div>
- <v-icon>chevron_right</v-icon>
- </v-btn>
- </div>
- </template>
- <script>
- import '@/plugins/checkout'
- import {
- bluemediaPaymentIntentCard,
- bluemediaPaymentIntentGooglePay
- } from '@/services/bluemedia/paymentIntents'
- import '@google-pay/button-element'
- import { mapMutations, mapGetters, mapState } from 'vuex'
- import {
- GOOGLE_CONFIG,
- BM_GATEWAY,
- EXTERNAL_WALLETS_TYPES,
- PAYMENT_OPERATORS
- } from '@/utils/macros/payments'
- import { fetchMerchant } from '@/services/bluemedia/merchantScript'
- import UsersDB from '@/firebase/users-db'
- export default {
- name: 'BluemediaButtons',
- props: {
- disableButtons: {
- type: Boolean
- },
- teamName: {
- type: String
- },
- price: {
- type: String,
- default: ''
- },
- boxId: {
- type: Number
- },
- currency: {
- type: String
- },
- canMakePayment: {
- type: Boolean
- }
- },
- data: () => ({
- successLink: '',
- snackbar: '',
- basePath: 'tournaments.tournamentForm',
- paymentPending: false,
- ...BM_GATEWAY,
- userPath: 'layout.donation.user',
- alertPath: 'layout.donation.alerts',
- merchantInfo: {},
- googleButtonSettings: {
- environment: 'PRODUCTION',
- buttonType: 'pay',
- buttonColor: 'black',
- buttonSize: 'static'
- },
- googleMerchantId: '',
- googleConfig: GOOGLE_CONFIG
- }),
- beforeMount() {
- window.onpageshow = async event => {
- if (event.persisted) {
- this.$emit('change-loader', true)
- window.location.reload()
- }
- }
- },
- computed: {
- ...mapGetters('donation', ['getProfile']),
- ...mapState('app', { isOnline: 'networkOnLine' })
- },
- destroyed() {
- window.onpageshow = null
- },
- async mounted() {
- const link = this.$route.params.userLink.toLowerCase()
- const field = link.length === 4 ? 'link' : 'customLink'
- await new UsersDB().find(field, link).then(async user => {
- this.setProfile(user)
- })
- if (!this.getProfile?.bluemediaPaymentConfig?.gpay?.redirect) {
- const {
- merchantOrigin,
- merchantName,
- authJwt,
- merchantId,
- acceptorId
- } = await fetchMerchant()
- this.googleConfig.merchantInfo = {
- merchantOrigin,
- merchantName,
- authJwt,
- merchantId
- }
- this.googleConfig.allowedPaymentMethods[0].tokenizationSpecification.parameters = {
- gateway: PAYMENT_OPERATORS.BLUEMEDIA,
- gatewayMerchantId: acceptorId.toString()
- }
- }
- window.PayBmCheckout.transactionDeclined = async () => {
- this.paymentPending = false
- this.$emit('change-loader', false)
- }
- window.PayBmCheckout.transactionSuccess = async () => {
- this.$router.push(`/service/bluemedia/transaction${this.successLink}`)
- this.paymentPending = false
- this.$emit('change-loader', false)
- }
- window.PayBmCheckout.transactionError = async () => {
- this.paymentPending = false
- this.$emit('change-loader', false)
- }
- },
- methods: {
- ...mapMutations('donation', ['setAlertMessage', 'setProfile']),
- async makePaymentInFrame() {
- this.$emit('change-loader', true)
- if (this.getProfile.bluemediaPaymentConfig.cardsEnabled) {
- await this.makePaymentCard()
- } else {
- this.setAlertMessage(
- this.$t(`${this.alertPath}.unavailablePaymentMethod`)
- )
- }
- this.$emit('change-loader', false)
- },
- applePayAvailable() {
- return window.ApplePaySession !== undefined
- },
- onError: event => {
- console.error('error', event.error)
- },
- onPaymentDataAuthorized: () => {
- return {
- transactionState: 'SUCCESS'
- }
- },
- onReadyToPayChange(e) {},
- async onLoadPaymentData({ detail }) {
- const { token } = detail.paymentMethodData.tokenizationData
- await this.makePayment(
- this.GOOGLE,
- JSON.stringify(token),
- EXTERNAL_WALLETS_TYPES.google
- )
- },
- async send(gatewayId) {
- this.$emit('change-loader', true)
- if (
- [this.BM].includes(gatewayId) &&
- this.getProfile.bluemediaPaymentConfig.otherMethodsEnabled
- ) {
- await this.makePayment(gatewayId)
- } else if (
- [this.APPLE, this.GOOGLE].includes(gatewayId) &&
- this.getProfile.bluemediaPaymentConfig.cardsEnabled
- ) {
- await this.makePayment(gatewayId)
- } else {
- this.setAlertMessage(
- this.$t(`${this.alertPath}.unavailablePaymentMethod`)
- )
- }
- this.$emit('change-loader', false)
- },
- async makePayment(
- gatewayId,
- token,
- type = EXTERNAL_WALLETS_TYPES.appleAndGoogle
- ) {
- this.paymentPending = true
- const response = await bluemediaPaymentIntentGooglePay({
- amount: this.price,
- currency: this.currency.toUpperCase(),
- token,
- type,
- uid: this.getProfile.uid,
- link: this.getProfile.link,
- gatewayId
- })
- window.location.href = response
- },
- async makePaymentCard() {
- this.paymentPending = true
- const result = await bluemediaPaymentIntentCard({
- amount: this.price,
- currency: this.currency.toUpperCase(),
- type: 'card',
- uid: this.getProfile.uid,
- link: this.getProfile.link
- })
- this.successLink = result.success
- window.PayBmCheckout.transactionStartByUrl(result.url)
- }
- }
- }
- </script>
- <style lang="scss">
- @import '@/theme/variables.scss';
- #google-pay-button {
- height: 52px;
- width: 100%;
- div {
- height: 100%;
- .gpay-button {
- width: 100%;
- height: 100%;
- }
- }
- }
- .bm_icon {
- border: 1px solid black;
- border-radius: 3px;
- }
- .card_button {
- display: flex;
- justify-content: space-between;
- background-color: white !important;
- box-shadow: none;
- border: 1px solid $color-secondary-dark;
- border-color: $color-secondary-dark !important;
- color: $color-secondary-dark !important;
- }
- .content_button_wrapper {
- display: flex;
- align-items: center;
- }
- .icon_wrapper {
- border: 1px solid #3c4043;
- background-color: white !important;
- border-radius: 4px;
- height: 32px;
- width: 50px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .content_button_wrapper {
- display: flex;
- align-items: center;
- }
- .googleButton {
- width: 100%;
- border-color: $color-secondary-dark !important;
- color: $color-secondary-dark !important;
- img {
- width: auto;
- height: 32px;
- margin-right: 24px !important;
- }
- div {
- width: 100% !important;
- height: 100% !important;
- button {
- width: 100% !important;
- height: 100% !important;
- }
- }
- }
- </style>