UNPKG

@magic.batua/utility

Version:

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

225 lines (204 loc) 8.97 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Source/Electricity.js - Postman Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Electricity.html">Electricity</a><ul class='methods'><li data-type='method'><a href="Electricity.html#.CheckStatus">CheckStatus</a></li><li data-type='method'><a href="Electricity.html#.GetProviders">GetProviders</a></li><li data-type='method'><a href="Electricity.html#Pay">Pay</a></li><li data-type='method'><a href="Electricity.html#Validate">Validate</a></li></ul></li><li><a href="Gas.html">Gas</a><ul class='methods'><li data-type='method'><a href="Gas.html#.CheckStatus">CheckStatus</a></li><li data-type='method'><a href="Gas.html#.GetProviders">GetProviders</a></li><li data-type='method'><a href="Gas.html#Pay">Pay</a></li></ul></li><li><a href="Insurance.html">Insurance</a><ul class='methods'><li data-type='method'><a href="Insurance.html#.CheckStatus">CheckStatus</a></li><li data-type='method'><a href="Insurance.html#.GetProviders">GetProviders</a></li><li data-type='method'><a href="Insurance.html#Pay">Pay</a></li></ul></li><li><a href="Provider.html">Provider</a><ul class='methods'><li data-type='method'><a href="Provider.html#.InitList">InitList</a></li><li data-type='method'><a href="Provider.html#.WithCode">WithCode</a></li></ul></li><li><a href="UtilityBill.html">UtilityBill</a></li></ul><h3>Modules</h3><ul><li><a href="module-UtilityError.html">UtilityError</a><ul class='methods'><li data-type='method'><a href="module-UtilityError.html#~Check">Check</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">Source/Electricity.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>"use strict"; /** * @module Electricity * @overview Defines the `Electricity` class * * @author Animesh Mishra &lt;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 electricity bill payments. */ class Electricity { constructor(provider, accountNumber) { this.amount = 0; this.provider = provider; this.accountNumber = accountNumber; } /** * Returns the current due amount of the account. Since utility APIs, * expect exact bill amount you must call this API before calling the payment API. * * In case of MSEDC - MAHARASHTRA provider, you must send `billUnit` and `processingCycle` information * too through the optional `extra` parameter. * * In case of Reliance Energy - MUMBAI provider, you must send `cycleNumber` information through the * optional `extra` parameter. * * In case of Torrent Power provider, you must send `city` name through the `extra` parameter. * * @param creds Merchant credentials to connect to Rocket in Pocket API * @param extra Optional parameters only required for some parameters */ async Validate(creds, extra) { let options = { method: "GET", uri: `https://${creds.baseURL}/validate/electricity`, 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_unit: extra ? extra.billUnit : null, processing_cycle: extra ? extra.processingCycle : null, cycle_number: extra ? extra.cycleNumber : null, city: extra ? extra.city : null } }; let response = await Request(options); response = JSON.parse(response); let error = UtilityError.Check(response); if (error) { throw error; } return Number(response.particulars.due_amount); } /** * Makes the bill payment of electricity connection. * * In case of MSEDC - MAHARASHTRA provider, you must send `billUnit` and `processingCycle` information * too through the optional `extra` parameter. * * In case of Reliance Energy - MUMBAI provider, you must send `cycleNumber` information through the * optional `extra` parameter. * * In case of Torrent Power provider, you must send `city` name through the `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, amount, live = false, extra) { let options = { method: "GET", uri: `https://${creds.baseURL}/pay/electricity`, 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: amount, bill_unit: extra ? extra.billUnit : null, processing_cycle: extra ? extra.processingCycle : null, cycle_number: extra ? extra.cycleNumber : null, city: extra ? extra.city : 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 electricity providers supported by Rocket in Pocket * API. */ static async GetProviders(creds) { let options = { method: "GET", uri: `https://${creds.baseURL}/providers/electricity`, 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.Electricity = Electricity; //# sourceMappingURL=Electricity.js.map</code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated at Tue Mar 20 2018 03:29:29 GMT+0530 (IST) </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>