185 lines
6.4 KiB
TypeScript
185 lines
6.4 KiB
TypeScript
// Metro module 3844 (f3845).
|
|
import Record from "../lib/Record";
|
|
import { createInvoiceItemFromServer } from "../modules/premium/PremiumSubscriptionInvoiceItem";
|
|
import { $callWithNewTarget } from "../_hermes/prelude";
|
|
class BaseInvoiceRecord extends Record {
|
|
constructor(a0) {
|
|
super();
|
|
this.total = a0.total;
|
|
this.subtotal = a0.subtotal;
|
|
this.tax = a0.tax;
|
|
this.currency = a0.currency;
|
|
let invoiceItems = a0.invoiceItems;
|
|
if (invoiceItems == null) {
|
|
invoiceItems = [];
|
|
}
|
|
this.invoiceItems = invoiceItems;
|
|
}
|
|
static createFromServer(a0) {
|
|
const { total, subtotal, tax, currency } = a0;
|
|
let invoiceItems = a0.invoice_items.map((invoice_item) => ({
|
|
skuId: invoice_item.sku_id,
|
|
quantity: invoice_item.quantity,
|
|
description: invoice_item.description
|
|
}));
|
|
const prototypeOf = Object.getPrototypeOf(BaseInvoiceRecord);
|
|
const r18 = Object.create(BaseInvoiceRecord.prototype);
|
|
const r19 = $callWithNewTarget(prototypeOf, r18, BaseInvoiceRecord);
|
|
const r20 = r19 instanceof Object ? r19 : r18;
|
|
r20.total = total;
|
|
r20.subtotal = subtotal;
|
|
r20.tax = tax;
|
|
r20.currency = currency;
|
|
if (invoiceItems == null) {
|
|
invoiceItems = [];
|
|
}
|
|
r20.invoiceItems = invoiceItems;
|
|
return r20;
|
|
}
|
|
static createInvoiceFromOrder(a0) {
|
|
const billing_facet = a0.billing_facet;
|
|
const invoice_preview = billing_facet != null ? billing_facet.invoice_preview : null;
|
|
if (invoice_preview == null) {
|
|
return null;
|
|
}
|
|
let invoiceItems = invoice_preview.line_items.map((line_item) => {
|
|
const r9 = a0.order_line_items.find((order_line_item) => order_line_item.id === line_item.ref_order_line_item_id);
|
|
return r9 != null ? {
|
|
skuId: r9.sku_id,
|
|
unitPrice: {
|
|
amount: line_item.unit_price,
|
|
currency: invoice_preview.currency
|
|
},
|
|
quantity: line_item.quantity
|
|
} : null;
|
|
}).filter((item) => item != null);
|
|
const { total, subtotal, tax, currency } = invoice_preview;
|
|
const prototypeOf = Object.getPrototypeOf(BaseInvoiceRecord);
|
|
const r26 = Object.create(BaseInvoiceRecord.prototype);
|
|
const r27 = $callWithNewTarget(prototypeOf, r26, BaseInvoiceRecord);
|
|
const r28 = r27 instanceof Object ? r27 : r26;
|
|
r28.total = total;
|
|
r28.subtotal = subtotal;
|
|
r28.tax = tax;
|
|
r28.currency = currency;
|
|
if (invoiceItems == null) {
|
|
invoiceItems = [];
|
|
}
|
|
r28.invoiceItems = invoiceItems;
|
|
return r28;
|
|
}
|
|
getInvoicePreviewLineItemForSku(c13679_0) {
|
|
let r7 = this.invoiceItems.find((invoiceItem) => invoiceItem.skuId === c13679_0);
|
|
if (r7 == null) {
|
|
r7 = null;
|
|
}
|
|
return r7;
|
|
}
|
|
getInvoicePreviewLineItemUnitPriceForSku(a0) {
|
|
const invoicePreviewLineItemForSku = this.getInvoicePreviewLineItemForSku(a0);
|
|
return invoicePreviewLineItemForSku == null ? null : invoicePreviewLineItemForSku.unitPrice == null ? null : invoicePreviewLineItemForSku.unitPrice.amount;
|
|
}
|
|
}
|
|
class InvoiceRecord extends BaseInvoiceRecord {
|
|
constructor(a0) {
|
|
super(a0);
|
|
this.id = a0.id;
|
|
let invoiceItems = a0.invoiceItems;
|
|
if (invoiceItems == null) {
|
|
invoiceItems = [];
|
|
}
|
|
this.invoiceItems = invoiceItems;
|
|
this.taxInclusive = a0.taxInclusive;
|
|
this.subscriptionPeriodStart = a0.subscriptionPeriodStart;
|
|
this.subscriptionPeriodEnd = a0.subscriptionPeriodEnd;
|
|
this.status = a0.status;
|
|
this.orbsReward = a0.orbsReward;
|
|
this.checkoutContext = a0.checkoutContext;
|
|
}
|
|
static createInvoiceFromServer(a0) {
|
|
const invoice_items = a0.invoice_items;
|
|
const r4 = {
|
|
id: a0.id,
|
|
invoiceItems: invoice_items == null ? void 0 : invoice_items.map(createInvoiceItemFromServer),
|
|
total: a0.total,
|
|
subtotal: a0.subtotal,
|
|
currency: a0.currency,
|
|
tax: a0.tax,
|
|
taxInclusive: a0.tax_inclusive,
|
|
subscriptionPeriodStart: new Date(a0.subscription_period_start),
|
|
subscriptionPeriodEnd: new Date(a0.subscription_period_end),
|
|
status: a0.status,
|
|
orbsReward: a0.orbs_reward,
|
|
checkoutContext: a0.checkout_context
|
|
};
|
|
const prototypeOf = Object.getPrototypeOf(InvoiceRecord);
|
|
const r42 = Object.create(InvoiceRecord.prototype);
|
|
const r45 = $callWithNewTarget(prototypeOf, r42, InvoiceRecord, r4);
|
|
const r46 = r45 instanceof Object ? r45 : r42;
|
|
r46.id = r4.id;
|
|
let invoiceItems = r4.invoiceItems;
|
|
if (invoiceItems == null) {
|
|
invoiceItems = [];
|
|
}
|
|
r46.invoiceItems = invoiceItems;
|
|
r46.taxInclusive = r4.taxInclusive;
|
|
r46.subscriptionPeriodStart = r4.subscriptionPeriodStart;
|
|
r46.subscriptionPeriodEnd = r4.subscriptionPeriodEnd;
|
|
r46.status = r4.status;
|
|
r46.orbsReward = r4.orbsReward;
|
|
r46.checkoutContext = r4.checkoutContext;
|
|
return r46;
|
|
}
|
|
static createFromOTPPreview(a0) {
|
|
const invoice_items = a0.invoice_items;
|
|
const r17 = {
|
|
id: "",
|
|
invoiceItems: invoice_items == null ? void 0 : invoice_items.map(createInvoiceItemFromServer),
|
|
total: a0.amount,
|
|
subtotal: a0.subtotal,
|
|
currency: a0.currency,
|
|
tax: a0.tax,
|
|
taxInclusive: a0.tax_inclusive,
|
|
subscriptionPeriodStart: new Date(0),
|
|
subscriptionPeriodEnd: new Date(0),
|
|
orbsReward: a0.orbs_reward,
|
|
checkoutContext: a0.checkout_context
|
|
};
|
|
const prototypeOf = Object.getPrototypeOf(InvoiceRecord);
|
|
const r40 = Object.create(InvoiceRecord.prototype);
|
|
const r43 = $callWithNewTarget(prototypeOf, r40, InvoiceRecord, r17);
|
|
const r44 = r43 instanceof Object ? r43 : r40;
|
|
r44.id = r17.id;
|
|
let invoiceItems = r17.invoiceItems;
|
|
if (invoiceItems == null) {
|
|
invoiceItems = [];
|
|
}
|
|
r44.invoiceItems = invoiceItems;
|
|
r44.taxInclusive = r17.taxInclusive;
|
|
r44.subscriptionPeriodStart = r17.subscriptionPeriodStart;
|
|
r44.subscriptionPeriodEnd = r17.subscriptionPeriodEnd;
|
|
r44.status = r17.status;
|
|
r44.orbsReward = r17.orbsReward;
|
|
r44.checkoutContext = r17.checkoutContext;
|
|
return r44;
|
|
}
|
|
findInvoiceItemByPlanId(c13680_0) {
|
|
let r7 = this.invoiceItems.find((invoiceItem) => invoiceItem.subscriptionPlanId === c13680_0);
|
|
if (r7 == null) {
|
|
r7 = null;
|
|
}
|
|
return r7;
|
|
}
|
|
getDiscountIdIfExists() {
|
|
const r7 = this.invoiceItems.find((invoiceItem) => invoiceItem.discounts.length > 0);
|
|
if (r7 != null && r7.discounts.length !== 0) {
|
|
const r11 = r7.discounts[0];
|
|
if (r11 != null) {
|
|
return r11.discount_id;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
export default InvoiceRecord;
|
|
export { BaseInvoiceRecord };
|