美文网首页
ios使用paypal支付

ios使用paypal支付

作者: 桔子橙子柚子_F | 来源:发表于2018-08-24 17:52 被阅读0次

    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; //支付成功

    ```

    相关文章

      网友评论

          本文标题:ios使用paypal支付

          本文链接:https://www.haomeiwen.com/subject/nddiiftx.html