triniwiz / triniwiz/nativescript-plugins

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

Open
#115 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
87
Forks
57
Avg merge
1h 36m
Merged PRs (30d)
4

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in index.ios.js at StripePaymentDelegate.prototype.paymentContextDidCreatePaymentResultCompletion and trace how capturePayment rejection reaches the completion callback. Verify the iOS payment flow reports an error rather than success when capturePayment throws, and check the related payment delegate behavior for regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.