rgcl / webpay-nodejs

[Spanish/Chile] Módulo no oficial para integrar WebPay Plus en Node.js, con soporte para promesas.
GNU Lesser General Public License v3.0
93 stars 32 forks source link

Error manejando promesas #1

Closed churro90 closed 6 years ago

churro90 commented 6 years ago

Hola, Estoy tratando de realizar esta integración para una plataforma que estoy creando actualmente, pero me tira un error, específicamente en la línea en que se instancia webpay, es decir:

const WebPay = require('webpay-nodejs');

let wp = new WebPay({
    commerceCode: youCommerceCode,
    publicKey: youPublicKey,
    privateKey: youPrivateKey,
    webpayKey: youWebpayKey,
    env: WebPay.ENV.INTEGRACION
});

Cuando corro el servidor para realizar pruebas me arroja el siguiente error:

UnhandledPromiseRejectionWarning: Error: Could not find openssl on your system on this path: openssl
    at C:\Users\marti\Desktop\WebpayPrueba\node_modules\pem\lib\openssl.js:238:23
    at F (C:\Users\marti\Desktop\WebpayPrueba\node_modules\which\which.js:68:16)
    at E (C:\Users\marti\Desktop\WebpayPrueba\node_modules\which\which.js:80:29)
    at C:\Users\marti\Desktop\WebpayPrueba\node_modules\which\which.js:89:16
    at C:\Users\marti\Desktop\WebpayPrueba\node_modules\isexe\index.js:42:5
    at C:\Users\marti\Desktop\WebpayPrueba\node_modules\isexe\windows.js:36:5
    at FSReqWrap.oncomplete (fs.js:152:21)
(node:10224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:10224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Alguna idea? Estuve leyendo que con versiones nuevas de Node no se pueden manejar los rejects de promesas de manera asíncrona pero no estoy muy seguro como solucionar esto.

rgcl commented 6 years ago

Hola, lo que vez es la excepción de la excepción. Es decir, el error original es que la dependencia llamada "pem" no encuentra openssl.

Luego como no estás manejando la excepción, node bota el hilo.

Para manejar la excepción debes usar catch en la promesa agregando .catch(fn) Al llamar algún método de tu wp.

Por ejemplo:

wp.initTransaction(params) .then(callback) .catch((error) => {

console.log(error)

})

Con esto evitas que node bote el hilo, Pero el error persiste claro.

Para solucionarlo definitivamente revisa el readme del módulo pem. Al parecer debes instalar openssl.

El mar., 24 de abr. de 2018 19:39, churro90 notifications@github.com escribió:

Hola, Estoy tratando de realizar esta integración para una plataforma que estoy creando actualmente, pero me tira un error, específicamente en la línea en que se instancia webpay, es decir:

const WebPay = require('webpay-nodejs');

let wp = new WebPay({ commerceCode: youCommerceCode, publicKey: youPublicKey, privateKey: youPrivateKey, webpayKey: youWebpayKey, env: WebPay.ENV.INTEGRACION });

Cuando corro el servidor para realizar pruebas me arroja el siguiente error:

UnhandledPromiseRejectionWarning: Error: Could not find openssl on your system on this path: openssl at C:\Users\marti\Desktop\WebpayPrueba\node_modules\pem\lib\openssl.js:238:23 at F (C:\Users\marti\Desktop\WebpayPrueba\node_modules\which\which.js:68:16) at E (C:\Users\marti\Desktop\WebpayPrueba\node_modules\which\which.js:80:29) at C:\Users\marti\Desktop\WebpayPrueba\node_modules\which\which.js:89:16 at C:\Users\marti\Desktop\WebpayPrueba\node_modules\isexe\index.js:42:5 at C:\Users\marti\Desktop\WebpayPrueba\node_modules\isexe\windows.js:36:5 at FSReqWrap.oncomplete (fs.js:152:21) (node:10224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:10224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Alguna idea? Estuve leyendo que con versiones nuevas de Node no se pueden manejar los rejects de promesas de manera asíncrona pero no estoy muy seguro como solucionar esto.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sapienman/webpay-nodejs/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyltjEOpq5RXWnFGzDxW3gP7F11he5Wks5tr6m4gaJpZM4TihwQ .

rgcl commented 6 years ago

*ves.

churro90 commented 6 years ago

Gracias! Revisé el readme del módulo pem y lo arregle finalmente incluyendo el siguiente código dentro de mi punto de entrada (app.js):

const pem = require('pem');
 pem.config({
    pathOpenSSL: 'C:/GnuWin32/bin/openssl'
}); 

Ojalá a alguien le sirva! slds

norwebcl commented 6 years ago

Hola amigos, muchas gracias por el aporte.

Comentarles que tenemos un error parecido trabajando con angular5:

ERROR in ./node_modules/pem/lib/openssl.js Module not found: Error: Can't resolve 'child_process' in '/usr/local/bin/benjamin/node_modules/pem/lib'

Es un error del módulo pem al parecer, y el archivo openssl.ts

tienen alguna información de cómo poder solucionarlo?

Un saludo!