一、在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傳遞給服務端進行支付和驗證
? ? }];
}