# API Direct Payment Access

# 一、Method:PSE、Efecty(Past)

New ways:After successful PSE or Efecty payment, you need to pay_url jump to Payty payment(Launch on March 27, 2023).

Past:After successful PSE or Efecty payment, you need to jump to Payty payment(The old version has been docked, and the new version is not supported). The detailed process is as follows:

# 1、Payment return example (successful):

New return
{
    "code":"10000",
    "msg":"Success",
    "out_trade_no":"out_trade_no_1285925731034600",
    "trade_no":"LP20230310035011408-YNdRcq",
    "trade_status":"PROCESSING",
    "pay_url":"https://secure.payty.com/t/8x8pk8gk"
}
Past
{
    "code":"10000",
    "msg":"Success",
    "trade_no":"2022021402120600004",
    "out_trade_no":"LP20220214021316563-5d0Wg6",
    "web_url":"",
    "pay_url":"https://secure.payty.com/vads-payment/",
    "trade_status":"PROCESSING",
    "form_date":{
        "vads_payment_cards":"VISA;PSE",
        "signature":"V64LLsvVZR+7UoKGxEKu0alqTvAVmh81+5vASLLECl0=",
        "vads_trans_date":"20220214021206",
        "vads_ctx_mode":"TEST",
        "vads_action_mode":"INTERACTIVE",
        "vads_page_action":"PAYMENT",
        "vads_order_description":"luxpag test",
        "vads_order_id":"2022021402120600004",
        "vads_currency":"170",
        "vads_version":"V2",
        "vads_trans_id":"07hscj",
        "vads_amount":100000,
        "vads_payment_config":"SINGLE",
        "vads_site_id":"10454805"
    }
}

# 2、Jump payment(Past):

Stop
<input type="button" id="button1" onclick="pay()" value="Test" />

