forest-express
Version:
Official package for all Forest Express Lianas
30 lines (29 loc) • 1.11 kB
JavaScript
;
var P = require('bluebird');
function InvoicesGetter(Implementation, params, opts, integrationInfo) {
var stripe = opts.integrations.stripe.stripe(opts.integrations.stripe.apiKey);
var collectionModel = null;
function getInvoice(invoiceId) {
return new P(function (resolve, reject) {
stripe.invoices.retrieve(invoiceId, function (error, invoice) {
if (error) {
return reject(error);
}
return resolve(invoice);
});
});
}
this.perform = function () {
collectionModel = integrationInfo.collection;
var collectionFieldName = integrationInfo.field,
embeddedPath = integrationInfo.embeddedPath;
var fieldName = embeddedPath ? "".concat(collectionFieldName, ".").concat(embeddedPath) : collectionFieldName;
return getInvoice(params.invoiceId).then(function (invoice) {
return Implementation.Stripe.getCustomerByUserField(collectionModel, fieldName, invoice.customer).then(function (customer) {
invoice.customer = customer;
return invoice;
});
});
};
}
module.exports = InvoicesGetter;