Stripe 蘋果支付

一、在pod文件中添加以下代碼導入SDK

pod 'Stripe'

二、在AppDelegate.m中引入并初始化sdk

#import?<Stripe/Stripe.h>

//配置stripe支付

[[STPPaymentConfiguration sharedConfiguration] setPublishableKey:@"key"]; ? ?[[STPPaymentConfiguration sharedConfiguration] setAppleMerchantIdentifier:@"merchantId"];


三、#pragma mark- 蘋果支付<PKPaymentAuthorizationViewControllerDelegate>

- (void)startApplePay {

? ? /*

?? ? * 開始配置支付信息

?? ? */

? ? PKPaymentRequest*paymentRequest = [Stripe paymentRequestWithMerchantIdentifier:@"merchantId"country:@"IT"currency:@"EUR"];

? ? paymentRequest.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa];

? ? paymentRequest.merchantCapabilities = PKMerchantCapability3DS;

? ? NSDecimalNumber *totalAmount = [NSDecimalNumber decimalNumberWithString:self.payMoney];

? ? NSString *summary01 = @"標題";

? ? NSString *summary02 = @"Pay內(nèi)容";

? ? paymentRequest.paymentSummaryItems=@[

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [PKPaymentSummaryItem summaryItemWithLabel:summary01 amount:totalAmount],

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //它的前綴是“Pay”(即“付款”)。"Pay iHats, Inc $50")

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [PKPaymentSummaryItem summaryItemWithLabel:summary02 amount:totalAmount]

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ];

? ? PKPaymentAuthorizationViewController *xxPaymentController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:paymentRequest];

? ? xxPaymentController.delegate = (id<PKPaymentAuthorizationViewControllerDelegate>)self;

? ? [self.navigationController presentViewController:xxPaymentController animated:YES completion:nil];

}

#pragma mark - PKPaymentAuthorizationViewControllerDelegate蘋果支付代理

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller

?? ? ? ? ? ? ? ? ? ? ? didAuthorizePayment:(PKPayment*)payment

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? handler:(void(^)(PKPaymentAuthorizationResult*result))completion{

? ? [[STPAPIClient sharedClient] createTokenWithPayment:payment completion:^(STPToken *token, NSError *error) {

? ? ? ? NSLog(@"token:%@",token);

? ? ? ? if(token ==nil || error !=nil) {

? ? ? ? ? ? // Present error to user...

? ? ? ? ? ? //NSLog(@"蘋果支付出錯 --- %@",error);

? ? ? ? ? ? PKPaymentAuthorizationResult *re = [[PKPaymentAuthorizationResult alloc]initWithStatus:PKPaymentAuthorizationStatusFailure errors:nil];

? ? ? ? ? ? completion(re);

? ? ? ? ? ? return;

? ? ? ? }

//將獲取的token傳遞給服務端進行支付和驗證

? ? }];

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容