我正在尝试在iOS应用程序中将Apple Pay与Stripe集成在一起。
使用ApplePayStub按条提供在调试模式下检查Apple Pay

我正在使用git的latest stripe和ApplePayStub代码

尝试在iPhone 6模拟器上运行,我正在使用的代码是:

paymentController = [[STPTestPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
((STPTestPaymentAuthorizationViewController*) paymentController).delegate = self;

出现错误:
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=0xxxxxxxxxxx {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 .},

任何帮助是极大的赞赏。

最佳答案

@Wizyashas,您的 STPTestPaymentAuthorizationViewController 的设置非常好。当您尝试通过 STPAPIClient 生成 token 时,会发生问题。到处都是混乱。

RnD的这一点帮助了我。深入研究 strip 化本身提供的CustomSampleProject,当代表被识别为 STPCard 时, ApplePayStubs 可以很好地工作

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

调用的PKPaymentAuthorizationViewControllerDelegate 。此处的示例代码检查了该代码是否在 ApplePayStubs 的调试中运行,委托中的(PKPayment *)付款被转换为 STPCard 并为生成 STPAPIClient 启动。以下是上述代表的正文:
#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 (在Simulator上),而没有它们(在Device上)。

希望这可以帮助 :)

10-07 14:36