Apple pay
来源:互联网 发布:淘宝助手菜鸟模板 编辑:程序博客网 时间:2024/05/01 04:41
Apple pay的使用
apply pay:移动支付方式
:设备支持,银行支持,版本支持iPhone6+ iOS8.0+(ios9.2+中国使用),商家也要支持才可以使用
:应用场景:线下支付,线上支付(app需要支持)
:与支付宝、微信区别:手机型号、网络环境、使用技术
1.配置支付环境:BundleId、商业标识符、配置项目
BundleId:
商业标识符:进入开发者中心进入证书配置栏目添加appleId
配置Merchant Id并下载证书到钥匙串
绑定MerchantId到AppleID
2.到Xcode中开启Apple Pay功能,在target中的capabilities中开启
3.需要引入#import <PassKit/PassKit.h>框架
4.代码实现:1.判断当前设备是否支持苹果支付
if (![PKPaymentAuthorizationViewController canMakePayments]) {
NSLog(@"doesn't support ApplePay");//判断是否支持
} else if([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkVisa,PKPaymentNetworkChinaUnionPay]]){//判断是否支持银行卡,如果支持则声称一个按钮
PKPaymentButton *button = [PKPaymentButton buttonWithType:PKPaymentButtonTypeSetUp style:PKPaymentButtonStyleWhiteOutline];
[button addTarget:self action:@selector(jump:) forControlEvents:UIControlEventTouchUpInside];
[btnView addSubview:button];
}
5.跳转到添加银行卡界面
-(void)add{
PKPassLibrary *pl = [[PKPassLibrary alloc]init];
[pl openPaymentSetup];
}
6.开始支付
-(void)jump:(UIButton *)btn{
NSLog(@"开始支付");
//创建支付请求
PKPaymentRequest *request = [[PKPaymentRequest alloc]init];
//配置支付请求
request.merchantIdentifier = @"";
//配置货币代码
request.countryCode = @"CN";
request.currencyCode = @"CNY";
//配置请求网络
request.supportedNetworks = @[PKPaymentNetworkVisa,PKPaymentNetworkChinaUnionPay];
//配置用户处理方式
request.merchantCapabilities = PKMerchantCapability3DS;
//配置购买的商品列表
NSDecimalNumber *price = [NSDecimalNumber decimalNumberWithString:@"100"];//价格
PKPaymentSummaryItem *item = [PKPaymentSummaryItem summaryItemWithLabel:@"苹果笔记本" amount:price];
NSDecimalNumber *price1 = [NSDecimalNumber decimalNumberWithString:@"100"];//价格
PKPaymentSummaryItem *item1 = [PKPaymentSummaryItem summaryItemWithLabel:@"苹果笔记本2" amount:price1];
request.paymentSummaryItems = @[item,item1];
//配置请求的附加项
//是否显示发票收获地址,显示那些
request.requiredShippingAddressFields = PKAddressFieldAll;
//是否显示快递地址
request.requiredBillingAddressFields = PKAddressFieldAll;
//配置快递方式
NSDecimalNumber *price2 = [NSDecimalNumber decimalNumberWithString:@"10"];//价格
PKShippingMethod *method = [PKShippingMethod summaryItemWithLabel:@"顺丰快递" amount:price2];
method.identifier = @"顺丰";
method.detail = @"5小时内送到";
NSDecimalNumber *price3 = [NSDecimalNumber decimalNumberWithString:@"10"];//价格
PKShippingMethod *method2 = [PKShippingMethod summaryItemWithLabel:@"韵达快递" amount:price3];
method2.identifier = @"韵达";
method2.detail = @"马上就到";
request.shippingMethods = @[method,method2];
//配置类型
request.shippingType = PKShippingTypeStorePickup;
//添加附加数据
request.applicationData = [@"buyID=12345" dataUsingEncoding:NSUTF8StringEncoding];
//验证支付
PKPaymentAuthorizationViewController *avc = [[PKPaymentAuthorizationViewController alloc]initWithPaymentRequest:request];
avc.delegate = self;
[self presentViewController:avc animated:YES completion:nil];
}
7.实现两个代理方法
//代理方法
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion{
//拿到支付信息,发送给服务器,处理完毕,服务器返回一个状态告诉客户端
BOOL isSucess = YES;
if (isSucess) {
completion(PKPaymentAuthorizationStatusSuccess);
}else{
completion(PKPaymentAuthorizationStatusFailure);
}
}
-(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller{
NSLog(@"授权结束");
[self dismissViewControllerAnimated:controller completion:nil];
}
- Apple Pay
- Apple Pay
- Apple Pay
- apple Pay
- Apple pay
- apple pay
- Apple Pay
- apple pay
- Apple pay
- Apple Pay 究竟是什么
- Apple Pay的使用
- 苹果支付 apple Pay
- 浅谈Apple Pay开发
- Apple Pay初探
- Apple pay 论述
- Apple Pay开发详解
- Apple Pay支付分享
- iOS--Apple Pay
- java的String和StringBuilder类的替换方法的运用。
- 代码覆盖率工具---Emma
- maven项目打jar,war包方法
- 输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然按照递增排序
- 为什么百度地图只显示网格不显示内容
- Apple pay
- ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结
- linux源码安装iostat,dstat,systat的方法分享
- TCP协议中的三次握手和四次挥手(图解)
- linux驱动之--输入子系统
- UITableViewController与UIViewController的区别
- intellij + gradle + jetty + spring mvc step by step - 1
- 启动swift服务的时候出现Exception: Could not bind to 0.0.0.0:8080 after trying for 30 seconds
- J2SE(序)