hapi-middleman-paypal-intacct
Advanced tools
Comparing version 0.0.58 to 0.0.59
@@ -61,2 +61,3 @@ import * as hapi from "hapi"; | ||
webhookHandler(webhook: IWebhookEvent): Promise<void>; | ||
createPayment(invoice: IInvoice): Promise<any>; | ||
validateAccounts(): Promise<void>; | ||
@@ -63,0 +64,0 @@ validateKeys(): Promise<void>; |
@@ -100,21 +100,7 @@ "use strict"; | ||
case "INVOICING.INVOICE.PAID": | ||
const account = this.options.paymentaccounts.currencies[webhook.resource.invoice.total_amount.currency] || this.options.paymentaccounts.default; | ||
try { | ||
const payment = { | ||
customerid: webhook.resource.invoice.billing_info[0].additional_info, | ||
paymentamount: webhook.resource.invoice.total_amount.value, | ||
bankaccountid: account, | ||
refid: webhook.resource.invoice.payments[webhook.resource.invoice.payments.length - 1].transaction_id, | ||
arpaymentitem: [{ | ||
invoicekey: webhook.resource.invoice.number, | ||
amount: webhook.resource.invoice.total_amount.value, | ||
}], | ||
}; | ||
yield this.intacct.createPayment(payment); | ||
yield this.createPayment(webhook.resource.invoice); | ||
} | ||
catch (err) { | ||
const error = JSON.parse(err.message); | ||
if (error.length === 1 && error[0].errorno !== "BL03000130") { | ||
intacctInvoice.PAYPALERROR = err.message; | ||
} | ||
intacctInvoice.PAYPALERROR = err.message; | ||
} | ||
@@ -128,2 +114,27 @@ break; | ||
} | ||
createPayment(invoice) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const account = this.options.paymentaccounts.currencies[invoice.total_amount.currency] || this.options.paymentaccounts.default; | ||
try { | ||
const payment = { | ||
customerid: invoice.billing_info[0].additional_info, | ||
paymentamount: invoice.total_amount.value, | ||
bankaccountid: account, | ||
refid: invoice.payments[invoice.payments.length - 1].transaction_id, | ||
paymentmethod: "Credit Card", | ||
arpaymentitem: [{ | ||
invoicekey: invoice.number, | ||
amount: invoice.total_amount.value, | ||
}], | ||
}; | ||
return yield this.intacct.createPayment(payment); | ||
} | ||
catch (err) { | ||
const error = JSON.parse(err.message); | ||
if (error.length === 1 && error[0].errorno !== "BL03000130") { | ||
throw err; | ||
} | ||
} | ||
}); | ||
} | ||
validateAccounts() { | ||
@@ -266,2 +277,5 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
else if (paypalInvoice.model.status === "PAID" || paypalInvoice.model.status === "MARKED_AS_PAID") { | ||
yield this.createPayment(paypalInvoice.model); | ||
} | ||
return paypalInvoice; | ||
@@ -268,0 +282,0 @@ }); |
{ | ||
"name": "hapi-middleman-paypal-intacct", | ||
"version": "0.0.58", | ||
"version": "0.0.59", | ||
"description": "hapi-middleman module for integrating paypal with intacct", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
57148
807