<script type="text/javascript">
    function pay() {
        var pay_url = "https://secure.payty.com/vads-payment/";
        var form_date = {
            "vads_payment_cards": "VISA;PSE",
            "signature": "V64LLsvVZR+7UoKGxEKu0alqTvAVmh81+5vASLLECl0=",
            "vads_trans_date": "20220214021206",
            "vads_ctx_mode": "TEST",
            "vads_action_mode": "INTERACTIVE",
            "vads_page_action": "PAYMENT",
            "vads_order_description": "luxpag test",
            "vads_order_id": "2022021402120600004",
            "vads_currency": "170",
            "vads_version": "V2",
            "vads_trans_id": "07hscj",
            "vads_amount": 100000,
            "vads_payment_config": "SINGLE",
            "vads_site_id": "10454805"
        }
        
        location.href = pay_url + "?" + Object.keys(form_date)?.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(form_date[k])}`).join("&");
    }
</script>  

# 二、Method:Wallet - Paypal

Before placing an order, wallet Paypal needs to get a token from luxpag, and then get nonce from Paypal. The detailed process is as follows:

# 1、Get wallet paypal token from luxpag:

# Request Base URL

  测试环境 : https://gateway-sandbox.luxpag.com
  正式环境 : https://gateway.luxpag.com

# EndPoints

  /trade/get-paypal-client-token

# Request Header

Parameter Required Description
Content-Type recommend application/json
Authorization yes Basic Base64(app_id:secret_key)

# Request Body (JSON format)

Parameter Type Required Max Length(or Default Value) Description
app_id string yes 32 created app's id at dashboard
timestamp string yes 19 yyyy-MM-dd HH:mm:ss
region string no region code When the app is Global, it must

# Request Sample

curl --location --request POST 'https://gateway.luxpag.com/trade/get-paypal-client-token' \
--header 'Authorization: Basic Base64(appid:secret_key)' \
--header 'Content-Type: application/json' \
--data-raw '{
    "app_id": "app_id",
    "timestamp": "{{datetime}}",
}'

# Http Response (JSON format)

Parameter Type Description
code string return code
msg string return msg
token string token

# Return Code (Success)

{
    "code": "10000",
    "msg": "Success",
    "token": "{token}",
}

# 2、nonce from paypal with luxpag wallet token:

var myDeviceData;
// token:Luxpag token
function payForward(token) {
    braintree.client.create({
        authorization:  token // Token you got from Luxpag server
    }).then(function (clientInstance) {
        return braintree.dataCollector.create({
            client: clientInstance,
        });
    }).then(function (dataCollectorInstance) {
        // At this point, you should access the dataCollectorInstance.deviceData value and provide it
        // to your server, e.g. by injecting it into your form as a hidden input
        myDeviceData = dataCollectorInstance.deviceData;
        // Initialize your PayPal Checkout component here
        return braintree.paypalCheckout.create(/* ... */);
    });
    // Create a client.
    braintree.client.create({
        authorization: token//Token you got from Luxpag server
    }).then(function (clientInstance) {
        // Create a PayPal Checkout component.
        return braintree.paypalCheckout.create({
            client: clientInstance
        });
    }).then(function (paypalCheckoutInstance) {
        return paypalCheckoutInstance.loadPayPalSDK({
            vault: true
        });
    }).then(function (paypalCheckoutInstance) {
        return paypal.Buttons({
            fundingSource: paypal.FUNDING.PAYPAL,
            createBillingAgreement: function () {
                return paypalCheckoutInstance.createPayment({
                    flow: 'vault', // Required
                });
            },
            style: {
                shape: "rect",
                height: 52,
            },
            onApprove: function (data, actions) {
                return paypalCheckoutInstance.tokenizePayment(data).then(function (payload) {
                    // Submit `payload.nonce` to your server
                    // Submit Luxpag pay Interface and token = payload.nonce
                });
            },
            onCancel: function (data) {
                console.log('PayPal payment canceled', JSON.stringify(data, 0, 2));
            },
            onError: function (err) {
                console.error('PayPal error', err);
            }
        }).render('#paypal-button');
    }).then(function () {
        // The PayPal button will be rendered in an html element with the ID
        // `paypal-button`. This function will be called when the PayPal button
        // is set up and ready to be used
    }).catch(function (err) {
        // Handle component creation error
    });
}

# 3、API Direct Payment

API Direct Payment。

# 4、Test account with luxpag Wallet。

Test user account.

# 5、Sample。

For reference only. It is recommended to seal the luxpag API on the server and the PayPal nonce on the client.

<script src="https://res.luxpag.com/lib/js/jquery-1.10.2.min.js"></script>
<script src="https://js.braintreegateway.com/web/3.85.2/js/client.min.js"></script>
<script src="https://js.braintreegateway.com/web/3.85.2/js/paypal-checkout.min.js"></script>
<script src="https://js.braintreegateway.com/web/3.79.0/js/data-collector.min.js"></script>

<div id="paypal-button"> </div>

<script type="text/javascript">
    $(document).ready(function () {
    var param= '{"app_id":"???????","timestamp":"2022-01-20 14:55:10"}';
    $.ajax({
        type: "POST",
        url: "https://gateway-sandbox.luxpag.com/trade/get-paypal-client-token",
        headers: {'Authorization': 'Basic ???????'},
        cache: false,
        dataType: "json",
        contentType: "application/json",
        data: param,
        success: function (d) {
            if (d.code == "10000" && d.token != null) {
                payForward(d.token);
            }
        }
    });
});

var myDeviceData;
// token:Luxpag token
function payForward(token) {
    braintree.client.create({
        authorization:  token
    }).then(function (clientInstance) {
        return braintree.dataCollector.create({
            client: clientInstance,
        });
    }).then(function (dataCollectorInstance) {
        myDeviceData = dataCollectorInstance.deviceData;
        return braintree.paypalCheckout.create(/* ... */);
    });
    braintree.client.create({
        authorization: token
    }).then(function (clientInstance) {
        return braintree.paypalCheckout.create({
            client: clientInstance
        });
    }).then(function (paypalCheckoutInstance) {
        return paypalCheckoutInstance.loadPayPalSDK({
            vault: true
        });
    }).then(function (paypalCheckoutInstance) {
        return paypal.Buttons({
            fundingSource: paypal.FUNDING.PAYPAL,
            createBillingAgreement: function () {
                return paypalCheckoutInstance.createPayment({
                    flow: 'vault', // Required
                });
            },
            style: {
                shape: "rect",
                height: 52,
            },
            onApprove: function (data, actions) {
                return paypalCheckoutInstance.tokenizePayment(data).then(function (payload) {
                    // Submit `payload.nonce` to your server
                    // Submit Luxpag pay Interface and token = payload.nonce
                    pay(payload.nonce);
                });
            },
            onCancel: function (data) {
            },
            onError: function (err) {
            }
        }).render('#paypal-button');
    }).then(function () {
    }).catch(function (err) {
    });
}
function pay(token){
    var param = {};
    param.token = token;

    $.ajax({
        type: "POST",
        url: "https://gateway-sandbox.luxpag.com/trade/pay",
        headers: {'Authorization': 'Basic ???????'},
        cache: false,
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify(param),
        success: function (d) {
        }
    });
}
</script>