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{
-
- [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 ----------------上线的时候修改成正式环境----------------
-
- [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentNoNetwork];
- }
8.调用PayPal支付界面
-
-
-
- - (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;
- payment.paymentDetails = 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 {
-
- 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