UNPKG

@magic.batua/utility

Version:

The Utility module manages all the utility bills functionalities of the Magic Batua platform.

69 lines (57 loc) 2.13 kB
/** * @module UtilityBill * @overview Defines the `UtilityBill` class * * @author Animesh Mishra <hello@animesh.ltd> * @copyright © 2018 Animesh Ltd. All Rights Reserved. */ import { Electricity } from "./Source/Electricity" import { Gas } from "./Source/Gas" import { Insurance } from "./Source/Insurance" import { Provider } from "./Source/Provider" /** * Models a utility bill. */ export class UtilityBill { /** Service category. Either of Electricity, Gas or Insurance. */ public service: string /** Payment instruction sent to Rocket in Pocket servers */ public instructions: Electricity | Gas | Insurance /** Transaction status */ public status: string /** Bill aggregator's transaction reference */ public vendorReference: string /** Operator's transaction reference */ public operatorReference: string /** Amount debited from Magic Batua's wallet balance. */ public amountCharged: number /** Date and time of recharge request */ public date: Date public constructor(instructions: Electricity | Gas | Insurance, response: any) { // Set transaction category switch(instructions.constructor) { case Electricity: this.service = "Electricity" break case Gas: this.service = "Gas" break default: this.service = "Insurance" } this.instructions = instructions this.status = response.status this.vendorReference = response.rocket_trans_id this.operatorReference = response.opr_transid this.amountCharged = Number(response.charged_amt) // response.datetime has "[UTC]" as suffix which needs to be removed // for successful instantiation of a Date object let formattedDate = response.datetime.substr(0, response.datetime.indexOf("[")) this.date = new Date(formattedDate) } } // Exports export { Electricity } export { Gas } export { Insurance } export { Provider }