stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.12k stars 980 forks source link

STPPaymentHandler crashed when confirm PaymentIntent (automatic flow) #1242

Closed letrongtriet closed 5 years ago

letrongtriet commented 5 years ago

Summary

App crashed right away when try to confirm a payment intent (created by Backend)

Card used: 4000000000003253

Code to reproduce

extension WhimWheelViewController: STPAuthenticationContext {
func authenticationPresentingViewController() -> UIViewController {
        return self
    }

    private func book(_ booking: Booking, paymentSourceId: PaymentSourceId, choices: [ConfiguratorChoice]?) {
        BookingManager.shared.bookV2(booking: booking, paymentSourceId: paymentSourceId, successfulCallback: { [weak self] object in
            guard let self = self else { return }

            guard let clientSecret = object.paymentParameters?.clientSecret else {
                return
            }

            self.confirmPayment(with: clientSecret)

            }, errorCallback: { [weak self] error in
                log.error(error)
                self?.stopAnimating()
        })
    }

    private func confirmPayment(with clientSecret: String) {
        let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
        paymentIntentParams.returnURL = WhimNetworkPantry.Payment.stripeRedirectURL

        let paymentManager = STPPaymentHandler.shared()

        var stripeClient: STPAPIClient {
            let key = WhimNetworkManager.shared.environment.isTest ? WhimNetworkManager.shared.stripeTestApiKey : WhimNetworkManager.shared.stripeLiveApiKey
            return STPAPIClient(publishableKey: key)
        }

        paymentManager.apiClient = stripeClient

        paymentManager.confirmPayment(paymentIntentParams, with: self, completion: { (status, paymentIntent, error) in
            self.close()

            if let error = error {
                log.error(error)
            }

            switch status {
            case .failed:
                log.debug("++++++ failed")
            case .canceled:
                log.debug("++++++ canceled")
            case .succeeded:
                log.debug("++++++ succeeded")
            @unknown default:
                log.debug("++++++ @unknown default")
            }
        })
    }
}

iOS version

12.3.1

Installation method

Cocoapods

SDK version

16.0.0

Other information

Crash log:

2019-07-23 10:28:51.206562+0300 whim-ios[1669:643384] -[TVg isChallengeMandated]: unrecognized selector sent to instance 0x10ddb17a0
2019-07-23 10:30:06.638493+0300 whim-ios[1669:643384] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TVg isChallengeMandated]: unrecognized selector sent to instance 0x10ddb17a0'
*** First throw call stack:
(0x1a716a3a8 0x1a636fd00 0x1a70829f8 0x1a716fd54 0x1a7171b50 0x106e031d8 0x106dadfb8 0x106db1e70 0x109fdf1f8 0x109fe0778 0x109fee158 0x1a70fa024 0x1a70f4cd4 0x1a70f4254 0x1a9333d8c 0x1d443c4c0 0x102941cd4 0x1a6bb0fd8)
libc++abi.dylib: terminating with uncaught exception of type NSException

Last step before crash:

import "STPDispatchFunctions.h"

void stpDispatchToMainThreadIfNecessary(dispatch_block_t block) {
    if ([NSThread isMainThread]) {
        block();
    }
    else {
        dispatch_async(dispatch_get_main_queue(), block);
    }
}
tombates-pdr commented 5 years ago

@letrongtriet thanks for raising this, I was literally just having this issue and was about to raise it myself. The crash seems to be happening in STPPaymentHandler.m L:473 for me

I am attempting to use the following card: 4000000000003220

tombates-pdr commented 5 years ago

Digging a little deeper and it looks like it could be the object that is returned from: STDSAuthenticationResponseFromJSON being called in: STP3DS2AuthenticateResponse.h on line: 32

The authenticationResponseJSON that it is attempting to use to create the TVg object does, however, contain acsChallengeMandated = Y;

yuki-stripe commented 5 years ago

Thanks for reporting this!

I haven't been able to reproduce this crash so far. Are you able to breakpoint on line 473 in STPPaymentHandler and inspect the aRes variable there? I'm wondering what it looks like in the debugger, and if it responds to isChallengeMandated.

letrongtriet commented 5 years ago

@yuki-stripe Please see the attachment below for all information

NOTE:

Screen Shot 2019-07-23 at 21 09 27
yuki-stripe commented 5 years ago

Thanks @letrongtriet! We've identified an issue with our code obfuscation, and are working on a fix.

yuki-stripe commented 5 years ago

@letrongtriet @DrTomBates This should be fixed on 5cfa3dc83e25706a0a5f4a03bcac8805a9467041 - you can point your Podfile to that commit until the next version is released. Please let me know if that resolves this issue!

letrongtriet commented 5 years ago

@yuki-stripe It did fix the problem 👍 Thanks for you super fast support.

tombates-pdr commented 5 years ago

@yuki-stripe This looks like it has solved the issue for me as well, thanks!

denglei022 commented 5 years ago

@yuki-stripe It didn't help me...

yuki-stripe commented 5 years ago

@denglei022 Can you make a new issue with your crash and details?

The fix for this is in v16.0.1.

denglei022 commented 5 years ago

Thanks.That's OK.I used the new version

发自我的iPhone

------------------ Original ------------------ From: Yuki Tokuhiro notifications@github.com Date: Fri,Jul 26,2019 7:00 AM To: stripe/stripe-ios stripe-ios@noreply.github.com Cc: denglei022 573505513@qq.com, Mention mention@noreply.github.com Subject: Re: [stripe/stripe-ios] STPPaymentHandler crashed when confirm PaymentIntent (automatic flow) (#1242)

Closed #1242.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.