Axios: Прохождение -d керла в axios - PullRequest
0 голосов
/ 03 ноября 2018

У меня проблема с преобразованием данных curl -d в axios, я могу сделать это без проблем, просто с помощью curl ... То есть данные, которые мне нужно передать

curl https://api-3t.sandbox.paypal.com/nvp
-s 
-d USER=Caller_ID
-d PWD=Caller_Pswd
-d SIGNATURE=Caller_Sig 
-d METHOD=SetExpressCheckout
-d RETURNURL=https://example.com/success.html
-d CANCELURL=https://example.com/canceled.html 
-d VERSION=93 # API version 
-d PAYMENTREQUEST_0_CURRENCYCODE=USD
-d PAYMENTREQUEST_0_AMT=250 
-d PAYMENTREQUEST_0_ITEMAMT=225 
-d PAYMENTREQUEST_0_TAXAMT=25 
-d PAYMENTREQUEST_0_PAYMENTACTION=Sale 
-d PAYMENTREQUEST_0_DESC=Sandwich Combo 
-d PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID=Receiver_1 
-d PAYMENTREQUEST_0_PAYMENTREQUESTID=CART1
-d L_PAYMENTREQUEST_0_NAME0=Super Sub 
-d L_PAYMENTREQUEST_0_NUMBER0=SS-101 \
-d L_PAYMENTREQUEST_0_QTY0=1 \
-d L_PAYMENTREQUEST_0_AMT0=125 \
-d L_PAYMENTREQUEST_0_TAXAMT0=15 
-d L_PAYMENTREQUEST_0_NAME1=Classic Wineinformation 
-d L_PAYMENTREQUEST_0_QTY1=1 
-d L_PAYMENTREQUEST_0_AMT1=100 
-d L_PAYMENTREQUEST_0_TAXAMT1=10
-d PAYMENTREQUEST_1_CURRENCYCODE=USD
-d PAYMENTREQUEST_1_AMT=75 
-d PAYMENTREQUEST_1_ITEMAMT=65 
-d PAYMENTREQUEST_1_TAXAMT=10 
-d PAYMENTREQUEST_1_PAYMENTACTION=Sale 
-d PAYMENTREQUEST_1_DESC=Mocktail Large 
-d PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID=Receiver_2
-d PAYMENTREQUEST_1_PAYMENTREQUESTID=CART2
-d L_PAYMENTREQUEST_1_NAME0=Orange crush
-d L_PAYMENTREQUEST_1_NUMBER0=MC-77 
-d L_PAYMENTREQUEST_1_QTY0=1 
-d L_PAYMENTREQUEST_1_AMT0=65 
-d L_PAYMENTREQUEST_1_TAXAMT0=10 

Это API PayPal: https://developer.paypal.com/docs/classic/express-checkout/ht_ec-parallelPayments/?mark=parallel#create-a-parallel-payment

Как должен выглядеть мой почтовый запрос с данными такого типа?

1 Ответ

0 голосов
/ 04 ноября 2018

Проверка Использование формата application / x-www-form-urlencoded из Axios doc

Если вы используете его из браузера:

