1

我正在尝试将 Apple Pay 与 Stripe 集成到我的 iOS 应用程序中。使用 ApplePayStub 提供的条纹在 DEBUG 模式下检查苹果支付

我正在使用来自 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 .},

任何帮助是极大的赞赏。

4

2 回答 2

1

@Wizyashas,您对STPTestPaymentAuthorizationViewController的设置非常好。当您尝试通过STPAPIClient生成令牌时,就会出现问题。这就是一切变得混乱的地方。

这一点 RnD 帮助了我。深入研究Stripe自己提供的CustomSampleProject , ApplePayStubs在STPCard被代表识别时工作得很好

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

PKPaymentAuthorizationViewControllerDelegate调用。此处的示例代码检查代码是否在ApplePayStubs的调试中运行,委托中的(PKPayment *)payment将转换为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(在模拟器上)和没有它们(在设备上)。

希望这可以帮助 :)

于 2015-04-01T17:37:24.767 回答
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)
    }
}
于 2015-03-17T07:42:27.133 回答