我正在尝试在我的iOS应用中将苹果支付与条带集成。 使用ApplePayStub提供条带来检查DEBUG模式下的苹果工资
我正在使用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 .},
非常感谢任何帮助。
答案 0 :(得分:1)
@Wizyashas,您对 STPTestPaymentAuthorizationViewController 的设置完全没问题。当您尝试通过 STPAPIClient 生成令牌时会发生此问题。这一切都变得混乱。
这一点RnD帮助了我。深入了解 Stripe 提供的CustomSampleProject, ApplePayStubs 在代表
时识别 STPCard 时效果很好- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus))completion
调用 PKPaymentAuthorizationViewControllerDelegate 的。此处的示例代码检查代码是否在 ApplePayStubs 的调试中运行,代理中的(PKPayment *)付款转换为 STPCard 并且针对 STPToken 生成启动到 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 (在模拟器上)和没有它们(在设备上)。
希望这有助于:)
答案 1 :(得分:0)
尝试使用PaymentKit提出请求
@IBAction func payTapped(AnyObject) {
// Valiate that this device can take payments
if (PKPaymentAuthorizationViewController.canMakePayments()) {
// Construct the basic payment request
var paymentRequest = PKPaymentRequest()
paymentRequest.merchantIdentifier = "merchant.com.example";
paymentRequest.supportedNetworks = [PKPaymentNetworkVisa, PKPaymentNetworkMasterCard, PKPaymentNetworkAmex]
paymentRequest.merchantCapabilities = PKMerchantCapability.Capability3DS | PKMerchantCapability.CapabilityEMV
paymentRequest.countryCode = "US"
paymentRequest.currencyCode = "USD"
paymentRequest.requiredShippingAddressFields = PKAddressField.All;
// Add a line item
var totalItem = PKPaymentSummaryItem(label:"Foo", amount:NSDecimalNumber(string:"0.05"))
paymentRequest.paymentSummaryItems = [totalItem];
// Show the Apple Pay controller
var payAuth = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
payAuth.delegate = self
self.presentViewController(payAuth, animated:true, completion: nil)
}
}