iOS-OC-集成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;

- (void)setPayPal{
    // PayPal注册
    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : PRODUCTION,PayPalEnvironmentSandbox : SANDBOX}];
}

6.在viewDidLoad里面初始化PayPalConfiguration;

- (void)initPayPalConfiguration{
    _payPalConfiguration = [[PayPalConfiguration alloc] init];
    _payPalConfiguration.merchantName = @"香港泓庚科技有限公司";//公司名称
    _payPalConfiguration.acceptCreditCards = NO;
    _payPalConfiguration.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;
}

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

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self SetNavigationStyle:NO];
    #warning ----------------上线的时候修改成正式环境----------------
    // 开始与测试环境工作!当你准备好时,切换到paypalenvironmentproduction。
    [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentNoNetwork];
}
8.调用PayPal支付界面

//amount:金额
//currencyCode:获取单位 比如:USD
//shortDescription:商品标题 简短描述
- (void)PayPalWithAmount:(NSString *)amount currencyCode:(NSString *)currencyCode shortDescription:(NSString *)shortDescription{
    PayPalPayment *payment = [[PayPalPayment alloc] init];
    payment.amount = [[NSDecimalNumber alloc] initWithString:_orderModel.price_sum];
    payment.currencyCode = currencyCode;
    payment.shortDescription = @"购买商品购买商品购买商品";
    payment.items = nil;  // if not including multiple items, then leave payment.items as nil
    payment.paymentDetails = nil; // if not including payment details, then leave payment.paymentDetails as nil
    payment.intent = PayPalPaymentIntentSale;
    if (!payment.processable) {
        NSLog(@"-------------");
    }
    
    PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfiguration delegate:self];
    [self presentViewController:paymentViewController animated:YES completion:nil];
}

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

#pragma mark - PayPalPaymentDelegate methods

- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
    [self verifyCompletedPayment:completedPayment];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
    [self SHOWPrompttext:@"支付有误,请稍后再试"];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
    // Send the entire confirmation dictionary
    NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation options:0 error:nil];
    [self setCartOrderNotifyWith:_order_ids];
    NSLog(@"%@",completedPayment.confirmation);
    NSLog(@"---------------------------------");
    NSLog(@"%@",confirmation);
}

10.支付回调

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

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



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




















评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值