这一点 RnD 帮助了我。深入研究 Stripe 自己提供的CustomSampleProject ,ApplePayStubs 在STPCard被代表识别时工作得很好
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus))completion
PKPaymentAuthorizationViewControllerDelegate被调用。此处的示例代码检查代码是否在 ApplePayStubs 的调试中运行,委托中的(PKPayment *) 付款被转换为STPCard并被启动到STPAPIClient以生成STPToken。以下是上述代表的主体:
#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
这对我有用。使用 ApplePayStubs(在模拟器上)和没有它们(在设备上)希望这会有所帮助:)