triniwiz / nativescript-plugins

Apache License 2.0
80 stars 50 forks source link

[nativescript-stripe][ios] onPaymentSuccess gets called even when capturePayment handler throws error #115

Open msn444 opened 2 years ago

msn444 commented 2 years ago

Calls to the user-implemented capturePayment handler that result in error end up triggering onPaymentSuccess listener.

I believe this is due to the following code in index.ios.js:

    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) {
            completion(null, createError('PaymentError', 100, e));
        });
    };

Passing null to completion() results in StripePaymentDelegate.prototype.paymentContextDidFinishWithError = function (paymentContext, status, error) being called with status equal to 0, which is the value of STPPaymentStatus.Success. The following change resolves the issue for me:

            .catch(function (e) {
            completion(STPPaymentStatus.Error, createError('PaymentError', 100, e));

Version: 8.0.2