This little RnD helped me. Digging into the CustomSampleProject provided by Stripe itself, ApplePayStubs works very well when the STPCard is recognized when the delegate
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion
from PKPaymentAuthorizationViewControllerDelegate . The sample code here checked if the code was run during debugging, which is intended for ApplePayStubs, the payment (PKPayment *) in the delegate is converted to STPCard and run on STPAPIClient for the STPToken generation. The following is the body of the above 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
It worked for me. With and without ApplePayStubs (on the Simulator) (on the device) I hope this helps :)
source share