Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events lauched multiple times after error #6

Open
storm23 opened this issue May 17, 2024 · 2 comments
Open

Events lauched multiple times after error #6

storm23 opened this issue May 17, 2024 · 2 comments
Assignees

Comments

@storm23
Copy link

storm23 commented May 17, 2024

I'm using @mangopay/checkout-sdk in a vue.js 2 environment.

If an error occurs during payin with CB, users can retry a payment. If they do, each event is launched twice. Then three times if they retry etc ...

I tried to reload my vuejs component after an error, but I have the same problem.

See below my vuejs2 component.

I've tried with all package versions, even 1.1.6-alpha.4

<script type="text/ecmascript-6">
import { CheckoutSdk } from '@mangopay/checkout-sdk';
import mangoService from '@/services/mango'
export default {

    props: {
        amount: Number,
    },
    mounted() {

        this.initMangoPaySDK()
    },
    data() {

        return {
            mangopaySdk: null,
            currency: 'EUR',
            mangoTermsAccepted: true
        }
    },
    methods: {
        async createCardRegistration(event) {

            try {

                let response = await mangoService.callToMyAPI(event)
                let cardRegistrationInfos = response.data

                return cardRegistrationInfos
            }
            catch (error) {

                this.$emit('error', error)
            }
        },
        async createPayment(event) {

            try {

                let depositCreatedResponse = await mangoService.callToMyAPI(event)
                let depositPreAuthData = depositCreatedResponse.data
            
                return depositPreAuthData
            }
            catch (error) {

                this.$emit('error', error)
            }
        },
        error(event) {

            this.$emit('error', event.detail.error.ResultMessage)
        },
        async paymentComplete(event) {

            let status = event.detail.Status
            try {

                //DO STUFF
            }
            catch (error) {

                this.$emit('error', error)
            }

            this.$emit('paymentComplete', status)
        },
        async initMangoPaySDK() {


            const options = {
                clientId: process.env.VUE_APP_MANGO_CLIENT_ID,
                profilingMerchantId: process.env.VUE_APP_MANGO_PROFILING_MERCHANT_ID,
                environment: this.isProduction ? 'PRODUCTION' : 'SANDBOX',
                supportedCardBrands: ['VISA', 'MASTERCARD', 'CB'],
                amount: {
                    'currency': this.currency,
                    'value': this.amount
                },
                paymentMethods: [
                    {
                        type: 'card',
                        options: {
                            onCreateCardRegistration: this.createCardRegistration,
                            onCreatePayment: this.createPayment
                        }
                    }
                ]
            }

            try {

                this.mangopaySdk = await CheckoutSdk.loadCheckoutSdk('#container', options)
                if (!this.mangopaySdk) {
                    
                    throw new Error('Failed to load MangopayCheckoutSdk');
                }
            }
            catch (error) {

                console.log(error)
            }

            this.mangopaySdk.on('paymentComplete', this.paymentComplete)
            this.mangopaySdk.on('error', this.error)
        }
    },
    computed: {

        isProduction() {

            return process.env.VUE_APP_ENVIRONMENT === 'production'
        }
    }
}
</script>
<template>
    <div id="checkoutForm">
        <div id="container"></div>
    </div>
</template>

I tried many things to properly reload the component and refresh events if there is an error. For example, in the view :

Implementation of the component :

<MangoCardForm 
      :key="mangoCardFormKey"
      @error="handleError" 
      @paymentComplete="handlePaymentComplete"
      :amount="price" 
      @createCardRegistration="handleCreateCardRegistration"
  />

In "handleError" function :

 methods: {

    handleError(error) {

        this.mangoCardFormKey = this.mangoCardFormKey + 1
    },
....

This solution refresh the component, but "old" events are still attached to the MangoPaySDK.

@denysyakovenko
Copy link
Contributor

denysyakovenko commented May 17, 2024

Hi @storm23
Thanks for having interest to Mandgopay Checkout SDK!

I've tried to reproduce the issue you've described but unfortunately haven't been able to. I've created another example that uses vue2 with pretty much the same code that you have. Could you please try it and give a feedback if you still have the same issue?

@storm23
Copy link
Author

storm23 commented May 21, 2024

Hello.
In your example, the component doesn't handle 4xx errors. if "createCardRegistration" method fire a 4xx error, the user has to refresh the page.
I would like to auto-refresh the page automatically. But the "error" method is not launched when a 4xx error occurs.

In order to test that, in createCardRegistration, try to fetch a "not found" ressource, the "error" method will not be fired, so You can't handle this error.

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants