Skip to content

Instantly share code, notes, and snippets.

@crorodriguezro
Created June 2, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crorodriguezro/3fcd2ff4b7725a77364322ccf028c096 to your computer and use it in GitHub Desktop.
Save crorodriguezro/3fcd2ff4b7725a77364322ccf028c096 to your computer and use it in GitHub Desktop.
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);
});
@crorodriguezro
Copy link
Author

err:  { Error: cannot POST /payment/v1/charge/subscription/create (500)
    at Response.toError (C:\x\node_modules\superagent\lib\node\response.js:94:15)
    at ResponseBase._setStatusProperties (C:\x\node_modules\superagent\lib\response-base.js:123:16)
    at new Response (C:\x\node_modules\superagent\lib\node\response.js:41:8)
    at Request._emitResponse (C:\x\node_modules\superagent\lib\node\index.js:752:20)
    at IncomingMessage.parser (C:\x\node_modules\superagent\lib\node\index.js:916:38)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  status: 500,
  text: 'Server error.',
  method: 'POST',
  path: '/payment/v1/charge/subscription/create' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment