ios使用paypal支付

2018-08-24  本文已影响0人  桔子橙子柚子_F

1、导入PayPal的SDK

2、添加-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中注册

```

[PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : PayPalLive,PayPalEnvironmentSandbox:PayPalSandbox}];

```

6、paypal支付可自己封装工具类,便于使用

初始化PayPalConfiguration

```

PayPalConfiguration *payPalConfig = [[PayPalConfiguration alloc] init];

    payPalConfig.acceptCreditCards=NO;

    payPalConfig.merchantName=@"有限公司";

    payPalConfig.languageOrLocale = [InternationalControl userLanguage];  //获取本地语言

```

订单信息PayPalPayment

```

PayPalPayment *payment = [[PayPalPayment alloc] init];

    //订单总额

    OrderInfoModel *tempM = model.transactions[0];

    PayInfo*infoM = [PayInfo mj_objectWithKeyValues:tempM.amount];

    payment.amount= [NSDecimalNumberdecimalNumberWithString:infoM.total];

    //货币类型-RMB是没用的

    payment.currencyCode= infoM.currency;

    //订单描述

    payment.shortDescription= tempM.desc;

```

7、调用paypal支付

```

[PayPalMobile preconnectWithEnvironment:PayPalEnvironmentProduction];  //注意此处为上线状态  测试状态为PayPalEnvironmentSandbox沙盒测试

- (void)payPal:(PayPalItemModel*)model {

    PayPalConfiguration *con = [PayPalTool configuration]; //调用工具类

    if(model && model.transactions.count) {

        PayPalPayment*payment = [PayPalToolpayment:model];  //调用工具类

        PayPalPaymentViewController*paymentViewController = [[PayPalPaymentViewControlleralloc]initWithPayment:paymentconfiguration:condelegate:self];

        [self presentViewController:paymentViewController animated:YES completion:nil];

    }

}

```

8、通过代理获取支付状态

```

- (void)payPalPaymentDidCancel:(PayPalPaymentViewController*)paymentViewController; //取消支付

- (void)payPalPaymentViewController:(PayPalPaymentViewController*)paymentViewController didCompletePayment:(PayPalPayment*)completedPayment; //支付成功

```

上一篇下一篇

猜你喜欢

热点阅读