paypal支付(转)

1.到PayPal网站注册账号:https://developer.paypal.com 

创建一个APP,然后获取paypal的测试和正式环境的APPKey;

2.导入PayPal的SDK,下载地址:https://github.com/paypal/PayPal-iOS-SDK#add-the-sdk-to-your-project

3.添加-lc++和-ObjC到Other Linker Flags;

4.导入必须的框架:

Accelerate.framework
AudioToolbox.framework
AVFoundation.framework
CoreLocation.framework
CoreMedia.framework
MessageUI.framework
MobileCoreServices.framework
SystemConfiguration.framework
SafariServices.framework

5.在AppDelegate里面配置注册PalPal信息;

PRODUCTION为生成环境的key;

SANDBOX为开发环境的Key;

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. - (void)setPayPal{  
  2.     // PayPal注册  
  3.     [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : PRODUCTION,PayPalEnvironmentSandbox : SANDBOX}];  
  4. }  

6.在viewDidLoad里面初始化PayPalConfiguration;

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. - (void)initPayPalConfiguration{  
  2.     _payPalConfiguration = [[PayPalConfiguration alloc] init];  
  3.     _payPalConfiguration.merchantName = @"香港泓庚科技有限公司";//公司名称  
  4.     _payPalConfiguration.acceptCreditCards = NO;  
  5.     _payPalConfiguration.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;  
  6. }  

7.支付页面的viewWillAppear里面代码,上线的时候注意修改;

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. - (void)viewWillAppear:(BOOL)animated{  
  2.     [super viewWillAppear:animated];  
  3.     [self SetNavigationStyle:NO];  
  4.     #warning ----------------上线的时候修改成正式环境----------------  
  5.     // 开始与测试环境工作!当你准备好时,切换到paypalenvironmentproduction。  
  6.     [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentNoNetwork];  
  7. }  
8.调用PayPal支付界面

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //amount:金额  
  2. //currencyCode:获取单位 比如:USD  
  3. //shortDescription:商品标题 简短描述  
  4. - (void)PayPalWithAmount:(NSString *)amount currencyCode:(NSString *)currencyCode shortDescription:(NSString *)shortDescription{  
  5.     PayPalPayment *payment = [[PayPalPayment alloc] init];  
  6.     payment.amount = [[NSDecimalNumber alloc] initWithString:_orderModel.price_sum];  
  7.     payment.currencyCode = currencyCode;  
  8.     payment.shortDescription = @"购买商品购买商品购买商品";  
  9.     payment.items = nil;  // if not including multiple items, then leave payment.items as nil  
  10.     payment.paymentDetails = nil// if not including payment details, then leave payment.paymentDetails as nil  
  11.     payment.intent = PayPalPaymentIntentSale;  
  12.     if (!payment.processable) {  
  13.         NSLog(@"-------------");  
  14.     }  
  15.       
  16.     PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfiguration delegate:self];  
  17.     [self presentViewController:paymentViewController animated:YES completion:nil];  
  18. }  

9.PayPalPaymentDelegate代理方法,支付成功和失败;

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #pragma mark - PayPalPaymentDelegate methods  
  2.   
  3. - (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {  
  4.     [self verifyCompletedPayment:completedPayment];  
  5.     [self dismissViewControllerAnimated:YES completion:nil];  
  6. }  
  7.   
  8. - (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {  
  9.     [self SHOWPrompttext:@"支付有误,请稍后再试"];  
  10.     [self dismissViewControllerAnimated:YES completion:nil];  
  11. }  
  12.   
  13. - (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {  
  14.     // Send the entire confirmation dictionary  
  15.     NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation options:0 error:nil];  
  16.     [self setCartOrderNotifyWith:_order_ids];  
  17.     NSLog(@"%@",completedPayment.confirmation);  
  18.     NSLog(@"---------------------------------");  
  19.     NSLog(@"%@",confirmation);  
  20. }  

10.支付回调

- (void)setCartOrderNotifyWith:(NSString *)order_ids;

这个函数用于告诉我们自己的服务器完成支付;



11.附上PayPal开发文档,中文版:http://download.csdn.net/detail/u014220518/9606515





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值