简体   繁体   English

Apple Pay / Stripe集成问题

[英]Issue with Apple Pay / Stripe integration

I have followed Stripe's documentation and Example App on integrating Apple Pay. 我已经按照Stripe的文档和示例应用程序来集成Apple Pay。

In the handlePaymentAuthorizationWithPayment method, under createTokenWithPayment, I am getting the error: 在handlePaymentAuthorizationWithPayment方法中,在createTokenWithPayment下,我收到错误:

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 ." 错误域= com.stripe.lib代码= 50“您的付款信息格式不正确。请确保您使用的是最新版本的iOS库。有关详细信息,请参阅https://stripe.com/docs/mobile / ios 。“ UserInfo=0x170261b40 {com.stripe.lib:ErrorMessageKey=Your payment information is formatted improperly. UserInfo = 0x170261b40 {com.stripe.lib:ErrorMessageKey =您的付款信息格式不正确。 Please make sure you're correctly using the latest version of our iOS library. 请确保您正确使用我们iOS库的最新版本。 For more information see https://stripe.com/docs/mobile/ios ., NSLocalizedDescription=Your payment information is formatted improperly. 有关详细信息,请参阅https://stripe.com/docs/mobile/ios。,NSLocalizedDescription =您的付款信息格式不正确。 Please make sure you're correctly using the latest version of our iOS library. 请确保您正确使用我们iOS库的最新版本。 For more information see https://stripe.com/docs/mobile/ios .} 有关详细信息,请参阅https://stripe.com/docs/mobile/ios 。}

Anyone know how to resolve this? 有谁知道如何解决这个问题? I am using the latest Stripe library. 我正在使用最新的Stripe库。

Thanks. 谢谢。

This little bit of RnD helped me. 这一点RnD帮助了我。 Digging into the CustomSampleProject provided by Stripe themselves, ApplePayStubs works pretty well when the STPCard is recognized when the delegate 深入挖掘CustomSampleProject由条纹自行提供,ApplePayStubs工作时STPCard时确认委托很好

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

of PKPaymentAuthorizationViewControllerDelegate is called. 调用PKPaymentAuthorizationViewControllerDelegate 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. 此处的示例代码检查代码是否在ApplePayStubs的调试中运行,代理中的(PKPayment *)付款转换为STPCard并启动到STPAPIClient以进行STPToken生成。 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 :) 使用ApplePayStubs(在模拟器上)和没有它们(在设备上)希望这有助于:)

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 . 当我最初将Stripe / Apple Pay设置到我的应用程序中时,当我尝试实现STPTestPaymentAuthorizationController时,我不断收到大量错误。 I found the exact problem described here ( Stripe payment library and undefined symbols for x86_64 ). 我发现了这里描述的确切问题( 条带支付库和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. 我通过注释掉Stripe代码的一部分来复制上面定义的解决方案,这可能会(?)产生Error Domain=com.stripe.lib Code=50错误。

I fixed this by not using STPTestPaymentAuthorizationController at all, just replacing that with PKPaymentAuthorizationViewController in #DEBUG mode. 我通过不使用STPTestPaymentAuthorizationController解决这个问题,只是在#DEBUG模式下用PKPaymentAuthorizationViewController替换它。

tl:dr Not completely sure why STPTestPaymentAuthorization didn't work; tl:dr不完全确定为什么STPTestPaymentAuthorization不起作用; avoided situation completely by running PKPaymentAuthorizationViewController with my iPhone and Stripe dashboard in test mode. 通过在测试模式下使用我的iPhone和Stripe仪表板运行PKPaymentAuthorizationViewController完全避免了这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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