卡神吧
标题:
ios使用paypal支付
[打印本页]
作者:
成安网
时间:
2022-10-4 17:05
标题:
ios使用paypal支付
ios使用paypal支付
作者:
zy88
时间:
2022-10-4 17:05
1、导入PayPal的SDK
2、添加-lc++和-ObjC到Other Linker Flags
4.导入框架:
```
***.framework
***.framework
***.framework
***.framework
***.framework
***.framework
***.framework
***.framework
***.framework
```
5、在AppDelegate中注册
```
[PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : PayPalLive,PayPalEnvironmentSandbox:PayPalSandbox}];
```
6、paypal支付可自己封装工具类,便于使用
初始化PayPalConfiguration
```
PayPalConfiguration *payPalConfig = [[PayPalConfiguration alloc] init];
    ***.acceptcreditcards=NO;
    ***.merchantname=@"有限公司";
    ***.languageorlocale = [InternationalControl userLanguage];  //获取本地语言
```
订单信息PayPalPayment
```
PayPalPayment *payment = [[PayPalPayment alloc] init];
    //订单总额
    OrderInfoModel *tempM = ***.transactions[0];
    PayInfo*infoM = [PayInfo mj_objectWithKeyValues:***.amount];
    ***.amount= [NSDecimalNumberdecimalNumberWithString:***.total];
    //货币类型-RMB是没用的
    ***.currencycode= ***.currency;
    //订单描述
    ***.shortdescription= ***.desc;
```
7、调用paypal支付
```
[PayPalMobile preconnectWithEnvironment:PayPalEnvironmentProduction];  //注意此处为上线状态  测试状态为PayPalEnvironmentSandbox沙盒测试
- (void)payPal:(PayPalItemModel*)model {
    PayPalConfiguration *con = [PayPalTool configuration]; //调用工具类
    if(model && model.***.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; //支付成功
```
欢迎光临 卡神吧 (https://kashen8.com/)
Powered by Discuz! X3.4