ApplePay简单测试(一)
来源:互联网 发布:怎么制作淘宝店铺模板 编辑:程序博客网 时间:2024/06/05 17:32
最近ApplePay刚进入中国,现在貌似挺火的.在Github上看到了别人写的一个Demo(https://github.com/lintide/ApplePayDemo),于是研究了一下.下面简单记录一下步骤和经验.(在2016-2-24是有效的,以后不知道怎么改了)
1.登陆开发者中心,在申请证书里选择Merchant ID
点击右上角+号
2.continue 后有填写描述和标识符的.模仿例子填写
后面有确认注册的,点击Register.
3.编辑关联钥匙串
点击Edit
是否在美国外销售
后面有生成CSR文件的,点击continue.
在本机钥匙串访问-证书助理-从证书颁发机构请求证书中
确认生成CSR文件,上传
然后出现
下载.到目前为止在官网上基本配置完毕.
二.在Xcode中的Target-Capability中打开Apply Pay与Wallet开关,现在十分智能,只要选对证书和工作组应该就可以自动配置好环境.
可以看到自动导入了证书文件和依赖包.
2.引入PassKit
PassKit里有苹果为支付专门写的一个Button,叫 PKPaymentButton
和普通的Button用法一样
PKPaymentButton * payButton = [[PKPaymentButton alloc]initWithPaymentButtonType:PKPaymentButtonTypePlain paymentButtonStyle:PKPaymentButtonStyleWhiteOutline];
背景可以是黑是白,自己自定义一个也可以.
3.遵守协议 PKPaymentAuthorizationViewControllerDelegate
必须实现两个方法
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controllerdidAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion;
和
-(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller;
下面直接贴代码吧.和github上的大致相同
-(void)pressBtn:(id)sender{ if ([PKPaymentAuthorizationViewController canMakePayments]) { NSLog(@"可以进行支付"); } PKPaymentRequest * payment = [[PKPaymentRequest alloc]init]; // 写成<特殊符号>888会报错 Payment request is invalid: Error Domain=PKPassKitErrorDomain Code=1 "Invalid in-app payment request" UserInfo={NSLocalizedDescription=Invalid in-app payment request, NSUnderlyingError=0x7fc0384888d0 {Error Domain=PKPassKitErrorDomain Code=1 "PKPaymentRequest must contain an NSArray property 'paymentSummaryItems' of valid objects of class PKPaymentSummaryItem" UserInfo={NSLocalizedDescription=PKPaymentRequest must contain an NSArray property 'paymentSummaryItems' of valid objects of class PKPaymentSummaryItem, NSUnderlyingError=0x7fc038489bf0 {Error Domain=PKPassKitErrorDomain Code=1 "%@ has an invalid label or amount property" UserInfo={NSLocalizedDescription=%@ has an invalid label or amount property}}}}}// Label 付款对象 amount金额 type final确定的,pending不确定的 PKPaymentSummaryItem * total = [PKPaymentSummaryItem summaryItemWithLabel:@"Test" amount:[NSDecimalNumber decimalNumberWithString:@"888"] type:PKPaymentSummaryItemTypeFinal];// PKPaymentSummaryItem * total = [PKPaymentSummaryItem summaryItemWithLabel:@"Test" amount:[NSDecimalNumber decimalNumberWithString:@"888"]]; payment.paymentSummaryItems = @[total]; payment.merchantIdentifier = @"merchant.com.YoungForever.merchantname";// 人民币 payment.currencyCode = @"CNY";// 国家代码 payment.countryCode = @"CN";// 支持信用卡 payment.merchantCapabilities = PKMerchantCapabilityCredit;// 结算网关 payment.supportedNetworks = @[PKPaymentNetworkChinaUnionPay]; NSLog(@"payment==%@",payment); PKPaymentAuthorizationViewController * vc = [[PKPaymentAuthorizationViewController alloc]initWithPaymentRequest:payment]; vc.delegate = self; [self presentViewController:vc animated:YES completion:nil];}
待续(2)
1 0
- ApplePay简单测试(一)
- ApplePay 支付的简单使用
- ApplePay
- 简单RMI测试(一)
- c指针简单测试一
- c指针简单测试一
- ApplePay开发
- ApplePay接入
- ApplePay调研
- linux线程的简单测试(一)
- 2016/2/19:ApplePay
- ApplePay 实现代码片段
- 最新《ApplePay支付》接入
- App集成ApplePay
- APP应用接入ApplePay
- 开始使用ApplePay
- ApplePay 支付开发
- ApplePay完整添加流程
- cocos2d-android-1
- the inferior stopped because it triggered an exception
- Codeforces Round #304 (Div. 2)E. Soldier and Traveling 网络流
- Javascript中的String
- MatLab归一化说明
- ApplePay简单测试(一)
- ViewAnimation帧动画示例
- 328. Odd Even Linked List
- Redis常用数据类型
- 继承,装饰者模式和动态代理之间的区别
- SAE 环境 django 配置
- 《JAVA编程思想》日志(一)------对象导论
- 基于WKWebview IOS app (OC) 源码
- 10个精妙的Java编码最佳实践