Created
June 2, 2019 17:31
-
-
Save crorodriguezro/3fcd2ff4b7725a77364322ccf028c096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const epayco = require('epayco-node')({ | |
apiKey: 'xxx', | |
privateKey: 'xxx', | |
lang: 'ES', | |
test: false | |
}); | |
const credit_info = { | |
"card[number]": "4575623182290326", | |
"card[exp_year]": "2017", | |
"card[exp_month]": "07", | |
"card[cvc]": "123" | |
}; | |
let tokenExt; | |
let customerIdExt; | |
const docType = "CC"; | |
const docNum = "1026"; | |
const phoneNumber = "3005234321"; | |
const name = "Joe Doe"; | |
const email = "email@cris.com"; | |
const address = "calle falsa 123"; | |
const city = "Bogota"; | |
epayco.token.create(credit_info) | |
.then(function (tokenResponse) { | |
console.log("Token creado", tokenResponse); | |
const {data: {id}} = tokenResponse; | |
tokenExt = id; | |
const customer_info = { | |
token_card: id, | |
name: name, //opcional | |
default: true, | |
email: email, // obligatorio | |
//Optional parameters: These parameters are important when validating the credit card transaction | |
city: city, | |
address: address, | |
cell_phone: phoneNumber, | |
phone: phoneNumber, | |
}; | |
return epayco.customers.create(customer_info); | |
}) | |
.then(function (customers) { | |
console.log("Customer creado", customers); | |
const {data: {customerId}} = customers; | |
customerIdExt = customerId; | |
const subscription_info = { | |
id_plan: "mensual", | |
customer: customerIdExt, | |
token_card: tokenExt, | |
doc_type: docType, | |
doc_number: docNum, | |
phone: phoneNumber, | |
cell_phone: phoneNumber, | |
}; | |
return epayco.subscriptions.create(subscription_info); | |
}) | |
.then(function (suscription) { | |
console.log("Suscrib creada", suscription); | |
const subscription_info = { | |
id_plan: "mensual", | |
customer: customerIdExt, | |
token_card: tokenExt, | |
url_response: "https:/secure.payco.co/restpagos/testRest/endpagopse.php", | |
url_confirmation: "https:/secure.payco.co/restpagos/testRest/endpagopse.php", | |
doc_type: docType, | |
doc_number: docNum | |
}; | |
return epayco.subscriptions.charge(subscription_info); | |
}) | |
.then(function (charge) { | |
console.log("pago realizado", charge); | |
}) | |
.catch(function (err) { | |
console.log("err: ", err); | |
}); |
Author
crorodriguezro
commented
Jun 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment