UNPKG

paymentjs

Version:

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

28 lines (25 loc) 693 B
import Payment from '../payment' import Response from '../response' import stripe from 'stripe' export default class Stripe extends Payment { constructor(config){ super(config); this.stripe = stripe(config.key); } async purchase(order, options){ try { let charge = Object.assign({ amount: order.amount, currency: order.currency, }, options); let response = await this.stripe.charges.create(charge); if (response.status == 'succeeded') { return this.response(response); } else { return this.response(response, { error:true }); } } catch (e) { return this.response(e, { error:true }); } } }