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

[IOS] requestPayment does not throw error if occure #134

Closed
kefahB opened this issue Aug 17, 2022 · 3 comments
Closed

[IOS] requestPayment does not throw error if occure #134

kefahB opened this issue Aug 17, 2022 · 3 comments
Labels
bug Something isn't working Stripe

Comments

@kefahB
Copy link
Contributor

kefahB commented Aug 17, 2022

Hi @triniwiz

In IOS standard implementation, requestPayment will return always success (via the listener) even if createPaymentSession dont return a payment intent at all!

I've tried to reject a promise into capturePayment method and it return always success.

@triniwiz triniwiz added bug Something isn't working Stripe labels Aug 17, 2022
@kefahB
Copy link
Contributor Author

kefahB commented Sep 14, 2022

Hi @triniwiz

I did have a little bit time to investigate this issu .. the error come from here, the Completion handler is set to null instead of handling error.

I've tested and it work

StripePaymentDelegate.prototype.paymentContextDidCreatePaymentResultCompletion = function (paymentContext, paymentResult, completion) {
        StripeStandardConfig.shared.backendAPI
            .capturePayment(paymentResult.paymentMethod.stripeId, paymentContext.paymentAmount, createShippingMethod(paymentContext), createAddress(paymentContext.shippingAddress))
            .then(function (value) {
            completion(STPPaymentStatus.Success, null);
        })
            .catch(function (e) {
            // this is the error
            // completion(null createError('PaymentError', 100, e)); 
            completion(STPPaymentStatus.Error, createError('PaymentError', 100, e));
        });
    };

@kefahB
Copy link
Contributor Author

kefahB commented Sep 14, 2022

According to the Stripe docs we should handle 3 type of responses :

  • STPPaymentStatusSuccess
  • STPPaymentStatusError
  • STPPaymentStatusUserCancellation

For instance only the success is handled by this plugin, I suggest to update this part for IOS as below if you agree ?

PS: I tested all 3 cases and it work as expected

StripePaymentDelegate.prototype.paymentContextDidCreatePaymentResultCompletion = function (paymentContext, paymentResult, completion) {
        StripeStandardConfig.shared.backendAPI
            .capturePayment(paymentResult.paymentMethod.stripeId, paymentContext.paymentAmount, createShippingMethod(paymentContext), createAddress(paymentContext.shippingAddress))
            .then(function (value) {
                if(!value._native.lastPaymentError || value._native.lastPaymentError == "undefined") {
                    completion(STPPaymentStatus.Success, null);
                    return
                }
                completion(STPPaymentStatus.UserCancellation, null);
            })
            .catch(function (e) {
            console.error("ERROR >> : paymentContextDidCreatePaymentResultCompletion : ", e);
            completion(STPPaymentStatus.Error, createError('PaymentError', 100, e));
        });
    };

@kefahB kefahB mentioned this issue Sep 14, 2022
@kefahB
Copy link
Contributor Author

kefahB commented Sep 14, 2022

fixed with #141

@kefahB kefahB closed this as completed Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stripe
Projects
None yet
Development

No branches or pull requests

2 participants