# Open

  • Log in to the paypal Developer Center to create an application
  • Click the created app in My Apps to get ClientID (required in payment order)
  • Add related configurations such as return URL. When setting the return URL, pay attention to:
    • The format is "package name+://paypalpay", which must be all lowercase
    • Multiple return URLs can be added for Android and iOS platforms respectively

For more information, please refer to Operation Guide for Applying to Open Paypal

注意

  • iOS系统仅支持iOS13.0及以上版本

# Configuration

Parameter Description

  • returnURL_android
    The return URL used by the Android platform must be the same as the value configured in the paypal developer center, otherwise the payment cannot be invoked
  • returnURL_ios
    The return URL used by the iOS platform must be the same as the value configured in the paypal developer center, otherwise the payment cannot be invoked

Tip: returnURL_android and returnURL_ios can be the same, if they are different, you need to add multiple return URLs to the paypal developer center

# Server generates order

Before calling the payment on the App side, you need to generate a payment order on the business server and obtain the orderId. For details, please refer to the official paypal documentation: Create Order

# In-app payment

# Order object parameter description

Object object type

Attribute Type Required Description
clientId String Yes Client ID, which can be obtained when creating an application in the paypal developer center
currency String No The currency must be capitalized. For the value, please refer to the official paypal documentation Currency Codes
environment String Yes The operating environment, which can be sandbox/live, sandbox represents the sandbox environment (for development and testing), and live represents the online environment (officially released)
orderId String Yes Order id, which can be obtained when the server generates a payment order
userAction String No Button style, value paynow/continue

# Sample code

  • uni-app project
//Order object, obtained from the server
var orderInfo = {
  "clientId": "clientId from paypal",     //客户端id
  "orderId": "orderId from server",       //订单id
  "userAction": "continue",  //  paynow/continue
  "currency":"USD",          // 币种  
  "environment":"sandbox",   //运行环境 sandbox/live
};
uni.getProvider({
    service: 'payment',
    success: function (res) {
        console.log(res.provider)
        if (~res.provider.indexOf('paypal')) {
            uni.requestPayment({
                "provider": "paypal", 
                "orderInfo": orderInfo,
                success: function (res) {
                    var rawdata = JSON.parse(res.rawdata);
                    console.log("orderId:" + rawdata.orderId);
                },
                fail: function (err) {
                    console.log('fail:' + JSON.stringify(err));
                }
            });
        }
    }
});
  • 5+ App items
//Order object, obtained from the server
var orderInfo = {
  "clientId": "clientId from paypal",     //客户端id
  "orderId": "orderId from server",       //订单id
  "userAction":"continue",  //  paynow/continue
  "currency":"USD",         // 币种  
  "environment":"sandbox",  //运行环境 sandbox/live
};
//get payment channel
var paypalSev = null;
plus.payment.getChannels(function(channels){
    for (var i in channels) {
        var channel = channels[i];
        if (channel.id === 'paypal') {
            paypalSev = channel;
        }
    }
    //Initiate payment
    plus.payment.request(paypalSev, orderInfo, function(result) {
         var rawdata = JSON.parse(result.rawdata);
         console.log("支付成功");
    }, function(e) {
         console.log("支付失败:" + JSON.stringify(e));
    });
  }, function(e){
      console.log("获取支付渠道失败:" + JSON.stringify(e));
});

# Server authorization

After the payment is initiated on the App side, the order id is returned, and the payment operation has not been completed. The server needs to authorize or capture the order to complete the deduction.

# 注意事项

  • Android端需要注意应用包名和return_url要小写