sinusGob sinusGob - 1 year ago 69
Node.js Question

How does paypal rest sdk identify which card number belong to which card type?

Im trying to integrate paypal payment system via paypal-rest-node sdk, and I'm a little bit confused on how to tell which card numbers belong to which card types

For example

These are the codes, that i straight copy from their github page, but in one of their information, it says

"type:" "visa"
. So technically on the clientside a user would type in something and then they would click form submit to send the data to the server. but Im kinda confused on the type.

var card_data = {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"cvv2": "123",
"first_name": "Joe",
"last_name": "Shopper"

paypal.creditCard.create(card_data, function(error, credit_card){
if (error) {
throw error;
} else {
console.log("Create Credit-Card Response");

couldn't the API tells which card numbers belong to which card type?

Answer Source

You can use a module like credit-card-type

let creditCardType = require('credit-card-type');

let visaCards = creditCardType(yourCCNumber);
console.log(visaCards[0].type);  // Type
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download