gpt4 book ai didi

ios - Apple 支付与 Stripe 的集成(调试中的 STPTestPaymentAuthorizationViewController)

转载 作者:行者123 更新时间:2023-11-29 12:26:01 24 4
gpt4 key购买 nike

我正在尝试在我的 iOS 应用程序中将 apple pay 与 stripe 集成。在 DEBUG 模式下使用 ApplePayStub provide by stripe 查看 apple pay

我正在使用 latest stripe和来自 git 的 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 帮助了我。深入研究 CustomSampleProjectStripe 自己提供,ApplePayStubs 在委托(delegate)时识别 STPCard 时效果很好

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

PKPaymentAuthorizationViewControllerDelegate 被调用。此处的示例代码检查代码是否在针对 ApplePayStubs 的调试中运行,委托(delegate)中的 (PKPayment *)payment 被转换为 STPCard 并启动到 STPAPIClient 以生成 STTPoken。以下是上述代表的正文:

#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(在模拟器上)和不使用它们(在设备上)。

希望这有帮助:)

关于ios - Apple 支付与 Stripe 的集成(调试中的 STPTestPaymentAuthorizationViewController),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29091794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com