生活随笔
收集整理的這篇文章主要介紹了
ApplePay 支付的简单使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ApplePay支付功能出來已經很久了,看著API自己學習了一下,今天想起來總結一下,也算是在學習一下,所以寫了這篇筆記,
applePay是在iphone 6以上設備才支持這個支付功能的,這一點一定要清楚,
我是簡單的實現了一下功能做演示功能其他的就不說了,直接上代碼,加注釋
- (
void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (![PKPaymentAuthorizationViewController canMakePayments]) {
NSLog(@
"設備不支持");
return;}
if (![PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkChinaUnionPay,PKPaymentNetworkVisa]]) {
NSLog(@
"支持visa和銀聯");[[[PKPassLibrary alloc]init]openPaymentSetup];
return;}PKPaymentRequest *requ = [[PKPaymentRequest alloc]init];requ
.merchantIdentifier = @
"merchant.www.Kensence.com.ApplePay";requ
.countryCode = @
"CN"; requ
.supportedNetworks = @[PKPaymentNetworkChinaUnionPay,PKPaymentNetworkVisa];requ
.merchantCapabilities = PKMerchantCapability3DS;requ
.currencyCode = @
"CNY";NSDecimalNumber *number = [NSDecimalNumber decimalNumberWithString:@
"4"];PKPaymentSummaryItem *item = [PKPaymentSummaryItem summaryItemWithLabel:@
"毛巾" amount:number];requ
.paymentSummaryItems = @[item];requ
.requiredBillingAddressFields = PKAddressFieldAll;requ
.requiredShippingAddressFields = PKAddressFieldAll;PKShippingMethod *meth = [PKShippingMethod summaryItemWithLabel:@
"順風" amount:[NSDecimalNumber decimalNumberWithString:@
"8"]];meth
.identifier = @
"shunfeng";meth
.detail = @
"24小時之內到達";requ
.shippingMethods = @[meth];PKPaymentAuthorizationViewController *payVC = [[PKPaymentAuthorizationViewController alloc]initWithPaymentRequest:requ];payVC
.delegate =
self;[
self presentViewController:payVC animated:
YES completion:
nil];}
- (
void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controllerdidAuthorizePayment:(PKPayment *)paymentcompletion:(
void (^)(PKPaymentAuthorizationStatus status))completion{completion(PKPaymentAuthorizationStatusSuccess);}- (
void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
{[
self dismissViewControllerAnimated:
YES completion:
nil];}
總結
以上是生活随笔為你收集整理的ApplePay 支付的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。