@rytass/invoice-adapter-ecpay
Version:
Rytass Invoice Gateway - ECPay
41 lines (38 loc) • 1.08 kB
JavaScript
import { InvoiceState } from '@rytass/invoice';
class ECPayInvoice {
invoiceNumber;
randomCode;
issuedOn;
issuedAmount;
orderId;
taxType;
items;
allowances = [];
state = InvoiceState.ISSUED;
voidOn = null;
nowAmount;
awardType;
constructor(options){
this.issuedOn = options.issuedOn;
this.items = options.items;
this.nowAmount = options.items.reduce((sum, item)=>sum + item.quantity * item.unitPrice, 0);
this.issuedAmount = this.nowAmount;
this.randomCode = options.randomCode;
this.invoiceNumber = options.invoiceNumber;
this.orderId = options.orderId;
this.taxType = options.taxType;
this.awardType = options.awardType;
if (options.isVoid) {
this.setVoid();
}
}
setVoid() {
this.state = InvoiceState.VOID;
this.voidOn = new Date();
}
async addAllowance(allowance) {
this.allowances.push(allowance);
this.nowAmount = allowance.remainingAmount;
}
}
export { ECPayInvoice };