From c405823e0ab3bf99a5e92b956088e24965f9dab5 Mon Sep 17 00:00:00 2001 From: Gerson Vasquez Date: Wed, 25 May 2022 16:34:40 -0400 Subject: [PATCH 1/3] fix(efectivo): Se consultan los medios de pagos activos --- .gitignore | 1 + lib/errors.json | 4 ++-- lib/index.js | 2 +- lib/resources/cash.js | 35 +++++++++++----------------------- lib/resources/customers.js | 4 ++-- lib/resources/index.js | 1 - lib/resources/plans.js | 4 ++-- lib/resources/subscriptions.js | 4 ++-- package.json | 2 +- 9 files changed, 22 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index a50ce78..1695512 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ tests/testing.js +package-lock.json diff --git a/lib/errors.json b/lib/errors.json index 830f759..23c1d12 100644 --- a/lib/errors.json +++ b/lib/errors.json @@ -36,7 +36,7 @@ "EN": "[108] Error encrypting the data, please retry the operation" }, "109": { - "ES": "[109] Método de pago en efectivo no válido, unicamnete soportados (efecty - baloto - gana)", - "EN": "[109] Unsupported payment method, we only support (efecty - baloto - gana)" + "ES": "[109] Método de pago en efectivo no válido, unicamnete soportados efecty, gana, redservi, puntored, sured", + "EN": "[109] Unsupported payment method, we only support efecty, gana, redservi, puntored, sured" } } diff --git a/lib/index.js b/lib/index.js index b855743..ccf7e2f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,7 +4,7 @@ * Module dependencies */ -var debug = require('debug')('epayco:api'); +//var debug = require('debug')('epayco:api'); /** diff --git a/lib/resources/cash.js b/lib/resources/cash.js index 9dac7af..614ee64 100644 --- a/lib/resources/cash.js +++ b/lib/resources/cash.js @@ -24,31 +24,18 @@ util.inherits(cash, Resource); * @param {Object} options * @api public */ -cash.prototype.create = function(type, options) { - var url; - switch (type) { - case "efecty": - url = "/restpagos/v2/efectivo/efecty"; - break; - case "baloto": - url = "/restpagos/v2/efectivo/baloto"; - break; - case "gana": - url = "/restpagos/v2/efectivo/gana"; - break; - case "redservi": - url = "/restpagos/v2/efectivo/redservi"; - break; - case "puntored": - url = "/restpagos/v2/efectivo/puntored"; - break; - case "sured": - url = "/restpagos/v2/efectivo/sured"; - break; - default: - throw new EpaycoError(this._epayco.lang, 109); +cash.prototype.create = async function(type, options) { + var methods_payment = await this.request('get', '/payment/cash/entities', [], false, false, false, true); + if(!methods_payment.data && !Array.isArray(methods_payment.data)){ + throw new EpaycoError(this._epayco.lang, 106); } - return this.request('post', url, options, sw = true, cashData = true); + var entities = methods_payment.data.map(function(item){ + return item.name.toLowerCase(); + }) + if(!entities.includes(type.toLowerCase())){ + throw new EpaycoError(this._epayco.lang, 109); + } + return this.request('post', "/restpagos/v2/efectivo/"+type, options, sw = true, cashData = true); }; /** diff --git a/lib/resources/customers.js b/lib/resources/customers.js index 11de672..a9399d5 100644 --- a/lib/resources/customers.js +++ b/lib/resources/customers.js @@ -34,7 +34,7 @@ customers.prototype.create = function(options) { * @api public */ customers.prototype.get = function(uid) { - return this.request('get', "/payment/v1/customer/" + this._epayco.apiKey + "/" + uid + "/", {}, sw = false); + return this.request('get', "/payment/v1/customer/" + this._epayco.apiKey + "/" + uid, {}, sw = false); }; /** @@ -42,7 +42,7 @@ customers.prototype.get = function(uid) { * @api public */ customers.prototype.list = function() { - return this.request('get', "/payment/v1/customers/" + this._epayco.apiKey + "/", {}, sw = false); + return this.request('get', "/payment/v1/customers/" + this._epayco.apiKey, {}, sw = false); }; /** diff --git a/lib/resources/index.js b/lib/resources/index.js index 8cb25c1..956fe38 100644 --- a/lib/resources/index.js +++ b/lib/resources/index.js @@ -59,7 +59,6 @@ Resource.prototype.request = async function (method, url, data, sw, cashData, ca 'Authorization': token_bearer } }; - var send = await sendData(options, data) return send; diff --git a/lib/resources/plans.js b/lib/resources/plans.js index 70cd8a9..937ae19 100644 --- a/lib/resources/plans.js +++ b/lib/resources/plans.js @@ -34,7 +34,7 @@ plans.prototype.create = function(options) { * @api public */ plans.prototype.get = function(uid) { - return this.request('get', "/recurring/v1/plan/" + this._epayco.apiKey + "/" + uid + "/", {}, sw = false); + return this.request('get', "/recurring/v1/plan/" + this._epayco.apiKey + "/" + uid, {}, sw = false); }; /** @@ -42,7 +42,7 @@ plans.prototype.get = function(uid) { * @api public */ plans.prototype.list = function() { - return this.request('get', "/recurring/v1/plans/" + this._epayco.apiKey + "/", {}, sw = false); + return this.request('get', "/recurring/v1/plans/" + this._epayco.apiKey, {}, sw = false); }; /** diff --git a/lib/resources/subscriptions.js b/lib/resources/subscriptions.js index 79983e2..4fec021 100644 --- a/lib/resources/subscriptions.js +++ b/lib/resources/subscriptions.js @@ -34,7 +34,7 @@ subscriptions.prototype.create = function(options) { * @api public */ subscriptions.prototype.get = function(uid) { - return this.request('get', "/recurring/v1/subscription/" + uid + "/" + this._epayco.apiKey + "/", {}, sw = false); + return this.request('get', "/recurring/v1/subscription/" + uid + "/" + this._epayco.apiKey, {}, sw = false); }; /** @@ -42,7 +42,7 @@ subscriptions.prototype.get = function(uid) { * @api public */ subscriptions.prototype.list = function() { - return this.request('get', "/recurring/v1/subscriptions/" + this._epayco.apiKey + "/", {}, sw = false); + return this.request('get', "/recurring/v1/subscriptions/" + this._epayco.apiKey, {}, sw = false); }; /** diff --git a/package.json b/package.json index c0fe4ec..d7de85e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "epayco-sdk-node", - "version": "1.1.1", + "version": "1.2.1", "description": "Epayco API client for node.js", "main": "lib/index.js", "scripts": { From 3143b401e1b11759c17c7478e3c1bae4a626aac6 Mon Sep 17 00:00:00 2001 From: Gerson Vasquez Date: Wed, 1 Jun 2022 11:47:59 -0400 Subject: [PATCH 2/3] fix(efectivo): Se elimina espacios en blanco del nombre de los medios de pago de efectivo --- lib/resources/cash.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/resources/cash.js b/lib/resources/cash.js index 614ee64..8d13301 100644 --- a/lib/resources/cash.js +++ b/lib/resources/cash.js @@ -25,17 +25,22 @@ util.inherits(cash, Resource); * @api public */ cash.prototype.create = async function(type, options) { + medio = type.toLowerCase(); + if(medio == "baloto"){ + throw new EpaycoError(this._epayco.lang, 109); + } var methods_payment = await this.request('get', '/payment/cash/entities', [], false, false, false, true); - if(!methods_payment.data && !Array.isArray(methods_payment.data)){ + + if(!methods_payment.data || !Array.isArray(methods_payment.data) || methods_payment.data.length == 0){ throw new EpaycoError(this._epayco.lang, 106); } var entities = methods_payment.data.map(function(item){ - return item.name.toLowerCase(); + return item.name.toLowerCase().replace(" ", ""); }) - if(!entities.includes(type.toLowerCase())){ + if(!entities.includes(medio)){ throw new EpaycoError(this._epayco.lang, 109); } - return this.request('post', "/restpagos/v2/efectivo/"+type, options, sw = true, cashData = true); + return this.request('post', "/restpagos/v2/efectivo/"+medio, options, sw = true, cashData = true); }; /** From 4cd9085a9d757009ce5f9038cdba19623521f5b6 Mon Sep 17 00:00:00 2001 From: Gerson Vasquez Date: Tue, 5 Jul 2022 19:35:17 -0400 Subject: [PATCH 3/3] chore(README): se actualiza readme --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 50df6d4..782b309 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,7 @@ var pse_info = { last_name: "PAYCO", email: "no-responder@payco.co", country: "CO", + city: "Bogota", cell_phone: "3010000001", ip:"190.000.000.000", /*This is the client's IP, it is required */ url_response: "https://ejemplo.com/respuesta.html", @@ -418,6 +419,8 @@ var cash_info = { name: "testing", last_name: "PAYCO", email: "test@mailinator.com", + country: "CO", + city: "bogota", cell_phone: "3010000001", end_date: "2020-12-05", ip:"190.000.000.000", /*This is the client's IP, it is required */ @@ -635,7 +638,16 @@ var body = { value: "100", tax: "0", tax_base: "0", - method_confirmation: "" + method_confirmation: "GET", + url_response: "https://ejemplo.com/respuesta.html", + url_confirmation: "https://ejemplo.com/confirmacion", + extra1: "", + extra2: "", + extra3: "", + extra4: "", + extra5: "", + extra6: "" + } epayco.daviplata.create(body) .then(function(daviplata){ @@ -686,7 +698,13 @@ var body = { ico: 0, tax_base: 0, url_confirmation: "", - method_confirmation: "" + method_confirmation: "", + extra1: "", + extra2: "", + extra3: "", + extra4: "", + extra5: "", + extra6: "" } epayco.safetypay.create(body)