Skip to content

Conversation

@ffflabs
Copy link

@ffflabs ffflabs commented Feb 18, 2020

Cambio 1:

node-soap tiene métodos asíncronos nativos, de manera que no es necesario usar el constructor de promesas como envoltorio.

Por ejemplo, en vez de:

     // versión resumida
    _getClient(type) {
      let options={...};
      return new Promise((resolve, reject) => {
       soap.createClient(this.env[type], options, (err, client) => {
          if(err) {
            return reject(err);
          }
          resolve(client);
       });
      });
    }

Se puede hacer:

    _getClient(type) {
      let options={};
      return soap.createClientAsync(this.env[type], options)
      .then(client => {
          return client;
      }).catch(err=>{
        return Promise.reject(err);
      });
    }

(en general todo los los métodos de client soportan funcionar como promesa si se usa el sufijo Async.

Cambio 2

WebpayOneclick también soporta el método nullify cuando la transacción ocurrió en otro dia contable. (https://www.transbankdevelopers.cl/referencia/webpay#anular-un-pago-webpay-oneclick). En rigor se puede llamar directo a this.webpay._getClient('nullify') pero parece mejor tratar a _getClient como método privado y no llamarlo desde fuera de la librería.

Añadí el método nullify a webpayOneclick, aprovechando de usar la sintaxis de promesa que menciono más arriba.

A grandes rasgos:

return this.webpay
      ._getClient('nullify', options)
      .then(client => {
        return client.nullifyAsync({
          nullificationInput: props
        });
      })
      .then(([soapResult, rawResponse, soapHeader, rawRequest]) => {
          return Promise.resolve(soapResult.return);
      })
      .catch(err => {
        return Promise.reject(err);
      });

@ffflabs
Copy link
Author

ffflabs commented Feb 26, 2020

@rgcl ping

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant