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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With