UNPKG

paymentjs

Version:

A framework agnostic, multi-gateway payment processing library for Node.js, Inspired by Omnipay for PHP

33 lines (29 loc) 918 B
import _ from 'lodash' import ejs from 'ejs' export default class Response { constructor(body, options = { error: false, redirect: null}, config) { this.body = body; this.options = options; this.config = config; } async isSuccess(){ return this.options.error !== true; } isRedirect(){ return this.options.redirect !== null; } redirect(){ return new Promise((resolve, reject)=>{ let { redirect } = this.options; if (redirect) { resolve(ejs.render('<form method="<%=method%>" action="<%=url%>" id="payment"><% for (let k in body){ %><input type="hidden" name="<%=k%>" value="<%=body[k]%>" /><% } %></form><script type="text/javascript">document.getElementById("payment").submit();</script>', { url: redirect.url, method: redirect.method, body: this.body })); } else { reject(); } }) } }