简体   繁体   中英

Issue with Apple Pay / Stripe integration

I have followed Stripe's documentation and Example App on integrating Apple Pay.

In the handlePaymentAuthorizationWithPayment method, under createTokenWithPayment, I am getting the error:

Error Domain=com.stripe.lib Code=50 "Your payment information is formatted improperly. Please make sure you're correctly using the latest version of our iOS library. For more information see https://stripe.com/docs/mobile/ios ." UserInfo=0x170261b40 {com.stripe.lib:ErrorMessageKey=Your payment information is formatted improperly. Please make sure you're correctly using the latest version of our iOS library. For more information see https://stripe.com/docs/mobile/ios ., NSLocalizedDescription=Your payment information is formatted improperly. Please make sure you're correctly using the latest version of our iOS library. For more information see https://stripe.com/docs/mobile/ios .}

Anyone know how to resolve this? I am using the latest Stripe library.

Thanks.

This little bit of RnD helped me. Digging into the CustomSampleProject provided by Stripe themselves, ApplePayStubs works pretty well when the STPCard is recognized when the delegate

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                   didAuthorizePayment:(PKPayment *)payment
                            completion:(void (^)(PKPaymentAuthorizationStatus))completion

of PKPaymentAuthorizationViewControllerDelegate is called. The sample code here checked if the code was run in debug that is for ApplePayStubs, the (PKPayment *)payment in the delegate is converted to a STPCard and is launched to the STPAPIClient for STPToken generation. Following is the body of the above mentioned delegate:

#if DEBUG // This is to handle a test result from ApplePayStubs
if (payment.stp_testCardNumber)
{
    STPCard *card = [STPCard new];
    card.number = payment.stp_testCardNumber;
    card.expMonth = 12;
    card.expYear = 2020;
    card.cvc = @"123";
    [[STPAPIClient sharedClient] createTokenWithCard:card
                                          completion:^(STPToken *token, NSError *error)
    {
        if (error)
        {
            completion(PKPaymentAuthorizationStatusFailure);
            [[[UIAlertView alloc] initWithTitle:@"Error"
                                        message:@"Payment Unsuccessful! \n Please Try Again"
                                       delegate:self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
            return;
        }
    /*
     Handle Token here
     */
                                            }];
}
#else
[[STPAPIClient sharedClient] createTokenWithPayment:payment
                                         completion:^(STPToken *token, NSError *error)
{
    if (error)
    {
        completion(PKPaymentAuthorizationStatusFailure);
        [[[UIAlertView alloc] initWithTitle:@"Error"
                                    message:@"Payment Unsuccessful!"
                                   delegate:self
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil] show];
        return;
    }
    /*
     Handle Token here
     */
}];
#endif

This worked for me. With ApplePayStubs (on Simulator) and without them (on Device) Hope this Helps :)

I think I know what happened here. Leaving this up in case it helps anybody.

When I initially set up Stripe / Apple Pay into my app, I kept getting numerous errors when I attempted to implement STPTestPaymentAuthorizationController . I found the exact problem described here ( Stripe payment library and undefined symbols for x86_64 ).

I replicated the solution defined above by commenting out part of Stripe's code, which maybe (?) produced the Error Domain=com.stripe.lib Code=50 error.

I fixed this by not using STPTestPaymentAuthorizationController at all, just replacing that with PKPaymentAuthorizationViewController in #DEBUG mode.

tl:dr Not completely sure why STPTestPaymentAuthorization didn't work; avoided situation completely by running PKPaymentAuthorizationViewController with my iPhone and Stripe dashboard in test mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM