Apple Pay
来源:互联网 发布:linux安装yum包 编辑:程序博客网 时间:2024/04/30 23:01
主要的申请一个商品的ID,Xcode要支持Apple pay
//// ViewController.m// TestApplePay//// Created by yinbo on 2016/11/30.// Copyright © 2016年 yinbo. All rights reserved.//#import "ViewController.h"#import <PassKit/PassKit.h>@interface ViewController ()<PKPaymentAuthorizationViewControllerDelegate>@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; PKPaymentButton *payBtn=[PKPaymentButton buttonWithType:PKPaymentButtonTypePlain style:PKPaymentButtonStyleBlack]; payBtn.center=self.view.center; [payBtn addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:payBtn]; // Do any additional setup after loading the view, typically from a nib.}-(void)payAction:(PKPaymentButton *)btn{ PKPaymentRequest *request=[[PKPaymentRequest alloc]init]; request.countryCode=@"CN"; request.currencyCode=@"CNY"; request.supportedNetworks=@[PKPaymentNetworkAmex,PKPaymentNetworkChinaUnionPay,PKPaymentNetworkVisa,PKPaymentNetworkMasterCard,PKPaymentNetworkDiscover,PKPaymentNetworkInterac,PKPaymentNetworkPrivateLabel]; request.merchantCapabilities=PKMerchantCapabilityDebit|PKMerchantCapabilityCredit|PKMerchantCapabilityEMV; request.merchantIdentifier=@"merchant.com.zhuguangmama.TestApplePay"; request.requiredBillingAddressFields=PKAddressFieldAll; request.requiredShippingAddressFields=PKAddressFieldAll; NSDecimalNumber *shippingPrice=[NSDecimalNumber decimalNumberWithString:@"11.0"]; PKShippingMethod *method=[PKShippingMethod summaryItemWithLabel:@"快递公司" amount:shippingPrice]; method.detail=@"24小时送到!"; method.identifier=@"kuaidi"; request.shippingMethods=@[method]; request.shippingType=PKShippingTypeServicePickup; NSString *str=@"商品ID:123456"; request.applicationData=[str dataUsingEncoding:NSUTF8StringEncoding]; PKPaymentSummaryItem *item1=[PKPaymentSummaryItem summaryItemWithLabel:@"会员" amount:[NSDecimalNumber decimalNumberWithString:@"11.0"]]; request.paymentSummaryItems=@[item1]; PKPaymentAuthorizationViewController *paymentPane=[[PKPaymentAuthorizationViewController alloc]initWithPaymentRequest:request]; paymentPane.delegate=self;// [self presentViewController:paymentPane animated:YES completion:nil]; if([PKPaymentAuthorizationViewController canMakePayments]){ [self presentViewController:paymentPane animated:YES completion:nil]; }else{ NSLog(@"用户不支持Apple pay"); }}-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion{ PKPaymentToken *token=payment.token; NSLog(@"获取TOKEN---%@",token); NSString *address=payment.billingContact.postalAddress.city; NSLog(@"获取地址:%@",address); NSLog(@"验证通过后,需要开发者继续完成交易");}-(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller{ NSLog(@"取消或者交易成功"); [self dismissViewControllerAnimated:YES completion:nil];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- 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
- 发送队列
- Qt qml treeview 树控件
- 安卓底层开发学习经验第十二期
- BottomNavigationBar实现Android特色底部导航栏
- redis与DB数据同步问题
- Apple Pay
- 接口引用以参数被调用
- Qt qml 模拟iphone slide to unlock 的聚光动画文字效果
- 百度云智峰会 核心关键词都在这里了
- libcurl用法笔记
- 生产库MySQL配置文件my.cnf详解
- ROS学习历程(6)------理解ROS的节点(NODE)
- Android 6.0 BatteryService分析
- 开启nginx的status和php-fpm的status页面