const params = new URLSearchParams();
params.append('USER', 'Caller_ID');
params.append('PWD', 'Caller_Pswd');
params.append('SIGNATURE', 'Caller_Sig');
params.append('METHOD', 'SetExpressCheckout');
params.append('RETURNURL', 'https://example.com/success.html');
params.append('CANCELURL', 'https://example.com/canceled.html');
params.append('VERSION', 93);
params.append('PAYMENTREQUEST_0_CURRENCYCODE', 'USD');
params.append('PAYMENTREQUEST_0_AMT', 250);
params.append('PAYMENTREQUEST_0_ITEMAMT', 225);
params.append('PAYMENTREQUEST_0_TAXAMT', 25);
params.append('PAYMENTREQUEST_0_PAYMENTACTION', 'Sale');
params.append('PAYMENTREQUEST_0_DESC', 'Sandwich Combo');
params.append('PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID', 'Receiver_1');
params.append('PAYMENTREQUEST_0_PAYMENTREQUESTID', 'CART1');
params.append('L_PAYMENTREQUEST_0_NAME0', 'Super Sub');
params.append('L_PAYMENTREQUEST_0_NUMBER0', 'SS-101');
params.append('L_PAYMENTREQUEST_0_QTY0', 1);
params.append('L_PAYMENTREQUEST_0_AMT0', 125);
params.append('L_PAYMENTREQUEST_0_TAXAMT0', 15);
params.append('L_PAYMENTREQUEST_0_NAME1', 'Classic Wineinformation');
params.append('L_PAYMENTREQUEST_0_QTY1', 1);
params.append('L_PAYMENTREQUEST_0_AMT1', 100);
params.append('L_PAYMENTREQUEST_0_TAXAMT1', 10);
params.append('PAYMENTREQUEST_1_CURRENCYCODE', 'USD');
params.append('PAYMENTREQUEST_1_AMT', 75);
params.append('PAYMENTREQUEST_1_ITEMAMT', 65);
params.append('PAYMENTREQUEST_1_TAXAMT', 10);
params.append('PAYMENTREQUEST_1_PAYMENTACTION', 'Sale');
params.append('PAYMENTREQUEST_1_DESC', 'Mocktail Large');
params.append('PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID', 'Receiver_2');
params.append('PAYMENTREQUEST_1_PAYMENTREQUESTID', 'CART2');
params.append('L_PAYMENTREQUEST_1_NAME0', 'Orange crush');
params.append('L_PAYMENTREQUEST_1_NUMBER0', 'MC-77');
params.append('L_PAYMENTREQUEST_1_QTY0', 1);
params.append('L_PAYMENTREQUEST_1_AMT0', 65);
params.append('L_PAYMENTREQUEST_1_TAXAMT0', 1);

axios.post('https://api-3t.sandbox.paypal.com/nvp', params);
.then(function(response) {
        //handle success
        console.log(response);
    })
    .catch(function(response) {
        //handle error
        console.log(response);
    });

С :

const querystring = require('querystring');
axios.post('https://api-3t.sandbox.paypal.com/nvp', querystring.stringify({
    USER: "Caller_ID",
    PWD: "Caller_Pswd",
    SIGNATURE: "Caller_Sig",
    METHOD: "SetExpressCheckout",
    RETURNURL: "https: //example.com/success.html",
    CANCELURL: "https: //example.com/canceled.html ",
    VERSION: 93,
    PAYMENTREQUEST_0_CURRENCYCODE: "USD",
    PAYMENTREQUEST_0_AMT: 250,
    PAYMENTREQUEST_0_ITEMAMT: 225,
    PAYMENTREQUEST_0_TAXAMT: 25,
    PAYMENTREQUEST_0_PAYMENTACTION: "Sale",
    PAYMENTREQUEST_0_DESC: "Sandwich Combo",
    PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID: "Receiver_1",
    PAYMENTREQUEST_0_PAYMENTREQUESTID: "CART1",
    L_PAYMENTREQUEST_0_NAME0: "Super Sub",
    L_PAYMENTREQUEST_0_NUMBER0: "SS-101",
    L_PAYMENTREQUEST_0_QTY0: 1,
    L_PAYMENTREQUEST_0_AMT0: 125,
    L_PAYMENTREQUEST_0_TAXAMT0: 15,
    L_PAYMENTREQUEST_0_NAME1: "Classic Wineinformation",
    L_PAYMENTREQUEST_0_QTY1: 1,
    L_PAYMENTREQUEST_0_AMT1: 100,
    L_PAYMENTREQUEST_0_TAXAMT1: 10,
    PAYMENTREQUEST_1_CURRENCYCODE: "USD",
    PAYMENTREQUEST_1_AMT: 75,
    PAYMENTREQUEST_1_ITEMAMT: 65,
    PAYMENTREQUEST_1_TAXAMT: 10,
    PAYMENTREQUEST_1_PAYMENTACTION: "Sale",
    PAYMENTREQUEST_1_DESC: "Mocktail Large",
    PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID: "Receiver_2",
    PAYMENTREQUEST_1_PAYMENTREQUESTID: "CART2",
    L_PAYMENTREQUEST_1_NAME0: "Orange crush",
    L_PAYMENTREQUEST_1_NUMBER0: "MC-77",
    L_PAYMENTREQUEST_1_QTY0: 1,
    L_PAYMENTREQUEST_1_AMT0: 65,
    L_PAYMENTREQUEST_1_TAXAMT0: 1,
}));
...