I’m trying to make an application to buy games online. And I’m currently working on the payment page. I’ve implimented a PayPal to PayPal transactions successfully and now i’m working on to make a Credit Card to PayPal transactions. So I’ve made a front end page with all the inputs that I’ve needed : Card Number, Expiration Date and CVV. And I want that when I press on the buy button, the client send the card number, expiration date and cvv to an express api. Then when in the api, I make the payment such like the PayPal to PayPal method that I’ve used.
Here is my Client-side code :
const CreditCardNumber = document.getElementById("CreditCardNumber");
const CreditCardCVV = document.getElementById("CreditCardCVV");
const ExpireMonth = document.getElementById("ExpireMonth");
const ExpireYear = document.getElementById("ExpireYear");
fetch(properties.api + '/getProductByInvoiceToken',{
method:'POST',
headers : {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'http://127.0.0.1:5500'
},
body: JSON.stringify({
'number' : CreditCardNumber.value,
'cvv2' : CreditCardCVV.value,
'expireMonth' : ExpireMonth.options[ExpireMonth.selectedIndex].value,
'expireYear' : ExpireYear.options[ExpireYear.selectedIndex].value,
})
})
Here is my code Server-side code :
app.post('/buyWithCreditCard',(req,res)=>{
const { number, expireMonth, expireYear, cvv } = req.body;
paypal.payment.create({
intent: 'sale',
payer: {
payment_method: 'credit_card',
funding_instruments: [{
credit_card: {
number: number,
type: 'visa',
expire_month: expireMonth,
expire_year: expireYear,
cvv2: cvv2,
first_name: "John",
last_name: "Doe"
}
}]
},
transactions: [{
amount: {
total: product.child('Price').val(),
currency: "USD"
},
description: 'Payment desc.'
}]
}, function (error, payment) {
if (error) {
console.log(error.response);
} else {
console.log('LTETT');
}
});
});
and every time I’m trying to pay, the app send me the following error :
{
name: 'PAYEE_ACCOUNT_INVALID',
message: 'Payee account is invalid.',
information_link: 'https://developer.paypal.com/docs/api/payments/v1/#error-PAYEE_ACCOUNT_INVALID', debug_id: 'cd64907fda648',
httpStatusCode: 400
}
Can someone please help with this ?
I’m excepting the server to respond correctly