UNPKG

@magic.batua/utility

Version:

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

115 lines 3.82 kB
"use strict"; /** * @module Gas * @overview Defines the `Gas` class * * @author Animesh Mishra <hello@animesh.ltd> * @copyright © 2018 Animesh Ltd. All Rights Reserved. */ Object.defineProperty(exports, "__esModule", { value: true }); const Request = require("request-promise-native"); const UtilityError = require("./UtilityError"); const Provider_1 = require("./Provider"); const index_1 = require("../index"); /** Manages gas bill payments. */ class Gas { constructor(provider, accountNumber, amount) { this.provider = provider; this.accountNumber = accountNumber; this.amount = amount; } /** * Makes the bill payment of gas connection. * * In case of Mahanagar Gas, you must send `billGroup` information through the optional * `extra` parameter. * * @param creds Merchant credentials to access Rocket in Pocket API * @param amount In Rupees. Must be exact due amount. * @param extra Any optional parameters. */ async Pay(creds, live = false, extra) { let options = { method: "GET", uri: `https://${creds.baseURL}/pay/gas`, headers: { Accept: "application/json" }, qs: { client_id: creds.merchantID, client_key: creds.merchantKey, provider_code: this.provider.code, connection_provider: this.provider.name, account_number: this.accountNumber, amount: this.amount, bill_group: extra ? extra.billGroup : null, live: live } }; let response = await Request(options); response = JSON.parse(response); let error = UtilityError.Check(response); if (error) { throw error; } return new index_1.UtilityBill(this, response); } /** * Returns a list of all gas providers supported by Rocket in Pocket * API. */ static async GetProviders(creds) { let options = { method: "GET", uri: `https://${creds.baseURL}/providers/gas`, headers: { Accept: "application/json" }, qs: { client_id: creds.merchantID, client_key: creds.merchantKey } }; let response = await Request(options); response = JSON.parse(response); let error = UtilityError.Check(response); if (error) { throw error; } let providers = Provider_1.Provider.InitList(response); return providers; } /** * Checks status of a previously submitted bill payment request. We make use of Rocket in * Pocket callbacks for status updates. So this is largely implemented as a backup in * case RIP callback systems fail. * * @param transactionID Magic Batua transaction ID of the recharge request */ static async CheckStatus(creds, transactionID) { let options = { method: "GET", uri: `https://${creds.baseURL}/recharge/order`, headers: { Accept: "application/json" }, qs: { client_order_id: transactionID } }; let response = await Request(options); response = JSON.parse(response); let error = UtilityError.Check(response); if (error) { throw error; } return { operatorReference: response.opr_transid, vendorReference: response.rocket_trans_id, status: response.status, date: response.datetime }; } } exports.Gas = Gas; //# sourceMappingURL=Gas.js.map