UNPKG

forest-express

Version:

Official package for all Forest Express Lianas

30 lines (29 loc) 1.11 kB
"use strict"; var P = require('bluebird'); function PaymentsGetter(Implementation, params, opts, integrationInfo) { var stripe = opts.integrations.stripe.stripe(opts.integrations.stripe.apiKey); var collectionModel = null; function getCharge(paymentId) { return new P(function (resolve, reject) { stripe.charges.retrieve(paymentId, function (error, charge) { if (error) { return reject(error); } return resolve(charge); }); }); } this.perform = function () { collectionModel = integrationInfo.collection; var collectionFieldName = integrationInfo.field, embeddedPath = integrationInfo.embeddedPath; var fieldName = embeddedPath ? "".concat(collectionFieldName, ".").concat(embeddedPath) : collectionFieldName; return getCharge(params.paymentId).then(function (payment) { return Implementation.Stripe.getCustomerByUserField(collectionModel, fieldName, payment.customer).then(function (customer) { payment.customer = customer; return payment; }); }); }; } module.exports = PaymentsGetter;