Node.js Paypal sdk:visa 卡无法使用
Node.js Paypal sdk: visa card is not working
我正尝试在 node.js
中使用 PayPal 处理信用卡
使用万事达卡,以下代码使用状态代码为 201
的沙箱帐户。
但是,不使用 'visa'、'amex'.
使用 'visa'、'amex' 卡,我得到 500
状态代码,但找不到错误详细信息。
谁见过这个案例?
var paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox',
'client_id': 'CLIENT_ID',
'client_secret': 'CLIENT_SECRET_KEY'
});
var payment = {
"intent": "authorize",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card": {
"type": "visa",//visa//mastercard//amex
"expire_month": 1,
"expire_year": 2022,
"cvv2": "VISA_CCV2",
"number": "VISA_NUMBER"
}
}]
},
"redirect_urls": {
"return_url": "http://127.0.0.1:3000/success",
"cancel_url": "http://127.0.0.1:3000/err"
},
"transactions": [{
"item_list": {
"items": [{
"name": "media dvd",
"sku": "001",
"price": "1.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"total": 1.00,
"currency": "USD"
},
"description": " a book on mean stack "
}]
}
paypal.payment.create(payment, { timeout: 10000 }, function (err, payment) {
if (err) {
console.log(err, payment);
}
else {
console.log(payment);
}
});
发件人:https://developer.paypal.com/docs/api/payments/v1/
Important: The use of the PayPal REST /payments APIs to accept credit card payments is restricted. Instead, you can accept credit card payments with Braintree Direct.
(Braintree direct 将是一个完整的网关帐户,需要帐户批准并且仅适用于企业 in certain countries.)
由于您试图将旧的东西与旧的 SDK 集成,并且不能在实时环境中使用 - 这是最好的 PayPal 替代方案:
使用新的、受支持的 v2 Checkout-NodeJS-SDK
使用带有黑色 Debit/Credit 卡按钮的 PayPal Checkout 前端:https://developer.paypal.com/demo/checkout/#/pattern/server
直接支付仅限信用卡到paypal。
因此,您可以使用 Braintree Direct.
实现支付集成
const braintree = require("braintree");
const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox, // Sandbox or Production
merchantId: "Your_merchatn_id",
publicKey: "Your_public key",
privateKey: "Your_private_key"
});
您可以使用 merchantId, publicKey, privateKey.
进行身份验证
gateway.transaction.sale({
amount: `10`,
paymentMethodNonce: "fake-valid-nonce",
options: {
submitForSettlement: true,
storeInVaultOnSuccess: true
}
}, function (err, result) {
if (err) {
console.error(err);
}
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
console.log('Customer ID: ' + result.transaction.customer.id);
var customer_id = result.transaction.customer.id;
let creditCardParams = {
customer_id,
number: `4111111111111111`,
expirationDate: `04/2022`,
cvv: `133`
};
gateway.creditCard.create(creditCardParams, (err, response) => {
if(err) {
console.log(err.message);
} else {
console.log(response);
}
});
} else {
console.error(result);
}
});
我正尝试在 node.js
中使用 PayPal 处理信用卡
使用万事达卡,以下代码使用状态代码为 201
的沙箱帐户。
但是,不使用 'visa'、'amex'.
使用 'visa'、'amex' 卡,我得到 500
状态代码,但找不到错误详细信息。
谁见过这个案例?
var paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox',
'client_id': 'CLIENT_ID',
'client_secret': 'CLIENT_SECRET_KEY'
});
var payment = {
"intent": "authorize",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card": {
"type": "visa",//visa//mastercard//amex
"expire_month": 1,
"expire_year": 2022,
"cvv2": "VISA_CCV2",
"number": "VISA_NUMBER"
}
}]
},
"redirect_urls": {
"return_url": "http://127.0.0.1:3000/success",
"cancel_url": "http://127.0.0.1:3000/err"
},
"transactions": [{
"item_list": {
"items": [{
"name": "media dvd",
"sku": "001",
"price": "1.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"total": 1.00,
"currency": "USD"
},
"description": " a book on mean stack "
}]
}
paypal.payment.create(payment, { timeout: 10000 }, function (err, payment) {
if (err) {
console.log(err, payment);
}
else {
console.log(payment);
}
});
发件人:https://developer.paypal.com/docs/api/payments/v1/
Important: The use of the PayPal REST /payments APIs to accept credit card payments is restricted. Instead, you can accept credit card payments with Braintree Direct.
(Braintree direct 将是一个完整的网关帐户,需要帐户批准并且仅适用于企业 in certain countries.)
由于您试图将旧的东西与旧的 SDK 集成,并且不能在实时环境中使用 - 这是最好的 PayPal 替代方案:
使用新的、受支持的 v2 Checkout-NodeJS-SDK
使用带有黑色 Debit/Credit 卡按钮的 PayPal Checkout 前端:https://developer.paypal.com/demo/checkout/#/pattern/server
直接支付仅限信用卡到paypal。 因此,您可以使用 Braintree Direct.
实现支付集成const braintree = require("braintree");
const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox, // Sandbox or Production
merchantId: "Your_merchatn_id",
publicKey: "Your_public key",
privateKey: "Your_private_key"
});
您可以使用 merchantId, publicKey, privateKey.
进行身份验证gateway.transaction.sale({
amount: `10`,
paymentMethodNonce: "fake-valid-nonce",
options: {
submitForSettlement: true,
storeInVaultOnSuccess: true
}
}, function (err, result) {
if (err) {
console.error(err);
}
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
console.log('Customer ID: ' + result.transaction.customer.id);
var customer_id = result.transaction.customer.id;
let creditCardParams = {
customer_id,
number: `4111111111111111`,
expirationDate: `04/2022`,
cvv: `133`
};
gateway.creditCard.create(creditCardParams, (err, response) => {
if(err) {
console.log(err.message);
} else {
console.log(response);
}
});
} else {
console.error(result);
}
});