b23-lib 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Auth/index.js +1 -1
- package/dist/Auth/index.js.map +1 -1
- package/dist/Auth/index.mjs +1 -1
- package/dist/Auth/index.mjs.map +1 -1
- package/dist/Classes/Address.d.mts +1 -1
- package/dist/Classes/Address.d.ts +1 -1
- package/dist/Classes/Address.js.map +1 -1
- package/dist/Classes/Address.mjs +1 -1
- package/dist/Classes/Base.d.mts +5 -5
- package/dist/Classes/Base.d.ts +5 -5
- package/dist/Classes/Base.js.map +1 -1
- package/dist/Classes/Base.mjs +1 -1
- package/dist/Classes/Cart.d.mts +27 -12
- package/dist/Classes/Cart.d.ts +27 -12
- package/dist/Classes/Cart.js +1 -1
- package/dist/Classes/Cart.js.map +1 -1
- package/dist/Classes/Cart.mjs +1 -1
- package/dist/Classes/Cart.mjs.map +1 -1
- package/dist/Classes/Common.d.mts +2 -93
- package/dist/Classes/Common.d.ts +2 -93
- package/dist/Classes/Coupon.d.mts +33 -15
- package/dist/Classes/Coupon.d.ts +33 -15
- package/dist/Classes/Coupon.js +1 -1
- package/dist/Classes/Coupon.js.map +1 -1
- package/dist/Classes/Coupon.mjs +1 -1
- package/dist/Classes/Customer.d.mts +2 -2
- package/dist/Classes/Customer.d.ts +2 -2
- package/dist/Classes/Customer.js.map +1 -1
- package/dist/Classes/Customer.mjs +1 -1
- package/dist/Classes/Customer.mjs.map +1 -1
- package/dist/Classes/CustomerAddress.d.mts +1 -1
- package/dist/Classes/CustomerAddress.d.ts +1 -1
- package/dist/Classes/CustomerAddress.js.map +1 -1
- package/dist/Classes/CustomerAddress.mjs +1 -1
- package/dist/Classes/Enum.d.mts +43 -2
- package/dist/Classes/Enum.d.ts +43 -2
- package/dist/Classes/Enum.js +1 -1
- package/dist/Classes/Enum.js.map +1 -1
- package/dist/Classes/Enum.mjs +1 -1
- package/dist/Classes/Error.d.mts +59 -0
- package/dist/Classes/Error.d.ts +59 -0
- package/dist/Classes/Error.js +2 -0
- package/dist/Classes/Error.js.map +1 -0
- package/dist/Classes/Error.mjs +2 -0
- package/dist/Classes/Error.mjs.map +1 -0
- package/dist/Classes/ImageInfo.js +1 -1
- package/dist/Classes/ImageInfo.js.map +1 -1
- package/dist/Classes/ImageInfo.mjs +1 -1
- package/dist/Classes/Inventory.d.mts +25 -6
- package/dist/Classes/Inventory.d.ts +25 -6
- package/dist/Classes/Inventory.js +1 -1
- package/dist/Classes/Inventory.js.map +1 -1
- package/dist/Classes/Inventory.mjs +1 -1
- package/dist/Classes/Inventory.mjs.map +1 -1
- package/dist/Classes/LineItem.d.mts +140 -58
- package/dist/Classes/LineItem.d.ts +140 -58
- package/dist/Classes/LineItem.js +1 -1
- package/dist/Classes/LineItem.js.map +1 -1
- package/dist/Classes/LineItem.mjs +1 -1
- package/dist/Classes/Order.d.mts +7 -51
- package/dist/Classes/Order.d.ts +7 -51
- package/dist/Classes/Order.js +1 -1
- package/dist/Classes/Order.js.map +1 -1
- package/dist/Classes/Order.mjs +1 -1
- package/dist/Classes/Order.mjs.map +1 -1
- package/dist/Classes/Payment.d.mts +4 -4
- package/dist/Classes/Payment.d.ts +4 -4
- package/dist/Classes/Payment.js.map +1 -1
- package/dist/Classes/Payment.mjs +1 -1
- package/dist/Classes/Payment.mjs.map +1 -1
- package/dist/Classes/Price.d.mts +1 -82
- package/dist/Classes/Price.d.ts +1 -82
- package/dist/Classes/Price.js +1 -1
- package/dist/Classes/Price.js.map +1 -1
- package/dist/Classes/Price.mjs +1 -1
- package/dist/Classes/Product.d.mts +103 -85
- package/dist/Classes/Product.d.ts +103 -85
- package/dist/Classes/Product.js +1 -1
- package/dist/Classes/Product.js.map +1 -1
- package/dist/Classes/Product.mjs +1 -1
- package/dist/Classes/Product.mjs.map +1 -1
- package/dist/Classes/ShoppingContainer.d.mts +79 -63
- package/dist/Classes/ShoppingContainer.d.ts +79 -63
- package/dist/Classes/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Classes/TaxRule.d.mts +63 -0
- package/dist/Classes/TaxRule.d.ts +63 -0
- package/dist/Classes/TaxRule.js +2 -0
- package/dist/Classes/TaxRule.js.map +1 -0
- package/dist/Classes/TaxRule.mjs +2 -0
- package/dist/Classes/TaxRule.mjs.map +1 -0
- package/dist/Classes/TieredPrice.d.mts +75 -0
- package/dist/Classes/TieredPrice.d.ts +75 -0
- package/dist/Classes/TieredPrice.js +2 -0
- package/dist/Classes/TieredPrice.js.map +1 -0
- package/dist/Classes/TieredPrice.mjs +2 -0
- package/dist/Classes/TieredPrice.mjs.map +1 -0
- package/dist/Common-D-UoxwM0.d.ts +210 -0
- package/dist/Common-FbQ5-3QN.d.mts +210 -0
- package/dist/chunk-2SGUPNWZ.mjs +2 -0
- package/dist/chunk-2SGUPNWZ.mjs.map +1 -0
- package/dist/chunk-54RUAXYE.mjs +2 -0
- package/dist/chunk-54RUAXYE.mjs.map +1 -0
- package/dist/{chunk-ATUUYYQT.mjs → chunk-55SOBG62.mjs} +2 -2
- package/dist/chunk-55SOBG62.mjs.map +1 -0
- package/dist/{chunk-H5GPM4LA.mjs → chunk-5KD2EW7O.mjs} +2 -2
- package/dist/{chunk-H5GPM4LA.mjs.map → chunk-5KD2EW7O.mjs.map} +1 -1
- package/dist/chunk-72DR3HF2.mjs +2 -0
- package/dist/chunk-72DR3HF2.mjs.map +1 -0
- package/dist/chunk-AMIRIUMH.mjs +2 -0
- package/dist/chunk-AMIRIUMH.mjs.map +1 -0
- package/dist/chunk-CEGQFFYZ.mjs +2 -0
- package/dist/chunk-CEGQFFYZ.mjs.map +1 -0
- package/dist/chunk-EP7WVZXC.mjs +2 -0
- package/dist/chunk-EP7WVZXC.mjs.map +1 -0
- package/dist/chunk-KWH7GE23.mjs +2 -0
- package/dist/chunk-KWH7GE23.mjs.map +1 -0
- package/dist/chunk-LNIZAPER.mjs +2 -0
- package/dist/chunk-LNIZAPER.mjs.map +1 -0
- package/dist/chunk-NJKSUUOB.mjs +2 -0
- package/dist/chunk-NJKSUUOB.mjs.map +1 -0
- package/dist/chunk-NUTKOIGY.mjs +2 -0
- package/dist/chunk-NUTKOIGY.mjs.map +1 -0
- package/dist/chunk-RBROVHJ4.mjs +2 -0
- package/dist/chunk-RBROVHJ4.mjs.map +1 -0
- package/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-6PDP4ETM.mjs +0 -2
- package/dist/chunk-6PDP4ETM.mjs.map +0 -1
- package/dist/chunk-ATUUYYQT.mjs.map +0 -1
- package/dist/chunk-CKUUUEWT.mjs +0 -2
- package/dist/chunk-CKUUUEWT.mjs.map +0 -1
- package/dist/chunk-DKI6BDWK.mjs +0 -2
- package/dist/chunk-DKI6BDWK.mjs.map +0 -1
- package/dist/chunk-K3AXPTGG.mjs +0 -2
- package/dist/chunk-K3AXPTGG.mjs.map +0 -1
- package/dist/chunk-LMMJSJTO.mjs +0 -2
- package/dist/chunk-LMMJSJTO.mjs.map +0 -1
- package/dist/chunk-RWBNLNQ6.mjs +0 -2
- package/dist/chunk-RWBNLNQ6.mjs.map +0 -1
- package/dist/chunk-V4H3X4PI.mjs +0 -2
- package/dist/chunk-V4H3X4PI.mjs.map +0 -1
- package/dist/chunk-WOMA746Z.mjs +0 -2
- package/dist/chunk-WOMA746Z.mjs.map +0 -1
package/dist/Classes/Order.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {a}from'../chunk-RBROVHJ4.mjs';import'../chunk-CEGQFFYZ.mjs';import'../chunk-EP7WVZXC.mjs';import'../chunk-5KD2EW7O.mjs';import'../chunk-2SGUPNWZ.mjs';import'../chunk-LNIZAPER.mjs';import'../chunk-KWH7GE23.mjs';import'../chunk-54RUAXYE.mjs';import'../chunk-72DR3HF2.mjs';import'../chunk-NUTKOIGY.mjs';import {a as a$1}from'../chunk-NJKSUUOB.mjs';import'../chunk-55SOBG62.mjs';var o=(e=>(e.PLACED="PLACED",e.PENDING_PAYMENT="PENDING_PAYMENT",e.PROCESSING="PROCESSING",e.CANCELLED="CANCELLED",e.COMPLETED="COMPLETED",e))(o||{}),r=class extends a{orderNumber;cartId;paymentStatus;holdReason;state;constructor(t,s=new Date){super(t,s),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state;}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let s=this.getLineItems().find(a=>a.getId()===t);if(!s)throw new a$1(t);return s.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{o as OrderState,r as default};//# sourceMappingURL=Order.mjs.map
|
|
2
2
|
//# sourceMappingURL=Order.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Order.ts"],"names":["OrderState","OrderLineItemState","OrderModel","BaseShoppingContainerModel","data","date","newLineItemStateMap","item","currentStateMap","filterRefunded","filteredLineItems","PriceModel","sum","shippingCouponDiscount","c","nonShippingCouponDiscount","grossTotal","lineItemId","LineItemNotFoundError"],"mappings":"6SAeYA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAA,CAAA,MAAA,CAAS,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yB,CAC/B,OAAO,IAAA,CAAK,WACd,CAMO,SAAoB,EAAA,CACzB,OAAO,IAAK,CAAA,MACd,CAMO,gBAAA,EAAkC,CACvC,OAAO,KAAK,aACd,CAMO,aAAwB,EAAA,CAC7B,OAAO,IAAA,CAAK,UACd,CAMO,QAAA,EAAuB,CAC5B,OAAO,IAAK,CAAA,KACd,CAOO,oBAA8C,EAAA,CACnD,OAAO,CAAE,GAAG,IAAA,CAAK,gBAAiB,CACpC,CAQO,gBAAiBE,CAAAA,CAAAA,CAAwC,CAC9D,GAAI,CAAC,IAAK,CAAA,gBAAA,CAAiBA,CAAU,CAAA,CACnC,MAAM,IAAIC,CAAsBD,CAAAA,CAAU,CAE5C,CAAA,OAAO,IAAK,CAAA,gBAAA,CAAiBA,CAAU,CAAA,CAAE,KAC3C,CAOA,UAAA,EAAwB,CACtB,OAAO,CACL,GAAG,MAAM,UAAW,EAAA,CACpB,WAAa,CAAA,IAAA,CAAK,cAAe,EAAA,CACjC,WAAY,IAAK,CAAA,aAAA,EACjB,CAAA,aAAA,CAAe,IAAK,CAAA,gBAAA,GACpB,eAAiB,CAAA,IAAA,CAAK,kBAAmB,EAAA,CAAE,UAAW,EAAA,CACtD,eAAgB,IAAK,CAAA,iBAAA,EAAoB,CAAA,UAAA,EACzC,CAAA,MAAA,CAAQ,KAAK,SAAU,EAAA,CACvB,aAAe,CAAA,IAAA,CAAK,gBAAiB,EAAA,CACrC,WAAY,IAAK,CAAA,aAAA,EACjB,CAAA,KAAA,CAAO,IAAK,CAAA,QAAA,EACZ,CAAA,gBAAA,CAAkB,IAAK,CAAA,oBAAA,EACzB,CACF,CACF","file":"Order.mjs","sourcesContent":["import AddressModel, { AddressData } from \"./Address\";\r\nimport { LineItemNotFoundError } from \"./Cart\";\r\nimport { ISODateTime } from \"./Common\";\r\nimport { CouponCategory } from \"./Coupon\";\r\nimport { PaymentStatus } from \"./Payment\";\r\nimport PriceModel from \"./Price\";\r\nimport BaseShoppingContainerModel, { BaseShoppingContainerAttributes, BaseShoppingContainerData, ShoppingContainerTotal } from \"./ShoppingContainer\";\r\n\r\n/**\r\n * PLACED: Order created, awaiting payment.\r\n * PENDING_PAYMENT: Waiting for payment confirmation.\r\n * PROCESSING: Payment received, order is being fulfilled. Stays here until all line items reach a final state.\r\n * CANCELLED: All line items are cancelled, or order is cancelled before fulfillment.\r\n * COMPLETED: All line items are delivered, returned, or refunded.\r\n */\r\nexport enum OrderState {\r\n PLACED = \"PLACED\",\r\n PENDING_PAYMENT = \"PENDING_PAYMENT\",\r\n PROCESSING = \"PROCESSING\",\r\n CANCELLED = \"CANCELLED\",\r\n COMPLETED = \"COMPLETED\"\r\n}\r\n\r\n/**\r\n * OrderLineItemState\r\n * \r\n * INITIAL: Item added to order, not yet processed.\r\n * PROCESSING: Item is being prepared for shipment.\r\n * SHIPPED: Item dispatched to customer.\r\n * DELIVERED: Item delivered to customer.\r\n * CANCELLED: Item cancelled before shipment or delivery.\r\n * RETURN_REQUESTED: Customer requests to return item.\r\n * RETURNED: Item received back from customer.\r\n * REFUND_INITIATED: Refund initiated for item.\r\n * REFUNDED: Refund processed for item.\r\n * ON_HOLD: Item is paused due to payment, inventory, or other issues.\r\n */\r\nexport enum OrderLineItemState {\r\n INITIAL = \"INITIAL\",\r\n PROCESSING = \"PROCESSING\",\r\n SHIPPED = \"SHIPPED\",\r\n DELIVERED = \"DELIVERED\",\r\n CANCELLED = \"CANCELLED\",\r\n RETURN_REQUESTED = \"RETURN_REQUESTED\",\r\n RETURNED = \"RETURNED\",\r\n REFUND_INITIATED = \"REFUND_INITIATED\",\r\n REFUNDED = \"REFUNDED\",\r\n ON_HOLD = \"ON_HOLD\",\r\n}\r\n\r\n\r\nexport type OrderLineItemStateMap = Record<string, {\r\n state:OrderLineItemState;\r\n reason?: string;\r\n transitionAt: ISODateTime;\r\n}>;\r\n\r\n/**\r\n * Input attributes for creating an OrderModel.\r\n * Extends CartAttributes but requires/adds order-specific fields.\r\n */\r\nexport type OrderAttributes = Omit<BaseShoppingContainerAttributes, 'anonymousId'> & {\r\n customerId: string;\r\n customerEmail: string;\r\n shippingAddress: AddressData;\r\n billingAddress: AddressData;\r\n anonymousId?: string;\r\n total: Required<ShoppingContainerTotal>;\r\n orderNumber: string;\r\n cartId: string;\r\n paymentStatus: PaymentStatus;\r\n holdReason?: string;\r\n state: OrderState;\r\n lineItemStateMap?: OrderLineItemStateMap;\r\n};\r\n\r\n/**\r\n * Output data structure for an OrderModel.\r\n */\r\nexport type OrderData = BaseShoppingContainerData & OrderAttributes & {\r\n holdReason: string;\r\n lineItemStateMap: OrderLineItemStateMap;\r\n};\r\n\r\n\r\nexport default class OrderModel extends BaseShoppingContainerModel {\r\n protected orderNumber: string;\r\n protected cartId: string;\r\n protected paymentStatus: PaymentStatus;\r\n protected holdReason: string;\r\n protected state: OrderState;\r\n protected lineItemStateMap: OrderLineItemStateMap;\r\n\r\n /**\r\n * Creates an instance of OrderModel.\r\n * @param data - The initial order attributes, including cart data.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n * @param config - Optional cart configuration (might be less relevant for orders).\r\n */\r\n constructor(data: OrderAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.orderNumber = data.orderNumber;\r\n this.cartId = data.cartId;\r\n this.paymentStatus = data.paymentStatus;\r\n this.holdReason = data.holdReason || '';\r\n this.state = data.state;\r\n \r\n const newLineItemStateMap: OrderLineItemStateMap = {};\r\n data.lineItems.forEach(item => {\r\n const currentStateMap = data.lineItemStateMap?.[item.id];;\r\n \r\n newLineItemStateMap[item.id] = {\r\n state: currentStateMap?.state || OrderLineItemState.INITIAL,\r\n reason: currentStateMap?.reason || '',\r\n transitionAt: currentStateMap?.transitionAt || this.createdAt,\r\n };\r\n });\r\n this.lineItemStateMap = newLineItemStateMap;\r\n }\r\n\r\n /**\r\n * Recalculates the subtotal and mrpTotal based on the current line items.\r\n * Uses PriceModel for rounding based on the country.\r\n */\r\n protected recalculateOrderBaseTotals(filterRefunded: boolean = false): void {\r\n const filteredLineItems = this.lineItems.filter(item =>\r\n !(this.lineItemStateMap[item.getId()]?.state === OrderLineItemState.CANCELLED \r\n ||\r\n filterRefunded && [OrderLineItemState.RETURN_REQUESTED, OrderLineItemState.RETURNED, OrderLineItemState.REFUND_INITIATED, OrderLineItemState.REFUNDED].includes(this.lineItemStateMap[item.getId()]?.state))\r\n );\r\n this.total.subtotal = PriceModel.getRoundedPrice(filteredLineItems\r\n .reduce((sum, item) => sum + item.getPriceTotals().subtotal, 0), this.country);\r\n\r\n this.total.mrpTotal = PriceModel.getRoundedPrice(filteredLineItems.reduce((sum, item) => sum + item.getPriceTotals().mrpTotal, 0), this.country);\r\n }\r\n\r\n public updateOrderTotals(): void {\r\n // 1. Calculate filtered line item totals (subtotal, mrpTotal)\r\n this.recalculateOrderBaseTotals(true);\r\n\r\n // 2. Calculate total coupon discount and update the per-coupon discount map\r\n this.recalculateCouponTotals(false);\r\n\r\n // 3. Calculate line item totals (subtotal, mrpTotal)\r\n this.recalculateOrderBaseTotals();\r\n\r\n // 4. Calculate effective shipping cost after applying shipping-specific coupons\r\n const shippingCouponDiscount = this.coupons\r\n .filter(c => c.getCategory() === CouponCategory.SHIPPING)\r\n .reduce((sum, c) => sum + (this.total.couponTotal[c.getCode()] ?? 0), 0);\r\n this.total.effectiveShipping = PriceModel.getRoundedPrice(Math.max(0, this.total.shipping - shippingCouponDiscount), this.country);\r\n\r\n // 5. Calculate total discount from non-shipping coupons\r\n const nonShippingCouponDiscount = this.coupons\r\n .filter(c => c.getCategory() !== CouponCategory.SHIPPING)\r\n .reduce((sum, c) => sum + (this.total.couponTotal[c.getCode()] ?? 0), 0);\r\n\r\n // 6. Calculate final grand total: (subtotal + effective shipping) - non-shipping discounts\r\n const grossTotal = this.total.subtotal + this.total.effectiveShipping;\r\n this.total.grandTotal = PriceModel.getRoundedPrice(Math.max(0, grossTotal - nonShippingCouponDiscount), this.country);\r\n }\r\n\r\n /**\r\n * Gets the customer ID associated with this order.\r\n * Overrides the base method to guarantee a non-undefined return type for orders.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string {\r\n return this.customerId as string;\r\n }\r\n\r\n /**\r\n * Gets the customer email associated with this order.\r\n * Overrides the base method to guarantee a non-undefined return type for orders.\r\n * @returns The customer email string.\r\n */\r\n public getCustomerEmail(): string {\r\n return this.customerEmail as string;\r\n }\r\n\r\n /**\r\n * Gets the shipping address associated with the order.\r\n * Overrides the base method to guarantee a non-null return type for orders.\r\n * @returns An AddressModel instance for the shipping address.\r\n */\r\n public getShippingAddress(): AddressModel {\r\n return this.shippingAddress as AddressModel;\r\n }\r\n\r\n /**\r\n * Gets the billing address associated with the order.\r\n * Overrides the base method to guarantee a non-null return type for orders.\r\n * @returns An AddressModel instance for the billing address.\r\n */\r\n public getBillingAddress(): AddressModel {\r\n return this.billingAddress as AddressModel;\r\n }\r\n\r\n\r\n /**\r\n * Gets the user-facing order number.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string {\r\n return this.orderNumber;\r\n }\r\n\r\n /**\r\n * Gets the ID of the cart from which this order was created.\r\n * @returns The cart ID string.\r\n */\r\n public getCartId(): string {\r\n return this.cartId;\r\n }\r\n\r\n /**\r\n * Gets the current payment status of the order.\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getPaymentStatus(): PaymentStatus {\r\n return this.paymentStatus;\r\n }\r\n\r\n /**\r\n * Gets the reason why the order might be on hold, if any.\r\n * @returns The hold reason string (empty if not on hold or no reason specified).\r\n */\r\n public getHoldReason(): string {\r\n return this.holdReason;\r\n }\r\n\r\n /**\r\n * Gets the current state of the order (e.g., PROCESSING, SHIPPED).\r\n * @returns The OrderState enum value.\r\n */\r\n public getState(): OrderState {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the map tracking the state of each line item in the order.\r\n * The keys are line item IDs, and the values contain the state, reason, and transition timestamp.\r\n * @returns The OrderLineItemStateMap.\r\n */\r\n public getLineItemsStateMap(): OrderLineItemStateMap {\r\n return { ...this.lineItemStateMap };\r\n }\r\n\r\n /**\r\n * Gets the current state of a specific line item within the order.\r\n * @param lineItemId - The ID of the line item whose state is requested.\r\n * @returns The OrderLineItemState enum value for the specified line item.\r\n * @throws {LineItemNotFoundError} If no line item with the given ID exists in the order's state map.\r\n */\r\n public getLineItemState(lineItemId: string): OrderLineItemState {\r\n if (!this.lineItemStateMap[lineItemId]){\r\n throw new LineItemNotFoundError(lineItemId)\r\n }\r\n return this.lineItemStateMap[lineItemId].state;\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the order's current state.\r\n * Includes all cart details plus order-specific information.\r\n * @returns OrderData object suitable for serialization or API responses.\r\n */\r\n getDetails(): OrderData {\r\n return {\r\n ...super.getDetails(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n customerEmail: this.getCustomerEmail(),\r\n shippingAddress: this.getShippingAddress().getDetails(),\r\n billingAddress: this.getBillingAddress().getDetails(),\r\n cartId: this.getCartId(),\r\n paymentStatus: this.getPaymentStatus(),\r\n holdReason: this.getHoldReason(),\r\n state: this.getState(),\r\n lineItemStateMap: this.getLineItemsStateMap()\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Order.ts"],"names":["OrderState","OrderModel","BaseShoppingContainerModel","data","date","lineItemId","lineItem","item","LineItemNotFoundError"],"mappings":"+XAaYA,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,EAAA,MAAS,CAAA,QAAA,CACTA,EAAA,eAAkB,CAAA,iBAAA,CAClBA,EAAA,UAAa,CAAA,YAAA,CACbA,EAAA,SAAY,CAAA,WAAA,CACZA,EAAA,SAAY,CAAA,WAAA,CALFA,OAAA,EAkCSC,CAAAA,CAAAA,CAAAA,CAArB,cAAwCC,CAA2B,CACvD,YACA,MACA,CAAA,aAAA,CACA,WACA,KAQV,CAAA,WAAA,CAAYC,EAAuBC,CAAa,CAAA,IAAI,KAAQ,CAC1D,KAAA,CAAMD,EAAMC,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,CAAY,KAAK,aAAc,EAAA,CAC/B,MAAO,IAAK,CAAA,QAAA,EACd,CACF,CACF","file":"Order.mjs","sourcesContent":["import AddressModel, { AddressData } from \"./Address\";\r\nimport { LineItemNotFoundError } from \"./Error\";\r\nimport { LineItemState } from \"./Enum\";\r\nimport { PaymentStatus } from \"./Payment\";\r\nimport BaseShoppingContainerModel, { BaseShoppingContainerAttributes, BaseShoppingContainerData, ShoppingContainerTotal } from \"./ShoppingContainer\";\r\n\r\n/**\r\n * PLACED: Order created, awaiting payment.\r\n * PENDING_PAYMENT: Waiting for payment confirmation.\r\n * PROCESSING: Payment received, order is being fulfilled. Stays here until all line items reach a final state.\r\n * CANCELLED: All line items are cancelled, or order is cancelled before fulfillment.\r\n * COMPLETED: All line items are delivered, returned, or refunded.\r\n */\r\nexport enum OrderState {\r\n PLACED = \"PLACED\",\r\n PENDING_PAYMENT = \"PENDING_PAYMENT\",\r\n PROCESSING = \"PROCESSING\",\r\n CANCELLED = \"CANCELLED\",\r\n COMPLETED = \"COMPLETED\"\r\n}\r\n\r\n/**\r\n * Input attributes for creating an OrderModel.\r\n * Extends CartAttributes but requires/adds order-specific fields.\r\n */\r\nexport type OrderAttributes = Omit<BaseShoppingContainerAttributes, 'anonymousId'> & {\r\n customerId: string;\r\n customerEmail: string;\r\n shippingAddress: AddressData;\r\n billingAddress: AddressData;\r\n anonymousId?: string;\r\n total: Required<ShoppingContainerTotal>;\r\n orderNumber: string;\r\n cartId: string;\r\n paymentStatus: PaymentStatus;\r\n holdReason?: string;\r\n state: OrderState;\r\n};\r\n\r\n/**\r\n * Output data structure for an OrderModel.\r\n */\r\nexport type OrderData = BaseShoppingContainerData & OrderAttributes & {\r\n holdReason: string;\r\n};\r\n\r\n\r\nexport default class OrderModel extends BaseShoppingContainerModel {\r\n protected orderNumber: string;\r\n protected cartId: string;\r\n protected paymentStatus: PaymentStatus;\r\n protected holdReason: string;\r\n protected state: OrderState;\r\n\r\n /**\r\n * Creates an instance of OrderModel.\r\n * @param data - The initial order attributes, including cart data.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n * @param config - Optional cart configuration (might be less relevant for orders).\r\n */\r\n constructor(data: OrderAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.orderNumber = data.orderNumber;\r\n this.cartId = data.cartId;\r\n this.paymentStatus = data.paymentStatus;\r\n this.holdReason = data.holdReason || '';\r\n this.state = data.state;\r\n }\r\n\r\n /**\r\n * Gets the customer ID associated with this order.\r\n * Overrides the base method to guarantee a non-undefined return type for orders.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string {\r\n return this.customerId as string;\r\n }\r\n\r\n /**\r\n * Gets the customer email associated with this order.\r\n * Overrides the base method to guarantee a non-undefined return type for orders.\r\n * @returns The customer email string.\r\n */\r\n public getCustomerEmail(): string {\r\n return this.customerEmail as string;\r\n }\r\n\r\n /**\r\n * Gets the shipping address associated with the order.\r\n * Overrides the base method to guarantee a non-null return type for orders.\r\n * @returns An AddressModel instance for the shipping address.\r\n */\r\n public getShippingAddress(): AddressModel {\r\n return this.shippingAddress as AddressModel;\r\n }\r\n\r\n /**\r\n * Gets the billing address associated with the order.\r\n * Overrides the base method to guarantee a non-null return type for orders.\r\n * @returns An AddressModel instance for the billing address.\r\n */\r\n public getBillingAddress(): AddressModel {\r\n return this.billingAddress as AddressModel;\r\n }\r\n\r\n\r\n /**\r\n * Gets the user-facing order number.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string {\r\n return this.orderNumber;\r\n }\r\n\r\n /**\r\n * Gets the ID of the cart from which this order was created.\r\n * @returns The cart ID string.\r\n */\r\n public getCartId(): string {\r\n return this.cartId;\r\n }\r\n\r\n /**\r\n * Gets the current payment status of the order.\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getPaymentStatus(): PaymentStatus {\r\n return this.paymentStatus;\r\n }\r\n\r\n /**\r\n * Gets the reason why the order might be on hold, if any.\r\n * @returns The hold reason string (empty if not on hold or no reason specified).\r\n */\r\n public getHoldReason(): string {\r\n return this.holdReason;\r\n }\r\n\r\n /**\r\n * Gets the current state of the order (e.g., PROCESSING, SHIPPED).\r\n * @returns The OrderState enum value.\r\n */\r\n public getState(): OrderState {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the current state of a specific line item within the order.\r\n * @param lineItemId - The ID of the line item whose state is requested.\r\n * @returns The OrderLineItemState enum value for the specified line item.\r\n * @throws {LineItemNotFoundError} If no line item with the given ID exists in the order's state map.\r\n */\r\n public getLineItemState(lineItemId: string): LineItemState {\r\n const lineItem = this.getLineItems().find(item => item.getId() === lineItemId);\r\n if (!lineItem){\r\n throw new LineItemNotFoundError(lineItemId)\r\n }\r\n return lineItem.getState();\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the order's current state.\r\n * Includes all cart details plus order-specific information.\r\n * @returns OrderData object suitable for serialization or API responses.\r\n */\r\n getDetails(): OrderData {\r\n return {\r\n ...super.getDetails(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n customerEmail: this.getCustomerEmail(),\r\n shippingAddress: this.getShippingAddress().getDetails(),\r\n billingAddress: this.getBillingAddress().getDetails(),\r\n cartId: this.getCartId(),\r\n paymentStatus: this.getPaymentStatus(),\r\n holdReason: this.getHoldReason(),\r\n state: this.getState()\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseModel, { BaseAttributes, BaseData } from './Base.mjs';
|
|
2
|
-
import { CurrencyCode,
|
|
2
|
+
import { a as CurrencyCode, I as ISODateTimeUTC } from '../Common-FbQ5-3QN.mjs';
|
|
3
3
|
import '../Auth/index.mjs';
|
|
4
4
|
import './Enum.mjs';
|
|
5
5
|
|
|
@@ -39,7 +39,7 @@ type PaymentAttributes = BaseAttributes & {
|
|
|
39
39
|
amountRefunded?: number;
|
|
40
40
|
cardLast4?: string;
|
|
41
41
|
cardBrand?: string;
|
|
42
|
-
transactionAt:
|
|
42
|
+
transactionAt: ISODateTimeUTC;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Output data structure for a PaymentModel.
|
|
@@ -65,7 +65,7 @@ declare class PaymentModel extends BaseModel {
|
|
|
65
65
|
protected amountRefunded: number;
|
|
66
66
|
protected cardLast4?: string;
|
|
67
67
|
protected cardBrand?: string;
|
|
68
|
-
protected transactionAt:
|
|
68
|
+
protected transactionAt: ISODateTimeUTC;
|
|
69
69
|
/**
|
|
70
70
|
* Creates an instance of PaymentModel.
|
|
71
71
|
* @param data - The initial payment attributes.
|
|
@@ -151,7 +151,7 @@ declare class PaymentModel extends BaseModel {
|
|
|
151
151
|
* Gets the timestamp when the transaction occurred or was recorded.
|
|
152
152
|
* @returns The transaction timestamp as an ISO 8601 string.
|
|
153
153
|
*/
|
|
154
|
-
getTransactionAt():
|
|
154
|
+
getTransactionAt(): ISODateTimeUTC;
|
|
155
155
|
/**
|
|
156
156
|
* Gets a plain data object representing the payment's current state.
|
|
157
157
|
* @returns PaymentData object suitable for serialization or API responses.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseModel, { BaseAttributes, BaseData } from './Base.js';
|
|
2
|
-
import { CurrencyCode,
|
|
2
|
+
import { a as CurrencyCode, I as ISODateTimeUTC } from '../Common-D-UoxwM0.js';
|
|
3
3
|
import '../Auth/index.js';
|
|
4
4
|
import './Enum.js';
|
|
5
5
|
|
|
@@ -39,7 +39,7 @@ type PaymentAttributes = BaseAttributes & {
|
|
|
39
39
|
amountRefunded?: number;
|
|
40
40
|
cardLast4?: string;
|
|
41
41
|
cardBrand?: string;
|
|
42
|
-
transactionAt:
|
|
42
|
+
transactionAt: ISODateTimeUTC;
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Output data structure for a PaymentModel.
|
|
@@ -65,7 +65,7 @@ declare class PaymentModel extends BaseModel {
|
|
|
65
65
|
protected amountRefunded: number;
|
|
66
66
|
protected cardLast4?: string;
|
|
67
67
|
protected cardBrand?: string;
|
|
68
|
-
protected transactionAt:
|
|
68
|
+
protected transactionAt: ISODateTimeUTC;
|
|
69
69
|
/**
|
|
70
70
|
* Creates an instance of PaymentModel.
|
|
71
71
|
* @param data - The initial payment attributes.
|
|
@@ -151,7 +151,7 @@ declare class PaymentModel extends BaseModel {
|
|
|
151
151
|
* Gets the timestamp when the transaction occurred or was recorded.
|
|
152
152
|
* @returns The transaction timestamp as an ISO 8601 string.
|
|
153
153
|
*/
|
|
154
|
-
getTransactionAt():
|
|
154
|
+
getTransactionAt(): ISODateTimeUTC;
|
|
155
155
|
/**
|
|
156
156
|
* Gets a plain data object representing the payment's current state.
|
|
157
157
|
* @returns PaymentData object suitable for serialization or API responses.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Payment.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","PaymentStatus","PaymentMode","PaymentModel"],"mappings":"sEA4BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YACA,CAAA,OAAA,CACA,SACA,CAAA,UAAA,CACA,UAQV,CAAA,WAAA,CAAYC,CAAsBC,CAAAA,CAAAA,CAAa,IAAI,IAAA,CAAQ,CACzD,IAAA,CAAK,YAAe,CAAA,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAAA,CAC3C,IAAK,CAAA,OAAA,CAAUA,CAAK,CAAA,OAAA,EAAW,CAC/B,CAAA,IAAA,CAAK,SAAYA,CAAAA,CAAAA,CAAK,SAAa,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,KAAMA,CAAAA,CAAAA,CAAK,SAAS,CAAC,CAElE,CAAA,IAAI,IAAKA,CAAAA,CAAAA,CAAK,SAAS,CAAA,CAAE,WAAY,EAAA,CAErCC,CAAK,CAAA,WAAA,EACP,CAAA,IAAA,CAAK,UAAaD,CAAAA,CAAAA,CAAK,UAAc,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,KAAMA,CAAAA,CAAAA,CAAK,UAAU,C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,OAAO,IAAK,CAAA,gBAAkB,CAM1E,sBAAA,EAA6C,CAAE,OAAO,IAAK,CAAA,mBAAqB,CAMhF,iBAAA,EAA4B,CAAE,OAAO,IAAK,CAAA,cAAgB,CAM1D,YAAA,EAAmC,CAAE,OAAO,IAAK,CAAA,SAAW,CAM5D,YAAA,EAAmC,CAAE,OAAO,IAAK,CAAA,SAAW,CAM5D,gBAAA,EAAgC,CAAE,OAAO,IAAK,CAAA,aAAe,CAOpE,UAAA,EAA0B,CAExB,OAAO,CACL,GAFkB,KAAM,CAAA,UAAA,EAGxB,CAAA,KAAA,CAAO,IAAK,CAAA,QAAA,EACZ,CAAA,UAAA,CAAY,IAAK,CAAA,aAAA,EACjB,CAAA,WAAA,CAAa,IAAK,CAAA,cAAA,EAClB,CAAA,UAAA,CAAY,IAAK,CAAA,aAAA,EACjB,CAAA,MAAA,CAAQ,IAAK,CAAA,SAAA,EACb,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,MAAA,CAAQ,IAAK,CAAA,SAAA,EACb,CAAA,QAAA,CAAU,IAAK,CAAA,WAAA,EACf,CAAA,WAAA,CAAa,IAAK,CAAA,cAAA,EAClB,CAAA,gBAAA,CAAkB,IAAK,CAAA,mBAAA,EACvB,CAAA,cAAA,CAAgB,IAAK,CAAA,iBAAA,EACrB,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,aAAA,CAAe,IAAK,CAAA,gBAAA,EACtB,CACF,CACF","file":"Payment.js","sourcesContent":["import { AuthType } from \"../Auth\";\r\nimport { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type ModifiedBy = {\r\n id?: string;\r\n authType?: string;\r\n requestId?: string;\r\n lambdaName?: string;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: ModifiedBy;\r\n};\r\n\r\nexport type BaseData = Required<BaseAttributes>;\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: ModifiedBy;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = { ...data.modifiedBy };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns\r\n */\r\n getModifiedBy(): ModifiedBy {\r\n return { ...this.modifiedBy };\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(id?: string, authType?: AuthType, requestId?: string, lambdaName?: string): void {\r\n this.modifiedBy = {\r\n id,\r\n authType,\r\n requestId,\r\n lambdaName,\r\n };\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport { CurrencyCode, ISODateTime } from \"./Common\";\r\n\r\nexport enum PaymentStatus {\r\n PENDING = \"PENDING\",\r\n AUTHORIZED = \"AUTHORIZED\",\r\n CAPTURED = \"CAPTURED\",\r\n FAILED = \"FAILED\",\r\n REFUNDED = \"REFUNDED\",\r\n PARTIALLY_REFUNDED = \"PARTIALLY_REFUNDED\",\r\n}\r\n\r\nexport enum PaymentMode {\r\n PAY_LATER = \"PAY_LATER\",\r\n CARD = \"CARD\",\r\n CASH = \"CASH\",\r\n NET_BANKING = \"NET_BANKING\",\r\n WALLET = \"WALLET\",\r\n COD = \"COD\",\r\n UNKNOWN = \"UNKNOWN\",\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a PaymentModel.\r\n */\r\nexport type PaymentAttributes = BaseAttributes & {\r\n txnId: string;\r\n externalId?: string;\r\n orderNumber: string;\r\n customerId: string;\r\n status: PaymentStatus;\r\n subStatus?: string;\r\n amount: number;\r\n currency: CurrencyCode;\r\n paymentMode: PaymentMode;\r\n gatewayResponse?: string;\r\n gatewayErrorCode?: string;\r\n gatewayErrorMessage?: string;\r\n amountRefunded?: number;\r\n cardLast4?: string;\r\n cardBrand?: string;\r\n transactionAt: ISODateTime;\r\n};\r\n\r\n/**\r\n * Output data structure for a PaymentModel.\r\n * Excludes potentially large or sensitive fields by default.\r\n */\r\nexport type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData\r\n\r\n/**\r\n * Represents a payment transaction, attempt, or record associated with an order.\r\n */\r\nexport default class PaymentModel extends BaseModel {\r\n protected txnId: string;\r\n protected externalId?: string;\r\n protected orderNumber: string;\r\n protected customerId: string;\r\n protected status: PaymentStatus;\r\n protected subStatus?: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n protected paymentMode: PaymentMode;\r\n protected gatewayResponse?: string;\r\n protected gatewayErrorCode?: string;\r\n protected gatewayErrorMessage?: string;\r\n protected amountRefunded: number;\r\n protected cardLast4?: string;\r\n protected cardBrand?: string;\r\n protected transactionAt: ISODateTime;\r\n\r\n /**\r\n * Creates an instance of PaymentModel.\r\n * @param data - The initial payment attributes.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: PaymentAttributes, date: Date = new Date()) {\r\n super(data, date); // Pass BaseAttributes to parent\r\n\r\n // Assign properties\r\n this.txnId = data.txnId;\r\n this.externalId = data.externalId;\r\n this.orderNumber = data.orderNumber;\r\n this.customerId = data.customerId;\r\n this.status = data.status;\r\n this.subStatus = data.subStatus;\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n this.paymentMode = data.paymentMode;\r\n this.gatewayResponse = data.gatewayResponse;\r\n this.gatewayErrorCode = data.gatewayErrorCode;\r\n this.gatewayErrorMessage = data.gatewayErrorMessage;\r\n this.amountRefunded = data.amountRefunded || 0; // Default to 0 if undefined\r\n this.cardLast4 = data.cardLast4;\r\n this.cardBrand = data.cardBrand;\r\n this.transactionAt = data.transactionAt;\r\n }\r\n\r\n /**\r\n * Gets the primary transaction identifier.\r\n * @returns The transaction ID string.\r\n */\r\n public getTxnId(): string { return this.txnId; }\r\n\r\n /**\r\n * Gets the external identifier, often from a payment gateway.\r\n * @returns The external ID string, or undefined if not set.\r\n */\r\n public getExternalId(): string | undefined { return this.externalId; }\r\n\r\n /**\r\n * Gets the order number associated with this payment.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string { return this.orderNumber; }\r\n\r\n /**\r\n * Gets the customer ID associated with this payment.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string { return this.customerId; }\r\n\r\n /**\r\n * Gets the current status of the payment (e.g., PENDING, CAPTURED).\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getStatus(): PaymentStatus { return this.status; }\r\n\r\n /**\r\n * Gets the detailed sub-status, often provided by the payment gateway.\r\n * @returns The sub-status string, or undefined if not set.\r\n */\r\n public getSubStatus(): string | undefined { return this.subStatus; }\r\n\r\n /**\r\n * Gets the amount of the payment transaction.\r\n * @returns The payment amount number.\r\n */\r\n public getAmount(): number { return this.amount; }\r\n\r\n /**\r\n * Gets the currency code for the payment amount.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode { return this.currency; }\r\n\r\n /**\r\n * Gets the mode or method used for the payment (e.g., CARD, COD).\r\n * @returns The PaymentMode enum value.\r\n */\r\n public getPaymentMode(): PaymentMode { return this.paymentMode; }\r\n\r\n /**\r\n * Gets the raw response data from the payment gateway (potentially large).\r\n * @returns The gateway response string, or undefined if not set.\r\n */\r\n public getGatewayResponse(): string | undefined { return this.gatewayResponse; }\r\n\r\n /**\r\n * Gets the error code returned by the payment gateway, if any.\r\n * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorCode(): string | undefined { return this.gatewayErrorCode; }\r\n\r\n /**\r\n * Gets the error message returned by the payment gateway, if any.\r\n * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorMessage(): string | undefined { return this.gatewayErrorMessage; }\r\n\r\n /**\r\n * Gets the total amount that has been refunded for this transaction.\r\n * @returns The refunded amount number (defaults to 0).\r\n */\r\n public getAmountRefunded(): number { return this.amountRefunded; }\r\n\r\n /**\r\n * Gets the last 4 digits of the card used, if applicable.\r\n * @returns The card's last 4 digits string, or undefined.\r\n */\r\n public getCardLast4(): string | undefined { return this.cardLast4; }\r\n\r\n /**\r\n * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.\r\n * @returns The card brand string, or undefined.\r\n */\r\n public getCardBrand(): string | undefined { return this.cardBrand; }\r\n\r\n /**\r\n * Gets the timestamp when the transaction occurred or was recorded.\r\n * @returns The transaction timestamp as an ISO 8601 string.\r\n */\r\n public getTransactionAt(): ISODateTime { return this.transactionAt; }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the payment's current state.\r\n * @returns PaymentData object suitable for serialization or API responses.\r\n */\r\n getDetails(): PaymentData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n ...baseDetails,\r\n txnId: this.getTxnId(),\r\n externalId: this.getExternalId(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n status: this.getStatus(),\r\n subStatus: this.getSubStatus(),\r\n amount: this.getAmount(),\r\n currency: this.getCurrency(),\r\n paymentMode: this.getPaymentMode(),\r\n gatewayErrorCode: this.getGatewayErrorCode(),\r\n amountRefunded: this.getAmountRefunded(),\r\n cardLast4: this.getCardLast4(),\r\n cardBrand: this.getCardBrand(),\r\n transactionAt: this.getTransactionAt(),\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Payment.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","PaymentStatus","PaymentMode","PaymentModel"],"mappings":"sEA4BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YACA,CAAA,OAAA,CACA,SACA,CAAA,UAAA,CACA,UAQV,CAAA,WAAA,CAAYC,CAAsBC,CAAAA,CAAAA,CAAa,IAAI,IAAA,CAAQ,CACzD,IAAA,CAAK,YAAe,CAAA,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAAA,CAC3C,IAAK,CAAA,OAAA,CAAUA,CAAK,CAAA,OAAA,EAAW,CAC/B,CAAA,IAAA,CAAK,SAAYA,CAAAA,CAAAA,CAAK,SAAa,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,KAAMA,CAAAA,CAAAA,CAAK,SAAS,CAAC,CAElE,CAAA,IAAI,IAAKA,CAAAA,CAAAA,CAAK,SAAS,CAAA,CAAE,WAAY,EAAA,CAErCC,CAAK,CAAA,WAAA,EACP,CAAA,IAAA,CAAK,UAAaD,CAAAA,CAAAA,CAAK,UAAc,EAAA,CAAC,KAAM,CAAA,IAAA,CAAK,KAAMA,CAAAA,CAAAA,CAAK,UAAU,CAAC,CACnE,CAAA,IAAI,IAAKA,CAAAA,CAAAA,CAAK,UAAU,CAAA,CAAE,WAAY,EAAA,CACtCC,CAAK,CAAA,WAAA,EAET,CAAA,IAAA,CAAK,UAAa,CAAA,CAAE,GAAGD,CAAAA,CAAK,UAAW,EACzC,CAMA,U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AM5D,YAAA,EAAmC,CAAE,OAAO,IAAK,CAAA,SAAW,CAM5D,gBAAA,EAAmC,CAAE,OAAO,IAAK,CAAA,aAAe,CAOvE,UAAA,EAA0B,CAExB,OAAO,CACL,GAFkB,KAAM,CAAA,UAAA,EAGxB,CAAA,KAAA,CAAO,IAAK,CAAA,QAAA,EACZ,CAAA,UAAA,CAAY,IAAK,CAAA,aAAA,EACjB,CAAA,WAAA,CAAa,IAAK,CAAA,cAAA,EAClB,CAAA,UAAA,CAAY,IAAK,CAAA,aAAA,EACjB,CAAA,MAAA,CAAQ,IAAK,CAAA,SAAA,EACb,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,MAAA,CAAQ,IAAK,CAAA,SAAA,EACb,CAAA,QAAA,CAAU,IAAK,CAAA,WAAA,EACf,CAAA,WAAA,CAAa,IAAK,CAAA,cAAA,EAClB,CAAA,gBAAA,CAAkB,IAAK,CAAA,mBAAA,EACvB,CAAA,cAAA,CAAgB,IAAK,CAAA,iBAAA,EACrB,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,SAAA,CAAW,IAAK,CAAA,YAAA,EAChB,CAAA,aAAA,CAAe,IAAK,CAAA,gBAAA,EACtB,CACF,CACF","file":"Payment.js","sourcesContent":["import { AuthType } from \"../Auth\";\r\nimport { ISODateTimeUTC } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type ModifiedBy = {\r\n id?: string;\r\n authType?: string;\r\n requestId?: string;\r\n lambdaName?: string;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTimeUTC;\r\n modifiedAt?: ISODateTimeUTC;\r\n modifiedBy?: ModifiedBy;\r\n};\r\n\r\nexport type BaseData = Required<BaseAttributes>;\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTimeUTC;\r\n protected modifiedAt: ISODateTimeUTC;\r\n protected modifiedBy: ModifiedBy;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = { ...data.modifiedBy };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns\r\n */\r\n getModifiedBy(): ModifiedBy {\r\n return { ...this.modifiedBy };\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(id?: string, authType?: AuthType, requestId?: string, lambdaName?: string): void {\r\n this.modifiedBy = {\r\n id,\r\n authType,\r\n requestId,\r\n lambdaName,\r\n };\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport { CurrencyCode, ISODateTimeUTC } from \"./Common\";\r\n\r\nexport enum PaymentStatus {\r\n PENDING = \"PENDING\",\r\n AUTHORIZED = \"AUTHORIZED\",\r\n CAPTURED = \"CAPTURED\",\r\n FAILED = \"FAILED\",\r\n REFUNDED = \"REFUNDED\",\r\n PARTIALLY_REFUNDED = \"PARTIALLY_REFUNDED\",\r\n}\r\n\r\nexport enum PaymentMode {\r\n PAY_LATER = \"PAY_LATER\",\r\n CARD = \"CARD\",\r\n CASH = \"CASH\",\r\n NET_BANKING = \"NET_BANKING\",\r\n WALLET = \"WALLET\",\r\n COD = \"COD\",\r\n UNKNOWN = \"UNKNOWN\",\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a PaymentModel.\r\n */\r\nexport type PaymentAttributes = BaseAttributes & {\r\n txnId: string;\r\n externalId?: string;\r\n orderNumber: string;\r\n customerId: string;\r\n status: PaymentStatus;\r\n subStatus?: string;\r\n amount: number;\r\n currency: CurrencyCode;\r\n paymentMode: PaymentMode;\r\n gatewayResponse?: string;\r\n gatewayErrorCode?: string;\r\n gatewayErrorMessage?: string;\r\n amountRefunded?: number;\r\n cardLast4?: string;\r\n cardBrand?: string;\r\n transactionAt: ISODateTimeUTC;\r\n};\r\n\r\n/**\r\n * Output data structure for a PaymentModel.\r\n * Excludes potentially large or sensitive fields by default.\r\n */\r\nexport type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData\r\n\r\n/**\r\n * Represents a payment transaction, attempt, or record associated with an order.\r\n */\r\nexport default class PaymentModel extends BaseModel {\r\n protected txnId: string;\r\n protected externalId?: string;\r\n protected orderNumber: string;\r\n protected customerId: string;\r\n protected status: PaymentStatus;\r\n protected subStatus?: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n protected paymentMode: PaymentMode;\r\n protected gatewayResponse?: string;\r\n protected gatewayErrorCode?: string;\r\n protected gatewayErrorMessage?: string;\r\n protected amountRefunded: number;\r\n protected cardLast4?: string;\r\n protected cardBrand?: string;\r\n protected transactionAt: ISODateTimeUTC;\r\n\r\n /**\r\n * Creates an instance of PaymentModel.\r\n * @param data - The initial payment attributes.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: PaymentAttributes, date: Date = new Date()) {\r\n super(data, date); // Pass BaseAttributes to parent\r\n\r\n // Assign properties\r\n this.txnId = data.txnId;\r\n this.externalId = data.externalId;\r\n this.orderNumber = data.orderNumber;\r\n this.customerId = data.customerId;\r\n this.status = data.status;\r\n this.subStatus = data.subStatus;\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n this.paymentMode = data.paymentMode;\r\n this.gatewayResponse = data.gatewayResponse;\r\n this.gatewayErrorCode = data.gatewayErrorCode;\r\n this.gatewayErrorMessage = data.gatewayErrorMessage;\r\n this.amountRefunded = data.amountRefunded || 0; // Default to 0 if undefined\r\n this.cardLast4 = data.cardLast4;\r\n this.cardBrand = data.cardBrand;\r\n this.transactionAt = data.transactionAt;\r\n }\r\n\r\n /**\r\n * Gets the primary transaction identifier.\r\n * @returns The transaction ID string.\r\n */\r\n public getTxnId(): string { return this.txnId; }\r\n\r\n /**\r\n * Gets the external identifier, often from a payment gateway.\r\n * @returns The external ID string, or undefined if not set.\r\n */\r\n public getExternalId(): string | undefined { return this.externalId; }\r\n\r\n /**\r\n * Gets the order number associated with this payment.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string { return this.orderNumber; }\r\n\r\n /**\r\n * Gets the customer ID associated with this payment.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string { return this.customerId; }\r\n\r\n /**\r\n * Gets the current status of the payment (e.g., PENDING, CAPTURED).\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getStatus(): PaymentStatus { return this.status; }\r\n\r\n /**\r\n * Gets the detailed sub-status, often provided by the payment gateway.\r\n * @returns The sub-status string, or undefined if not set.\r\n */\r\n public getSubStatus(): string | undefined { return this.subStatus; }\r\n\r\n /**\r\n * Gets the amount of the payment transaction.\r\n * @returns The payment amount number.\r\n */\r\n public getAmount(): number { return this.amount; }\r\n\r\n /**\r\n * Gets the currency code for the payment amount.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode { return this.currency; }\r\n\r\n /**\r\n * Gets the mode or method used for the payment (e.g., CARD, COD).\r\n * @returns The PaymentMode enum value.\r\n */\r\n public getPaymentMode(): PaymentMode { return this.paymentMode; }\r\n\r\n /**\r\n * Gets the raw response data from the payment gateway (potentially large).\r\n * @returns The gateway response string, or undefined if not set.\r\n */\r\n public getGatewayResponse(): string | undefined { return this.gatewayResponse; }\r\n\r\n /**\r\n * Gets the error code returned by the payment gateway, if any.\r\n * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorCode(): string | undefined { return this.gatewayErrorCode; }\r\n\r\n /**\r\n * Gets the error message returned by the payment gateway, if any.\r\n * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorMessage(): string | undefined { return this.gatewayErrorMessage; }\r\n\r\n /**\r\n * Gets the total amount that has been refunded for this transaction.\r\n * @returns The refunded amount number (defaults to 0).\r\n */\r\n public getAmountRefunded(): number { return this.amountRefunded; }\r\n\r\n /**\r\n * Gets the last 4 digits of the card used, if applicable.\r\n * @returns The card's last 4 digits string, or undefined.\r\n */\r\n public getCardLast4(): string | undefined { return this.cardLast4; }\r\n\r\n /**\r\n * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.\r\n * @returns The card brand string, or undefined.\r\n */\r\n public getCardBrand(): string | undefined { return this.cardBrand; }\r\n\r\n /**\r\n * Gets the timestamp when the transaction occurred or was recorded.\r\n * @returns The transaction timestamp as an ISO 8601 string.\r\n */\r\n public getTransactionAt(): ISODateTimeUTC { return this.transactionAt; }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the payment's current state.\r\n * @returns PaymentData object suitable for serialization or API responses.\r\n */\r\n getDetails(): PaymentData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n ...baseDetails,\r\n txnId: this.getTxnId(),\r\n externalId: this.getExternalId(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n status: this.getStatus(),\r\n subStatus: this.getSubStatus(),\r\n amount: this.getAmount(),\r\n currency: this.getCurrency(),\r\n paymentMode: this.getPaymentMode(),\r\n gatewayErrorCode: this.getGatewayErrorCode(),\r\n amountRefunded: this.getAmountRefunded(),\r\n cardLast4: this.getCardLast4(),\r\n cardBrand: this.getCardBrand(),\r\n transactionAt: this.getTransactionAt(),\r\n };\r\n }\r\n}\r\n"]}
|
package/dist/Classes/Payment.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'../chunk-
|
|
1
|
+
import {a}from'../chunk-55SOBG62.mjs';var u=(r=>(r.PENDING="PENDING",r.AUTHORIZED="AUTHORIZED",r.CAPTURED="CAPTURED",r.FAILED="FAILED",r.REFUNDED="REFUNDED",r.PARTIALLY_REFUNDED="PARTIALLY_REFUNDED",r))(u||{}),i=(e=>(e.PAY_LATER="PAY_LATER",e.CARD="CARD",e.CASH="CASH",e.NET_BANKING="NET_BANKING",e.WALLET="WALLET",e.COD="COD",e.UNKNOWN="UNKNOWN",e))(i||{}),s=class extends a{txnId;externalId;orderNumber;customerId;status;subStatus;amount;currency;paymentMode;gatewayResponse;gatewayErrorCode;gatewayErrorMessage;amountRefunded;cardLast4;cardBrand;transactionAt;constructor(t,a=new Date){super(t,a),this.txnId=t.txnId,this.externalId=t.externalId,this.orderNumber=t.orderNumber,this.customerId=t.customerId,this.status=t.status,this.subStatus=t.subStatus,this.amount=t.amount,this.currency=t.currency,this.paymentMode=t.paymentMode,this.gatewayResponse=t.gatewayResponse,this.gatewayErrorCode=t.gatewayErrorCode,this.gatewayErrorMessage=t.gatewayErrorMessage,this.amountRefunded=t.amountRefunded||0,this.cardLast4=t.cardLast4,this.cardBrand=t.cardBrand,this.transactionAt=t.transactionAt;}getTxnId(){return this.txnId}getExternalId(){return this.externalId}getOrderNumber(){return this.orderNumber}getCustomerId(){return this.customerId}getStatus(){return this.status}getSubStatus(){return this.subStatus}getAmount(){return this.amount}getCurrency(){return this.currency}getPaymentMode(){return this.paymentMode}getGatewayResponse(){return this.gatewayResponse}getGatewayErrorCode(){return this.gatewayErrorCode}getGatewayErrorMessage(){return this.gatewayErrorMessage}getAmountRefunded(){return this.amountRefunded}getCardLast4(){return this.cardLast4}getCardBrand(){return this.cardBrand}getTransactionAt(){return this.transactionAt}getDetails(){return {...super.getDetails(),txnId:this.getTxnId(),externalId:this.getExternalId(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),status:this.getStatus(),subStatus:this.getSubStatus(),amount:this.getAmount(),currency:this.getCurrency(),paymentMode:this.getPaymentMode(),gatewayErrorCode:this.getGatewayErrorCode(),amountRefunded:this.getAmountRefunded(),cardLast4:this.getCardLast4(),cardBrand:this.getCardBrand(),transactionAt:this.getTransactionAt()}}};export{i as PaymentMode,u as PaymentStatus,s as default};//# sourceMappingURL=Payment.mjs.map
|
|
2
2
|
//# sourceMappingURL=Payment.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Payment.ts"],"names":["PaymentStatus","PaymentMode","PaymentModel","BaseModel","data","date"],"mappings":"sCAGO,IAAKA,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,OAAU,CAAA,SAAA,CACVA,EAAA,UAAa,CAAA,YAAA,CACbA,CAAA,CAAA,QAAA,CAAW,WACXA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,SAAW,UACXA,CAAAA,CAAAA,CAAA,kBAAqB,CAAA,oBAAA,CANXA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CASAC,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,UAAY,WACZA,CAAAA,CAAAA,CAAA,IAAO,CAAA,MAAA,CACPA,EAAA,IAAO,CAAA,MAAA,CACPA,CAAA,CAAA,WAAA,CAAc,cACdA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,GAAM,CAAA,KAAA,CACNA,CAAA,CAAA,OAAA,CAAU,UAPAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAyCSC,CAArB,CAAA,cAA0CC,CAAU,CACxC,KAAA,CACA,UACA,CAAA,WAAA,C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from \"./Base\";\r\nimport { CurrencyCode, ISODateTime } from \"./Common\";\r\n\r\nexport enum PaymentStatus {\r\n PENDING = \"PENDING\",\r\n AUTHORIZED = \"AUTHORIZED\",\r\n CAPTURED = \"CAPTURED\",\r\n FAILED = \"FAILED\",\r\n REFUNDED = \"REFUNDED\",\r\n PARTIALLY_REFUNDED = \"PARTIALLY_REFUNDED\",\r\n}\r\n\r\nexport enum PaymentMode {\r\n PAY_LATER = \"PAY_LATER\",\r\n CARD = \"CARD\",\r\n CASH = \"CASH\",\r\n NET_BANKING = \"NET_BANKING\",\r\n WALLET = \"WALLET\",\r\n COD = \"COD\",\r\n UNKNOWN = \"UNKNOWN\",\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a PaymentModel.\r\n */\r\nexport type PaymentAttributes = BaseAttributes & {\r\n txnId: string;\r\n externalId?: string;\r\n orderNumber: string;\r\n customerId: string;\r\n status: PaymentStatus;\r\n subStatus?: string;\r\n amount: number;\r\n currency: CurrencyCode;\r\n paymentMode: PaymentMode;\r\n gatewayResponse?: string;\r\n gatewayErrorCode?: string;\r\n gatewayErrorMessage?: string;\r\n amountRefunded?: number;\r\n cardLast4?: string;\r\n cardBrand?: string;\r\n transactionAt: ISODateTime;\r\n};\r\n\r\n/**\r\n * Output data structure for a PaymentModel.\r\n * Excludes potentially large or sensitive fields by default.\r\n */\r\nexport type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData\r\n\r\n/**\r\n * Represents a payment transaction, attempt, or record associated with an order.\r\n */\r\nexport default class PaymentModel extends BaseModel {\r\n protected txnId: string;\r\n protected externalId?: string;\r\n protected orderNumber: string;\r\n protected customerId: string;\r\n protected status: PaymentStatus;\r\n protected subStatus?: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n protected paymentMode: PaymentMode;\r\n protected gatewayResponse?: string;\r\n protected gatewayErrorCode?: string;\r\n protected gatewayErrorMessage?: string;\r\n protected amountRefunded: number;\r\n protected cardLast4?: string;\r\n protected cardBrand?: string;\r\n protected transactionAt: ISODateTime;\r\n\r\n /**\r\n * Creates an instance of PaymentModel.\r\n * @param data - The initial payment attributes.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: PaymentAttributes, date: Date = new Date()) {\r\n super(data, date); // Pass BaseAttributes to parent\r\n\r\n // Assign properties\r\n this.txnId = data.txnId;\r\n this.externalId = data.externalId;\r\n this.orderNumber = data.orderNumber;\r\n this.customerId = data.customerId;\r\n this.status = data.status;\r\n this.subStatus = data.subStatus;\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n this.paymentMode = data.paymentMode;\r\n this.gatewayResponse = data.gatewayResponse;\r\n this.gatewayErrorCode = data.gatewayErrorCode;\r\n this.gatewayErrorMessage = data.gatewayErrorMessage;\r\n this.amountRefunded = data.amountRefunded || 0; // Default to 0 if undefined\r\n this.cardLast4 = data.cardLast4;\r\n this.cardBrand = data.cardBrand;\r\n this.transactionAt = data.transactionAt;\r\n }\r\n\r\n /**\r\n * Gets the primary transaction identifier.\r\n * @returns The transaction ID string.\r\n */\r\n public getTxnId(): string { return this.txnId; }\r\n\r\n /**\r\n * Gets the external identifier, often from a payment gateway.\r\n * @returns The external ID string, or undefined if not set.\r\n */\r\n public getExternalId(): string | undefined { return this.externalId; }\r\n\r\n /**\r\n * Gets the order number associated with this payment.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string { return this.orderNumber; }\r\n\r\n /**\r\n * Gets the customer ID associated with this payment.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string { return this.customerId; }\r\n\r\n /**\r\n * Gets the current status of the payment (e.g., PENDING, CAPTURED).\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getStatus(): PaymentStatus { return this.status; }\r\n\r\n /**\r\n * Gets the detailed sub-status, often provided by the payment gateway.\r\n * @returns The sub-status string, or undefined if not set.\r\n */\r\n public getSubStatus(): string | undefined { return this.subStatus; }\r\n\r\n /**\r\n * Gets the amount of the payment transaction.\r\n * @returns The payment amount number.\r\n */\r\n public getAmount(): number { return this.amount; }\r\n\r\n /**\r\n * Gets the currency code for the payment amount.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode { return this.currency; }\r\n\r\n /**\r\n * Gets the mode or method used for the payment (e.g., CARD, COD).\r\n * @returns The PaymentMode enum value.\r\n */\r\n public getPaymentMode(): PaymentMode { return this.paymentMode; }\r\n\r\n /**\r\n * Gets the raw response data from the payment gateway (potentially large).\r\n * @returns The gateway response string, or undefined if not set.\r\n */\r\n public getGatewayResponse(): string | undefined { return this.gatewayResponse; }\r\n\r\n /**\r\n * Gets the error code returned by the payment gateway, if any.\r\n * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorCode(): string | undefined { return this.gatewayErrorCode; }\r\n\r\n /**\r\n * Gets the error message returned by the payment gateway, if any.\r\n * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorMessage(): string | undefined { return this.gatewayErrorMessage; }\r\n\r\n /**\r\n * Gets the total amount that has been refunded for this transaction.\r\n * @returns The refunded amount number (defaults to 0).\r\n */\r\n public getAmountRefunded(): number { return this.amountRefunded; }\r\n\r\n /**\r\n * Gets the last 4 digits of the card used, if applicable.\r\n * @returns The card's last 4 digits string, or undefined.\r\n */\r\n public getCardLast4(): string | undefined { return this.cardLast4; }\r\n\r\n /**\r\n * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.\r\n * @returns The card brand string, or undefined.\r\n */\r\n public getCardBrand(): string | undefined { return this.cardBrand; }\r\n\r\n /**\r\n * Gets the timestamp when the transaction occurred or was recorded.\r\n * @returns The transaction timestamp as an ISO 8601 string.\r\n */\r\n public getTransactionAt(): ISODateTime { return this.transactionAt; }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the payment's current state.\r\n * @returns PaymentData object suitable for serialization or API responses.\r\n */\r\n getDetails(): PaymentData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n ...baseDetails,\r\n txnId: this.getTxnId(),\r\n externalId: this.getExternalId(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n status: this.getStatus(),\r\n subStatus: this.getSubStatus(),\r\n amount: this.getAmount(),\r\n currency: this.getCurrency(),\r\n paymentMode: this.getPaymentMode(),\r\n gatewayErrorCode: this.getGatewayErrorCode(),\r\n amountRefunded: this.getAmountRefunded(),\r\n cardLast4: this.getCardLast4(),\r\n cardBrand: this.getCardBrand(),\r\n transactionAt: this.getTransactionAt(),\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Payment.ts"],"names":["PaymentStatus","PaymentMode","PaymentModel","BaseModel","data","date"],"mappings":"sCAGO,IAAKA,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,OAAU,CAAA,SAAA,CACVA,EAAA,UAAa,CAAA,YAAA,CACbA,CAAA,CAAA,QAAA,CAAW,WACXA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,SAAW,UACXA,CAAAA,CAAAA,CAAA,kBAAqB,CAAA,oBAAA,CANXA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CASAC,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,UAAY,WACZA,CAAAA,CAAAA,CAAA,IAAO,CAAA,MAAA,CACPA,EAAA,IAAO,CAAA,MAAA,CACPA,CAAA,CAAA,WAAA,CAAc,cACdA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,GAAM,CAAA,KAAA,CACNA,CAAA,CAAA,OAAA,CAAU,UAPAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAyCSC,CAArB,CAAA,cAA0CC,CAAU,CACxC,KAAA,CACA,UACA,CAAA,WAAA,CACA,WACA,MACA,CAAA,SAAA,CACA,MACA,CAAA,QAAA,CACA,WACA,CAAA,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enum PaymentStatus {\r\n PENDING = \"PENDING\",\r\n AUTHORIZED = \"AUTHORIZED\",\r\n CAPTURED = \"CAPTURED\",\r\n FAILED = \"FAILED\",\r\n REFUNDED = \"REFUNDED\",\r\n PARTIALLY_REFUNDED = \"PARTIALLY_REFUNDED\",\r\n}\r\n\r\nexport enum PaymentMode {\r\n PAY_LATER = \"PAY_LATER\",\r\n CARD = \"CARD\",\r\n CASH = \"CASH\",\r\n NET_BANKING = \"NET_BANKING\",\r\n WALLET = \"WALLET\",\r\n COD = \"COD\",\r\n UNKNOWN = \"UNKNOWN\",\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a PaymentModel.\r\n */\r\nexport type PaymentAttributes = BaseAttributes & {\r\n txnId: string;\r\n externalId?: string;\r\n orderNumber: string;\r\n customerId: string;\r\n status: PaymentStatus;\r\n subStatus?: string;\r\n amount: number;\r\n currency: CurrencyCode;\r\n paymentMode: PaymentMode;\r\n gatewayResponse?: string;\r\n gatewayErrorCode?: string;\r\n gatewayErrorMessage?: string;\r\n amountRefunded?: number;\r\n cardLast4?: string;\r\n cardBrand?: string;\r\n transactionAt: ISODateTimeUTC;\r\n};\r\n\r\n/**\r\n * Output data structure for a PaymentModel.\r\n * Excludes potentially large or sensitive fields by default.\r\n */\r\nexport type PaymentData = Omit<PaymentAttributes, 'gatewayResponse' | 'gatewayErrorMessage'> & BaseData\r\n\r\n/**\r\n * Represents a payment transaction, attempt, or record associated with an order.\r\n */\r\nexport default class PaymentModel extends BaseModel {\r\n protected txnId: string;\r\n protected externalId?: string;\r\n protected orderNumber: string;\r\n protected customerId: string;\r\n protected status: PaymentStatus;\r\n protected subStatus?: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n protected paymentMode: PaymentMode;\r\n protected gatewayResponse?: string;\r\n protected gatewayErrorCode?: string;\r\n protected gatewayErrorMessage?: string;\r\n protected amountRefunded: number;\r\n protected cardLast4?: string;\r\n protected cardBrand?: string;\r\n protected transactionAt: ISODateTimeUTC;\r\n\r\n /**\r\n * Creates an instance of PaymentModel.\r\n * @param data - The initial payment attributes.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: PaymentAttributes, date: Date = new Date()) {\r\n super(data, date); // Pass BaseAttributes to parent\r\n\r\n // Assign properties\r\n this.txnId = data.txnId;\r\n this.externalId = data.externalId;\r\n this.orderNumber = data.orderNumber;\r\n this.customerId = data.customerId;\r\n this.status = data.status;\r\n this.subStatus = data.subStatus;\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n this.paymentMode = data.paymentMode;\r\n this.gatewayResponse = data.gatewayResponse;\r\n this.gatewayErrorCode = data.gatewayErrorCode;\r\n this.gatewayErrorMessage = data.gatewayErrorMessage;\r\n this.amountRefunded = data.amountRefunded || 0; // Default to 0 if undefined\r\n this.cardLast4 = data.cardLast4;\r\n this.cardBrand = data.cardBrand;\r\n this.transactionAt = data.transactionAt;\r\n }\r\n\r\n /**\r\n * Gets the primary transaction identifier.\r\n * @returns The transaction ID string.\r\n */\r\n public getTxnId(): string { return this.txnId; }\r\n\r\n /**\r\n * Gets the external identifier, often from a payment gateway.\r\n * @returns The external ID string, or undefined if not set.\r\n */\r\n public getExternalId(): string | undefined { return this.externalId; }\r\n\r\n /**\r\n * Gets the order number associated with this payment.\r\n * @returns The order number string.\r\n */\r\n public getOrderNumber(): string { return this.orderNumber; }\r\n\r\n /**\r\n * Gets the customer ID associated with this payment.\r\n * @returns The customer ID string.\r\n */\r\n public getCustomerId(): string { return this.customerId; }\r\n\r\n /**\r\n * Gets the current status of the payment (e.g., PENDING, CAPTURED).\r\n * @returns The PaymentStatus enum value.\r\n */\r\n public getStatus(): PaymentStatus { return this.status; }\r\n\r\n /**\r\n * Gets the detailed sub-status, often provided by the payment gateway.\r\n * @returns The sub-status string, or undefined if not set.\r\n */\r\n public getSubStatus(): string | undefined { return this.subStatus; }\r\n\r\n /**\r\n * Gets the amount of the payment transaction.\r\n * @returns The payment amount number.\r\n */\r\n public getAmount(): number { return this.amount; }\r\n\r\n /**\r\n * Gets the currency code for the payment amount.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode { return this.currency; }\r\n\r\n /**\r\n * Gets the mode or method used for the payment (e.g., CARD, COD).\r\n * @returns The PaymentMode enum value.\r\n */\r\n public getPaymentMode(): PaymentMode { return this.paymentMode; }\r\n\r\n /**\r\n * Gets the raw response data from the payment gateway (potentially large).\r\n * @returns The gateway response string, or undefined if not set.\r\n */\r\n public getGatewayResponse(): string | undefined { return this.gatewayResponse; }\r\n\r\n /**\r\n * Gets the error code returned by the payment gateway, if any.\r\n * @returns The gateway error code string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorCode(): string | undefined { return this.gatewayErrorCode; }\r\n\r\n /**\r\n * Gets the error message returned by the payment gateway, if any.\r\n * @returns The gateway error message string, or undefined if no error occurred or wasn't recorded.\r\n */\r\n public getGatewayErrorMessage(): string | undefined { return this.gatewayErrorMessage; }\r\n\r\n /**\r\n * Gets the total amount that has been refunded for this transaction.\r\n * @returns The refunded amount number (defaults to 0).\r\n */\r\n public getAmountRefunded(): number { return this.amountRefunded; }\r\n\r\n /**\r\n * Gets the last 4 digits of the card used, if applicable.\r\n * @returns The card's last 4 digits string, or undefined.\r\n */\r\n public getCardLast4(): string | undefined { return this.cardLast4; }\r\n\r\n /**\r\n * Gets the brand of the card used (e.g., Visa, Mastercard), if applicable.\r\n * @returns The card brand string, or undefined.\r\n */\r\n public getCardBrand(): string | undefined { return this.cardBrand; }\r\n\r\n /**\r\n * Gets the timestamp when the transaction occurred or was recorded.\r\n * @returns The transaction timestamp as an ISO 8601 string.\r\n */\r\n public getTransactionAt(): ISODateTimeUTC { return this.transactionAt; }\r\n\r\n\r\n /**\r\n * Gets a plain data object representing the payment's current state.\r\n * @returns PaymentData object suitable for serialization or API responses.\r\n */\r\n getDetails(): PaymentData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n ...baseDetails,\r\n txnId: this.getTxnId(),\r\n externalId: this.getExternalId(),\r\n orderNumber: this.getOrderNumber(),\r\n customerId: this.getCustomerId(),\r\n status: this.getStatus(),\r\n subStatus: this.getSubStatus(),\r\n amount: this.getAmount(),\r\n currency: this.getCurrency(),\r\n paymentMode: this.getPaymentMode(),\r\n gatewayErrorCode: this.getGatewayErrorCode(),\r\n amountRefunded: this.getAmountRefunded(),\r\n cardLast4: this.getCardLast4(),\r\n cardBrand: this.getCardBrand(),\r\n transactionAt: this.getTransactionAt(),\r\n };\r\n }\r\n}\r\n"]}
|
package/dist/Classes/Price.d.mts
CHANGED
|
@@ -1,83 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { g as PriceAttributes, P as PriceData, b as default } from '../Common-FbQ5-3QN.mjs';
|
|
2
2
|
import './Enum.mjs';
|
|
3
|
-
|
|
4
|
-
declare class PriceModel {
|
|
5
|
-
protected price: number;
|
|
6
|
-
protected country: CountryCode;
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of PriceModel, storing the currency-correct rounded price.
|
|
9
|
-
* @param price - The initial price value.
|
|
10
|
-
* @param country - The country code used for rounding and determining the currency symbol.
|
|
11
|
-
* @throws {Error} If price is negative or country/currency mapping is missing.
|
|
12
|
-
*/
|
|
13
|
-
constructor(price: number, country: CountryCode);
|
|
14
|
-
/**
|
|
15
|
-
* Gets the country code associated with this price instance.
|
|
16
|
-
* The country code is used for determining currency and formatting rules.
|
|
17
|
-
* @returns The CountryCode enum value.
|
|
18
|
-
*/
|
|
19
|
-
getCountry(): CountryCode;
|
|
20
|
-
/**
|
|
21
|
-
* Gets the rounded price value based on standard currency rules.
|
|
22
|
-
* @returns The numeric price, rounded according to its currency's typical decimal places.
|
|
23
|
-
*/
|
|
24
|
-
getRoundedPrice(): number;
|
|
25
|
-
/**
|
|
26
|
-
* Gets a locale-aware formatted display string for the price stored in this instance.
|
|
27
|
-
* Uses the static `PriceModel.getFormattedString` method for the actual formatting.
|
|
28
|
-
* @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.
|
|
29
|
-
* @returns The formatted price string according to locale rules.
|
|
30
|
-
* @throws {Error} If the currency mapping for the instance's country is not found (via the static method).
|
|
31
|
-
*/
|
|
32
|
-
getFormattedString(locale: LocaleCode): string;
|
|
33
|
-
/**
|
|
34
|
-
* Gets a locale-aware formatted display string for the price.
|
|
35
|
-
* Uses Intl.NumberFormat for accurate formatting based on locale and currency.
|
|
36
|
-
* @param price - The initial price value.
|
|
37
|
-
* @param country - The country code used for rounding and determining the currency symbol.
|
|
38
|
-
* @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.
|
|
39
|
-
* @param options - Configuration options for formatting.
|
|
40
|
-
* @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.
|
|
41
|
-
* @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.
|
|
42
|
-
* @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.
|
|
43
|
-
* @returns The formatted price string according to locale rules.
|
|
44
|
-
*/
|
|
45
|
-
static getFormattedString(price: number, country: CountryCode, locale?: LocaleCode, options?: {
|
|
46
|
-
displayAsInteger?: boolean;
|
|
47
|
-
style?: 'currency' | 'decimal';
|
|
48
|
-
currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
|
|
49
|
-
}): string;
|
|
50
|
-
/**
|
|
51
|
-
* Helper method to determine standard decimal places for a currency.
|
|
52
|
-
* @param currency - The currency code.
|
|
53
|
-
* @returns The number of decimal places (0, 2, or 3 based on common rules).
|
|
54
|
-
*/
|
|
55
|
-
private static getDecimalPlaces;
|
|
56
|
-
/**
|
|
57
|
-
* Adds basic thousand separators (commas) to a number string.
|
|
58
|
-
* Does not handle different locale separators (e.g., periods, spaces).
|
|
59
|
-
* @param numStr - The number string (potentially with decimals).
|
|
60
|
-
* @returns The number string with commas added.
|
|
61
|
-
*/
|
|
62
|
-
private static addThousandSeparators;
|
|
63
|
-
/**
|
|
64
|
-
* Rounds a price value according to the standard decimal places
|
|
65
|
-
* for the currency associated with the given country.
|
|
66
|
-
*
|
|
67
|
-
* @param price - The price value to round. Must be a non-negative number.
|
|
68
|
-
* @param country - The country code to determine the currency and rounding rules.
|
|
69
|
-
* @returns The rounded price as a number.
|
|
70
|
-
* @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.
|
|
71
|
-
*/
|
|
72
|
-
static getRoundedPrice(price: number, country: CountryCode): number;
|
|
73
|
-
/**
|
|
74
|
-
* Static method to retrieve the currency code associated with a given country code.
|
|
75
|
-
* Uses the `CountryCurrencyMap` to find the corresponding currency.
|
|
76
|
-
*
|
|
77
|
-
* @param country - The country code (e.g., 'IN') for which to find the currency.
|
|
78
|
-
* @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.
|
|
79
|
-
*/
|
|
80
|
-
static getCurrency(country: CountryCode): string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { PriceModel as default };
|
package/dist/Classes/Price.d.ts
CHANGED
|
@@ -1,83 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { g as PriceAttributes, P as PriceData, b as default } from '../Common-D-UoxwM0.js';
|
|
2
2
|
import './Enum.js';
|
|
3
|
-
|
|
4
|
-
declare class PriceModel {
|
|
5
|
-
protected price: number;
|
|
6
|
-
protected country: CountryCode;
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of PriceModel, storing the currency-correct rounded price.
|
|
9
|
-
* @param price - The initial price value.
|
|
10
|
-
* @param country - The country code used for rounding and determining the currency symbol.
|
|
11
|
-
* @throws {Error} If price is negative or country/currency mapping is missing.
|
|
12
|
-
*/
|
|
13
|
-
constructor(price: number, country: CountryCode);
|
|
14
|
-
/**
|
|
15
|
-
* Gets the country code associated with this price instance.
|
|
16
|
-
* The country code is used for determining currency and formatting rules.
|
|
17
|
-
* @returns The CountryCode enum value.
|
|
18
|
-
*/
|
|
19
|
-
getCountry(): CountryCode;
|
|
20
|
-
/**
|
|
21
|
-
* Gets the rounded price value based on standard currency rules.
|
|
22
|
-
* @returns The numeric price, rounded according to its currency's typical decimal places.
|
|
23
|
-
*/
|
|
24
|
-
getRoundedPrice(): number;
|
|
25
|
-
/**
|
|
26
|
-
* Gets a locale-aware formatted display string for the price stored in this instance.
|
|
27
|
-
* Uses the static `PriceModel.getFormattedString` method for the actual formatting.
|
|
28
|
-
* @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.
|
|
29
|
-
* @returns The formatted price string according to locale rules.
|
|
30
|
-
* @throws {Error} If the currency mapping for the instance's country is not found (via the static method).
|
|
31
|
-
*/
|
|
32
|
-
getFormattedString(locale: LocaleCode): string;
|
|
33
|
-
/**
|
|
34
|
-
* Gets a locale-aware formatted display string for the price.
|
|
35
|
-
* Uses Intl.NumberFormat for accurate formatting based on locale and currency.
|
|
36
|
-
* @param price - The initial price value.
|
|
37
|
-
* @param country - The country code used for rounding and determining the currency symbol.
|
|
38
|
-
* @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.
|
|
39
|
-
* @param options - Configuration options for formatting.
|
|
40
|
-
* @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.
|
|
41
|
-
* @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.
|
|
42
|
-
* @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.
|
|
43
|
-
* @returns The formatted price string according to locale rules.
|
|
44
|
-
*/
|
|
45
|
-
static getFormattedString(price: number, country: CountryCode, locale?: LocaleCode, options?: {
|
|
46
|
-
displayAsInteger?: boolean;
|
|
47
|
-
style?: 'currency' | 'decimal';
|
|
48
|
-
currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name';
|
|
49
|
-
}): string;
|
|
50
|
-
/**
|
|
51
|
-
* Helper method to determine standard decimal places for a currency.
|
|
52
|
-
* @param currency - The currency code.
|
|
53
|
-
* @returns The number of decimal places (0, 2, or 3 based on common rules).
|
|
54
|
-
*/
|
|
55
|
-
private static getDecimalPlaces;
|
|
56
|
-
/**
|
|
57
|
-
* Adds basic thousand separators (commas) to a number string.
|
|
58
|
-
* Does not handle different locale separators (e.g., periods, spaces).
|
|
59
|
-
* @param numStr - The number string (potentially with decimals).
|
|
60
|
-
* @returns The number string with commas added.
|
|
61
|
-
*/
|
|
62
|
-
private static addThousandSeparators;
|
|
63
|
-
/**
|
|
64
|
-
* Rounds a price value according to the standard decimal places
|
|
65
|
-
* for the currency associated with the given country.
|
|
66
|
-
*
|
|
67
|
-
* @param price - The price value to round. Must be a non-negative number.
|
|
68
|
-
* @param country - The country code to determine the currency and rounding rules.
|
|
69
|
-
* @returns The rounded price as a number.
|
|
70
|
-
* @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.
|
|
71
|
-
*/
|
|
72
|
-
static getRoundedPrice(price: number, country: CountryCode): number;
|
|
73
|
-
/**
|
|
74
|
-
* Static method to retrieve the currency code associated with a given country code.
|
|
75
|
-
* Uses the `CountryCurrencyMap` to find the corresponding currency.
|
|
76
|
-
*
|
|
77
|
-
* @param country - The country code (e.g., 'IN') for which to find the currency.
|
|
78
|
-
* @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.
|
|
79
|
-
*/
|
|
80
|
-
static getCurrency(country: CountryCode): string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { PriceModel as default };
|
package/dist/Classes/Price.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var d={INR:"\u20B9"},h={INR:"en-IN"};var a=class extends Error{constructor(r="Amount cannot be negative."){super(`InvalidAmount: ${r}`),this.name="InvalidPriceAmountError";}},u=class extends Error{constructor(r="Currency code is required."){super(`InvalidCurrency: ${r}`),this.name="InvalidCurrencyCodeError";}},c=class extends Error{constructor(r="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${r}`),this.name="CurrencyMismatchError";}},o=class extends Error{constructor(r){super(`InvalidArgument: ${r}`),this.name="InvalidArgumentError";}};var m=class e{amount;currency;constructor(r){if(r.amount<0)throw new a("Amount cannot be negative.");if(!r.currency)throw new u("Currency code is required.");this.amount=r.amount,this.currency=r.currency;}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(r){if(r instanceof e){if(this.currency!==r.getCurrency())throw new c("Cannot compare prices in different currencies.")}else throw new o("Must be a PriceModel instance.");return this.amount-r.getAmount()}add(r){if(r instanceof e){if(this.currency!==r.getCurrency())throw new c("Cannot add prices in different currencies.")}else throw new o("Must be a PriceModel instance.");return new e({amount:this.amount+r.getAmount(),currency:this.currency})}subtract(r){if(r instanceof e){if(this.currency!==r.getCurrency())throw new c("Cannot subtract prices in different currencies.")}else throw new o("Must be a PriceModel instance.");return new e({amount:this.amount-r.getAmount(),currency:this.currency})}multiply(r){if(r instanceof e){if(this.currency!==r.getCurrency())throw new c("Cannot multiply prices in different currencies.");return new e({amount:this.amount*r.getAmount(),currency:this.currency})}else if(typeof r=="number"&&r>=0)return new e({amount:this.amount*r,currency:this.currency});throw new o("Must be a non-negative number.")}divide(r){if(r instanceof e){if(this.currency!==r.getCurrency())throw new c("Cannot divide prices in different currencies.");return new e({amount:this.amount/r.getAmount(),currency:this.currency})}else if(typeof r=="number"&&r>0)return new e({amount:this.amount/r,currency:this.currency});throw new o("Must be a positive number.")}min(...r){if(r.length===0)throw new o("Must provide at least one PriceModel.");return r.reduce((t,n)=>{if(n instanceof e){if(t.getCurrency()!==n.getCurrency())throw new c("Cannot compare prices in different currencies.")}else throw new o("Must be a PriceModel instance.");return t.compareTo(n)<0?t:n})}max(...r){if(r.length===0)throw new o("Must provide at least one PriceModel.");return r.reduce((t,n)=>{if(n instanceof e){if(t.getCurrency()!==n.getCurrency())throw new c("Cannot compare prices in different currencies.")}else throw new o("Must be a PriceModel instance.");return t.compareTo(n)>0?t:n})}zero(){return new e({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new e({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return e.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return e.getFormattedString(this.amount,this.currency)}static getFormattedString(r,t,n={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let i=h[t];if(!t||!i)throw new u("Invalid currency code for formatting.");let s=r,l=n.displayAsInteger?0:e.getDecimalPlaces(t),y={style:n.style??"currency",currency:t,signDisplay:"never",currencyDisplay:n.currencyDisplay,minimumFractionDigits:l,maximumFractionDigits:l};n.displayAsInteger&&(s=Math.ceil(s));try{return new Intl.NumberFormat(i,y).format(s)}catch(g){return console.error(`Error formatting price for currency "${t}" and locale "${i}":`,g),`${d[t]??t} ${e.addThousandSeparators(s.toFixed(l))}`}}static getDecimalPlaces(r){switch(r){case"INR":default:return 2}}static addThousandSeparators(r){let t=r.split("."),n=t[0],i=t.length>1?"."+t[1]:"";return n.replace(/\B(?=(\d{3})+(?!\d))/g,",")+i}static getRoundedAmount(r,t){if(r<0)throw new a("Amount cannot be negative for rounding.");if(t===void 0)throw new u("Invalid currency code for rounding.");let n=e.getDecimalPlaces(t),i=Math.pow(10,n);return Math.round(r*i)/i}};module.exports=m;//# sourceMappingURL=Price.js.map
|
|
2
2
|
//# sourceMappingURL=Price.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Enum.ts","../../src/Classes/Price.ts"],"names":["CountryCurrencyMap","CurrencySymbolMap","PriceModel","_PriceModel","price","country","locale","options","displayAsInteger","currency","valueToFormat","fractionDigits","formattingOptions","error","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"aAkCO,IAAMA,CAAqB,CAAA,CAClB,EAAwB,CAAA,KACxC,CAEaC,CAAAA,CAAAA,CAAoB,CAC9B,GAAA,CAAiC,QACpC,CAAA,CCrCqBC,IAAAA,CAAAA,CAArB,MAAqBC,CAAW,CACpB,KA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,CAAA,IAAA,CAAK,GAAI,CAAA,EAAA,CAAID,CAAa,CAG7C,CAAA,OAFqB,IAAK,CAAA,KAAA,CAAMd,CAAQe,CAAAA,CAAU,CAAIA,CAAAA,CAGxD,CASA,OAAO,WAAYd,CAAAA,CAAAA,CAA8B,CAC/C,OAAOL,CAAmBK,CAAAA,CAAO,CACnC,CAEF","file":"Price.js","sourcesContent":["/**\r\n * Represents the countries where the application operates or products are available.\r\n */\r\nexport enum OperationalCountry {\r\n /** India */ IN = 'IN',\r\n}\r\n \r\nexport enum OperationalCountryCurrency {\r\n /** India */ INR = 'INR',\r\n}\r\n\r\nexport enum OperationalLocale {\r\n /** India */ 'en-IN' = 'en-IN',\r\n /** India ( Kannada) */ 'kn-IN' = 'kn-IN'\r\n}\r\n\r\nexport enum OperationalLanguage {\r\n en = 'en',\r\n kn = 'kn'\r\n}\r\n\r\nexport const LocaleLanguageMap: Record<OperationalLocale, OperationalLanguage> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalLanguage.en,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalLanguage.kn,\r\n}\r\n\r\nexport const LocaleCountryMap: Record<OperationalLocale, OperationalCountry> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalCountry.IN,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalCountry.IN,\r\n}\r\n\r\n/**\r\n * Defines the supported ISO 4217 currency codes as an enumeration.\r\n */\r\nexport const CountryCurrencyMap = {\r\n /** India */ [OperationalCountry.IN]: OperationalCountryCurrency.INR,\r\n};\r\n\r\nexport const CurrencySymbolMap = {\r\n [OperationalCountryCurrency.INR]: '₹',\r\n}\r\n\r\n/**\r\n * Defines standard gender categories for product targeting.\r\n */\r\nexport enum GenderCategory {\r\n MALE = 'Male',\r\n FEMALE = 'Female',\r\n UNISEX = 'Unisex',\r\n KIDS = 'Kids',\r\n BOY = 'Boy',\r\n GIRL = 'Girl',\r\n}","import { CountryCode, CurrencyCode, LocaleCode } from \"./Common\"; // Assuming these are in Common.ts\r\nimport { CountryCurrencyMap, CurrencySymbolMap } from \"./Enum\"; // Ensure these maps exist\r\n\r\nexport default class PriceModel {\r\n protected price: number;\r\n protected country: CountryCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param price - The initial price value.\r\n * @param country - The country code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(price: number, country: CountryCode) {\r\n this.country = country;\r\n\r\n if(price < 0) {\r\n throw new Error(\"InvalidPrice: Price cannot be negative.\");\r\n }\r\n\r\n this.price = price\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this price instance.\r\n * The country code is used for determining currency and formatting rules.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedPrice(): number {\r\n return PriceModel.getRoundedPrice(this.price, this.country);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price stored in this instance.\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.\r\n * @returns The formatted price string according to locale rules.\r\n * @throws {Error} If the currency mapping for the instance's country is not found (via the static method).\r\n */\r\n public getFormattedString(locale: LocaleCode){\r\n return PriceModel.getFormattedString(this.price, this.country, locale);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param price - The initial price value.\r\n * @param country - The country code used for rounding and determining the currency symbol.\r\n * @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.\r\n * @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.\r\n * @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n static getFormattedString(price: number, country: CountryCode, locale?: LocaleCode, options: { displayAsInteger?: boolean, style?: 'currency' | 'decimal', currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name' } = {}): string {\r\n const displayAsInteger = options.displayAsInteger ?? false;\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[country];\r\n\r\n if (currency === undefined) {\r\n throw new Error('Currency mapping not found for CountryCode');\r\n }\r\n\r\n let valueToFormat = price;\r\n const fractionDigits = displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: options.style ?? 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (displayAsInteger) {\r\n valueToFormat = Math.round(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for country \"${country}\" and currency \"${currency}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case 'INR':\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param country - The country code to determine the currency and rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.\r\n */\r\n static getRoundedPrice(price: number, country: CountryCode): number {\r\n if (price < 0) {\r\n throw new Error(\"Price cannot be negative for rounding.\");\r\n }\r\n\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[country];\r\n if (currency === undefined) {\r\n throw new Error(`Currency mapping not found for CountryCode: ${country}`);\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(price * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n\r\n /**\r\n * Static method to retrieve the currency code associated with a given country code.\r\n * Uses the `CountryCurrencyMap` to find the corresponding currency.\r\n *\r\n * @param country - The country code (e.g., 'IN') for which to find the currency.\r\n * @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.\r\n */\r\n static getCurrency(country: CountryCode): string {\r\n return CountryCurrencyMap[country];\r\n }\r\n\r\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Enum.ts","../../src/Classes/Error.ts","../../src/Classes/Price.ts"],"names":["CurrencySymbolMap","CurrencyLocaleMap","InvalidPriceAmountError","message","InvalidCurrencyCodeError","CurrencyMismatchError","InvalidArgumentError","PriceModel","_PriceModel","data","priceModel","factor","divisor","priceModels","minPrice","currentPrice","maxPrice","amount","currency","options","locale","valueToFormat","fractionDigits","formattingOptions","error","numStr","parts","integer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AMA,EAAM,CAAC,CAAA,CAAI,GAGxD,OADyBC,CAAAA,CAAY,QAAQ,uBAAyB,CAAA,GAAG,CAC/CC,CAAAA,CAC5B,CAWA,OAAO,gBAAA,CAAiBX,EAAgBC,CAAgC,CAAA,CACtE,GAAID,CAAS,CAAA,CAAA,CACX,MAAM,IAAIf,EAAwB,yCAAyC,CAAA,CAG7E,GAAIgB,CAAa,GAAA,KAAA,CAAA,CACf,MAAM,IAAId,CAAAA,CAAyB,qCAAqC,CAAA,CAG1E,IAAMyB,CAAgBrB,CAAAA,CAAAA,CAAW,iBAAiBU,CAAQ,CAAA,CACpDY,EAAa,IAAK,CAAA,GAAA,CAAI,GAAID,CAAa,CAAA,CAG7C,OAFqB,IAAK,CAAA,KAAA,CAAMZ,EAASa,CAAU,CAAA,CAAIA,CAGzD,CACF","file":"Price.js","sourcesContent":["/**\r\n * Represents the countries where the application operates or products are available.\r\n */\r\nexport enum OperationalCountry {\r\n /** India */ IN = 'IN',\r\n}\r\n \r\nexport enum OperationalCountryCurrency {\r\n /** India */ INR = 'INR',\r\n}\r\n\r\nexport enum OperationalLocale {\r\n /** India */ 'en-IN' = 'en-IN',\r\n /** India ( Kannada) */ 'kn-IN' = 'kn-IN'\r\n}\r\n\r\nexport enum OperationalLanguage {\r\n en = 'en',\r\n kn = 'kn'\r\n}\r\n\r\nexport const LocaleLanguageMap: Record<OperationalLocale, OperationalLanguage> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalLanguage.en,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalLanguage.kn,\r\n}\r\n\r\nexport const LocaleCountryMap: Record<OperationalLocale, OperationalCountry> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalCountry.IN,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalCountry.IN,\r\n}\r\n\r\n/**\r\n * Defines the supported ISO 4217 currency codes as an enumeration.\r\n */\r\nexport const CountryCurrencyMap = {\r\n /** India */ [OperationalCountry.IN]: OperationalCountryCurrency.INR,\r\n};\r\n\r\nexport const CurrencySymbolMap = {\r\n [OperationalCountryCurrency.INR]: '₹',\r\n}\r\n\r\nexport const CurrencyLocaleMap = {\r\n [OperationalCountryCurrency.INR]: OperationalLocale[\"en-IN\"],\r\n}\r\n\r\n/**\r\n * Defines standard gender categories for product targeting.\r\n */\r\nexport enum GenderCategory {\r\n MALE = 'Male',\r\n FEMALE = 'Female',\r\n UNISEX = 'Unisex',\r\n KIDS = 'Kids',\r\n BOY = 'Boy',\r\n GIRL = 'Girl',\r\n GENERAL = 'General',\r\n}\r\n\r\nexport enum ImageCategory {\r\n PRIMARY = 'PRIMARY',\r\n GALLERY = 'GALLERY'\r\n}\r\n\r\nexport enum TaxCategory {\r\n APPAREL = 'apparel',\r\n EXEMPT = 'exempt'\r\n}\r\n\r\nexport enum TaxSystem {\r\n GST = 'GST',\r\n}\r\n\r\n/**\r\n * LineItemState\r\n * \r\n * INITIAL: Item added to order, not yet processed.\r\n * PROCESSING: Item is being prepared for shipment.\r\n * SHIPPED: Item dispatched to customer.\r\n * DELIVERED: Item delivered to customer.\r\n * CANCELLED: Item cancelled before shipment or delivery.\r\n * RETURN_REQUESTED: Customer requests to return item.\r\n * RETURNED: Item received back from customer.\r\n * REFUND_INITIATED: Refund initiated for item.\r\n * REFUNDED: Refund processed for item.\r\n * ON_HOLD: Item is paused due to payment, inventory, or other issues.\r\n */\r\nexport enum LineItemState {\r\n INITIAL = \"INITIAL\",\r\n PROCESSING = \"PROCESSING\",\r\n SHIPPED = \"SHIPPED\",\r\n DELIVERED = \"DELIVERED\",\r\n CANCELLED = \"CANCELLED\",\r\n RETURN_REQUESTED = \"RETURN_REQUESTED\",\r\n RETURNED = \"RETURNED\",\r\n REFUND_INITIATED = \"REFUND_INITIATED\",\r\n REFUNDED = \"REFUNDED\",\r\n ON_HOLD = \"ON_HOLD\",\r\n}","export class LineItemNotFoundError extends Error {\r\n constructor(lineItemId: string) {\r\n super(`Line item with ID '${lineItemId}' not found in the cart.`);\r\n this.name = 'LineItemNotFoundError';\r\n }\r\n}\r\n\r\nexport class DuplicateSizeError extends Error {\r\n constructor(size: string) {\r\n super(`Duplicate size found: ${size}`);\r\n this.name = 'DuplicateSizeError';\r\n }\r\n}\r\n\r\nexport class ProductMismatchError extends Error {\r\n constructor(message: string = \"Product and selection attributes do not match.\") {\r\n super(`ProductMismatch: ${message}`);\r\n this.name = 'ProductMismatchError';\r\n }\r\n}\r\n\r\nexport class ProductInactiveError extends Error {\r\n constructor(message: string = \"Product is not active.\") {\r\n super(`ProductInactive: ${message}`);\r\n this.name = 'ProductInactiveError';\r\n }\r\n}\r\n\r\nexport class SelectionAttributeParseError extends Error {\r\n constructor(message: string = \"Failed to parse selection attributes key.\") {\r\n super(`SelectionAttributeParseError: ${message}`);\r\n this.name = 'SelectionAttributeParseError';\r\n }\r\n}\r\n\r\nexport class SizeMismatchError extends Error {\r\n constructor(message: string = \"Size does not match.\") {\r\n super(`SizeMismatch: ${message}`);\r\n this.name = 'SizeMismatchError';\r\n }\r\n}\r\n\r\nexport class PricingNotFoundError extends Error {\r\n constructor(message: string = \"Pricing details not available for the product\") {\r\n super(`NotFound: ${message}`);\r\n this.name = 'PricingNotFoundError';\r\n }\r\n}\r\n\r\nexport class InvalidTaxRuleError extends Error {\r\n constructor(message: string = \"Tax rule category mismatch.\") {\r\n super(`InvalidTaxRule: ${message}`);\r\n this.name = 'InvalidTaxRuleError';\r\n }\r\n}\r\n\r\nexport class InvalidTaxCategoryError extends Error {\r\n constructor(message: string = \"Tax category is not valid.\") {\r\n super(`InvalidTaxCategory: ${message}`);\r\n this.name = 'InvalidTaxCategoryError';\r\n }\r\n}\r\n\r\nexport class InvalidMinQuantityError extends Error {\r\n constructor(message: string = \"Minimum quantity must be greater than zero.\") {\r\n super(`InvalidMinQuantity: ${message}`);\r\n this.name = 'InvalidMinQuantityError';\r\n }\r\n}\r\n\r\nexport class InvalidTieredPriceError extends Error {\r\n constructor(message: string) {\r\n super(`InvalidTieredPrice: ${message}`);\r\n this.name = 'InvalidTieredPriceError';\r\n }\r\n}\r\n\r\nexport class InvalidQuantityError extends Error {\r\n constructor(message: string = \"Quantity must be greater than zero.\") {\r\n super(`InvalidQuantity: ${message}`);\r\n this.name = 'InvalidQuantityError';\r\n }\r\n}\r\n\r\nexport class NoApplicableTierError extends Error {\r\n constructor(quantity: number) {\r\n super(`NoApplicableTier: Quantity ${quantity} does not meet the minimum purchase requirement.`);\r\n this.name = 'NoApplicableTierError';\r\n }\r\n}\r\n\r\nexport class TaxSlabNotFoundError extends Error {\r\n constructor(message: string = \"No applicable tax slab or multiple slabs found for the given unit price.\") {\r\n super(`TaxSlabNotFound: ${message}`);\r\n this.name = 'TaxSlabNotFoundError';\r\n }\r\n}\r\n\r\nexport class InvalidPriceAmountError extends Error {\r\n constructor(message: string = \"Amount cannot be negative.\") {\r\n super(`InvalidAmount: ${message}`);\r\n this.name = 'InvalidPriceAmountError';\r\n }\r\n}\r\n\r\nexport class InvalidCurrencyCodeError extends Error {\r\n constructor(message: string = \"Currency code is required.\") {\r\n super(`InvalidCurrency: ${message}`);\r\n this.name = 'InvalidCurrencyCodeError';\r\n }\r\n}\r\n\r\nexport class CurrencyMismatchError extends Error {\r\n constructor(message: string = \"Cannot perform operation on prices with different currencies.\") {\r\n super(`CurrencyMismatch: ${message}`);\r\n this.name = 'CurrencyMismatchError';\r\n }\r\n}\r\n\r\nexport class InvalidArgumentError extends Error {\r\n constructor(message: string) {\r\n super(`InvalidArgument: ${message}`);\r\n this.name = 'InvalidArgumentError';\r\n }\r\n}\r\n\r\nexport class InvalidImageSourceError extends Error {\r\n constructor(message: string = \"Invalid image source configuration.\") {\r\n super(`InvalidImageSource: ${message}`);\r\n this.name = 'InvalidImageSourceError';\r\n }\r\n}","import { CurrencyCode } from \"./Common\";\r\nimport { CurrencyLocaleMap, CurrencySymbolMap, OperationalCountryCurrency } from \"./Enum\";\r\nimport {\r\n InvalidPriceAmountError,\r\n InvalidCurrencyCodeError,\r\n CurrencyMismatchError,\r\n InvalidArgumentError\r\n} from \"./Error\";\r\n\r\nexport type PriceAttributes = {\r\n amount: number;\r\n currency: CurrencyCode;\r\n}\r\n\r\nexport type PriceData = PriceAttributes;\r\n\r\nexport default class PriceModel {\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param amount - The initial price value.\r\n * @param currency - The currency code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(data: PriceAttributes) {\r\n if (data.amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative.\");\r\n }\r\n\r\n if (!data.currency) {\r\n throw new InvalidCurrencyCodeError(\"Currency code is required.\");\r\n }\r\n\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n }\r\n\r\n /**\r\n * Gets the currency associated with this price instance.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n /**\r\n * Returns the raw numeric price value.\r\n */\r\n public getAmount(): number {\r\n return this.amount;\r\n }\r\n\r\n /**\r\n *\r\n * @returns PriceData\r\n */\r\n public getDetails(): PriceData {\r\n return {\r\n amount: this.amount,\r\n currency: this.currency\r\n }\r\n }\r\n\r\n /**\r\n * Compares this price with another {@link PriceModel} instance.\r\n *\r\n * The comparison is performed using the numeric price value and is only valid\r\n * when both prices are expressed in the same currency.\r\n *\r\n * ### Comparison result:\r\n * - Returns a **negative number** if this price is **less than** `priceModel`\r\n * - Returns **zero** if both prices are **equal**\r\n * - Returns a **positive number** if this price is **greater than** `priceModel`\r\n *\r\n * @param priceModel - The {@link PriceModel} instance to compare against.\r\n *\r\n * @returns\r\n * A signed number representing the comparison result:\r\n * - `< 0` → this price is lower\r\n * - `0` → prices are equal\r\n * - `> 0` → this price is higher\r\n *\r\n * @throws {Error}\r\n * Throws an error if:\r\n * - `priceModel` is not an instance of {@link PriceModel}\r\n * - The currencies of the two prices do not match\r\n *\r\n * @example\r\n * ```ts\r\n * const a = new PriceModel(\"USD\", 100);\r\n * const b = new PriceModel(\"USD\", 150);\r\n *\r\n * a.compareTo(b); // -50\r\n * b.compareTo(a); // 50\r\n * a.compareTo(a); // 0\r\n * ```\r\n */\r\n public compareTo(priceModel: PriceModel): number {\r\n if (!(priceModel instanceof PriceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return this.amount - priceModel.getAmount();\r\n }\r\n\r\n public add(priceModel: PriceModel): PriceModel {\r\n if (!(priceModel instanceof PriceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot add prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount + priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public subtract(priceModel: PriceModel): PriceModel {\r\n if (!(priceModel instanceof PriceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot subtract prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount - priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public multiply(factor: number | PriceModel): PriceModel {\r\n if (factor instanceof PriceModel) {\r\n if (this.currency !== factor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot multiply prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount * factor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof factor === \"number\" && factor >= 0) {\r\n return new PriceModel({\r\n amount: this.amount * factor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a non-negative number.\");\r\n }\r\n\r\n public divide(divisor: number | PriceModel): PriceModel {\r\n if (divisor instanceof PriceModel) {\r\n if (this.currency !== divisor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot divide prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount / divisor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof divisor === \"number\" && divisor > 0) {\r\n return new PriceModel({\r\n amount: this.amount / divisor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a positive number.\");\r\n }\r\n\r\n public min(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((minPrice, currentPrice) => {\r\n if (!(currentPrice instanceof PriceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (minPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return minPrice.compareTo(currentPrice) < 0 ? minPrice : currentPrice;\r\n });\r\n }\r\n\r\n public max(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((maxPrice, currentPrice) => {\r\n if (!(currentPrice instanceof PriceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (maxPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return maxPrice.compareTo(currentPrice) > 0 ? maxPrice : currentPrice;\r\n });\r\n }\r\n\r\n /**\r\n * Gets a zero value PriceModel for the same currency.\r\n * @returns A PriceModel instance representing zero in the same currency.\r\n */\r\n public zero(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: 0\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the price is zero.\r\n * @returns True if the price is zero, false otherwise.\r\n */\r\n public isZero(): boolean {\r\n return this.amount === 0;\r\n }\r\n\r\n\r\n public round(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: this.getRoundedAmount()\r\n });\r\n }\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedAmount(): number {\r\n return PriceModel.getRoundedAmount(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price stored in this instance.\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n public getFormattedString() {\r\n return PriceModel.getFormattedString(this.amount, this.currency);\r\n }\r\n\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the amount.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param amount - The initial amount value.\r\n * @param currency - The currency code for formatting.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the amount rounded to the next nearest integer (no decimals). Defaults to false.\r\n * @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.\r\n * @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.\r\n * @returns The formatted price string according to locale rules.\r\n * @throws {Error} If currency code is invalid.\r\n */\r\n static getFormattedString(amount: number, currency: CurrencyCode, options: {\r\n displayAsInteger?: boolean,\r\n style?: 'currency' | 'decimal',\r\n currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name'\r\n } = {\r\n displayAsInteger: false,\r\n style: 'currency',\r\n currencyDisplay: 'symbol'\r\n }): string {\r\n\r\n const locale = CurrencyLocaleMap[currency];\r\n if (!currency || !locale) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for formatting.');\r\n }\r\n\r\n let valueToFormat = amount;\r\n const fractionDigits = options.displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: options.style ?? 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (options.displayAsInteger) {\r\n valueToFormat = Math.ceil(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for currency \"${currency}\" and locale \"${locale}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case OperationalCountryCurrency.INR:\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param currency - The currency code to determine the rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the price is negative or currency is invalid.\r\n */\r\n static getRoundedAmount(amount: number, currency: CurrencyCode): number {\r\n if (amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative for rounding.\");\r\n }\r\n\r\n if (currency === undefined) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for rounding.');\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(amount * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n}"]}
|
package/dist/Classes/Price.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as default}from'../chunk-
|
|
1
|
+
export{a as default}from'../chunk-54RUAXYE.mjs';import'../chunk-72DR3HF2.mjs';import'../chunk-NJKSUUOB.mjs';//# sourceMappingURL=Price.mjs.map
|
|
2
2
|
//# sourceMappingURL=Price.mjs.map
|