{"_id":"@aberba/hubtel","_rev":"2-b6203aa01dceaa2f10800889762a6022","name":"@aberba/hubtel","dist-tags":{"latest":"0.2.2"},"versions":{"0.2.1":{"name":"@aberba/hubtel","version":"0.2.1","description":"Hubtel API for Node.js","main":"index.js","scripts":{"test-momo":"node tests/mobile-money.test.js","test-sms":"node tests/sms.test.js"},"keywords":["hubtel"],"repository":{"type":"git","url":"git+https://github.com/aberba/hubtel-nodejs.git"},"bugs":{"url":"https://github.com/aberba/hubtel-nodejs/issues"},"author":{"name":"Lawrence Aberba","email":"karabutaworld@gmail.com"},"license":"BSL-1.0","dependencies":{"node-fetch":"^2.2.0"},"gitHead":"84a04efe16476d9d4da7190db1e394262838ce88","homepage":"https://github.com/aberba/hubtel-nodejs#readme","_id":"@aberba/hubtel@0.2.1","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"aberba","email":"karabutaworld@gmail.com"},"dist":{"integrity":"sha512-wKAJ+dYJsCiFRH66gm1vgRA27gxgFZtMU7SYpS6EpPxOzrC+itwQ3uP9InUy2N3S+jEwUkqNKabXoYUp2p+whQ==","shasum":"ed95337be7e0f1a4897917993fa9759deefb5d68","tarball":"https://registry.npmjs.org/@aberba/hubtel/-/hubtel-0.2.1.tgz","fileCount":10,"unpackedSize":21395,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb8GagCRA9TVsSAnZWagAA/tgP/2UtyxkfdZtbuHS39jQd\nT/nexhtZ258EAexIXu9fzNGTdYGeSio67Y9HQelhzXu3G9et2JnQM2wPfdR/\nMSMQlxj5tSFHyAVIg462X8J1L/VPXhM3fJ6yTZRyPTHEqNRDq44cP/7kTsKB\nHxUXcP2Qo6gdjWCI07Wx63dKw1rVCkyPEcyotjYx17jO9uL9gwTa8xwKWhEW\nQc5hqmAXueXqnoGsZ9l5V2jugvqsKKJtvEnkx3owVwvBrGxBzN8ZujNPL0yJ\nIlbivetWdPLrvGlWareNK90ojo9tLWUbVktCLqJjLvKSBAnAkRQyGcbtUvdM\nA/nyMxllhGvzSrR8k3ClQTYSj0enq/OAsU082dmGgYwhUfBNFtJhBwYzbPeC\nIyWTYyiw+zkaxpn+rP1ZK6LLt+f01R6hJgWhjE2YY8qOyXH0lUN3LEsleaXK\nBPZxdRCiVtnaavMJACra8hyeNiWKz4/rm/UiebOF+M4oghYVDdHwZ8Z2DKlR\nDipWCyIrYgpkqSrwvB8TuVL6MlkqgF1wzri+3s29KSy5f0AylCpPR/kecn8h\nsp3HMULeoMH/uNAHlcD0Y4QHsiyeJcV26k5bDcnO4M0IM0FP7ji+64RLstNb\nlEI8xMeLhvpMVhKcBvmO8D+Hg98gADOGkIoO3v6BfDf3nU0R+eS7+rSTs4P8\nK0Bx\r\n=EOzz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAvAwoVRRM7RP8cI0y0d3/zdIQ7HbMyyXYf9Y1nVlkDTAiEAtyvumw/46hPUazusmZtJSbY+uKtUIxuvvvkz3JIACU8="}]},"maintainers":[{"name":"aberba","email":"karabutaworld@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hubtel_0.2.1_1542481567918_0.8815858374226433"},"_hasShrinkwrap":false},"0.2.2":{"name":"@aberba/hubtel","version":"0.2.2","description":"Hubtel API for Node.js","main":"index.js","scripts":{"test-momo":"node tests/mobile-money.test.js","test-sms":"node tests/sms.test.js"},"keywords":["hubtel","sms","mobile money","momo","payments"],"repository":{"type":"git","url":"git+https://github.com/aberba/hubtel-nodejs.git"},"bugs":{"url":"https://github.com/aberba/hubtel-nodejs/issues"},"author":{"name":"Lawrence Aberba","email":"karabutaworld@gmail.com"},"license":"BSL-1.0","dependencies":{"node-fetch":"^2.2.0"},"gitHead":"d204209743d41aa04acc4155ba7e174845590a60","homepage":"https://github.com/aberba/hubtel-nodejs#readme","_id":"@aberba/hubtel@0.2.2","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"aberba","email":"karabutaworld@gmail.com"},"dist":{"integrity":"sha512-brcZUYfqTNogpSxvynnYlsboiBEmTIQFl9FQ7pEM7UTzCGVt7psUrkQigip0ypFWzTl2S5BiF35zscrIQPXz8w==","shasum":"f5ec13fa70e876af0ed65c80012809612dff2b9e","tarball":"https://registry.npmjs.org/@aberba/hubtel/-/hubtel-0.2.2.tgz","fileCount":10,"unpackedSize":21471,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb8GgNCRA9TVsSAnZWagAAIZwP/jG60jG7nq5xb/0Lbjod\nQe+zkBFP5zQeSREF7d+u2AC6Ts/AbtYju8JjZCHBx78fRoyhtUsHzr0vnIjQ\nKiadsGnpkSu1spN8kNUJnqlE3y81Dv2e+s2HONgiKmlf69RWNN9sqMk9W/Bw\ndfi72z1c8w3QrMJ+we8gHzj+4Pxx7vT8xzFAx7ZPHN2jFVTOx+YhZiDgXCs6\nv7JgJ9Nohjk4m5JGC9e6TRAjA1kYUvT0c1DRwwIbdw+DZXyZiVv5Gm8Z12wO\nDYI2B67k8U3s1vMSgHnl5doeFwnO+7ucle8BDnirAAs22A1EzEQf0iKp5hmG\ntdRLjCD8LNT8sNQpSMeDOxXrY5dvnG8NNgMsC10dcnUnBse+/FlNcKyOu/kM\nENMsc7cokmX2VERFfrTQ/a4W7Ll7rOYEwc2E/pOkvnQ5JEb9ASEEPA0jR/DI\nT/uur67FtIBSjS4xp+Z1zDkv+JbdvMvyL6qV6SQ93cJEM8q4WnK9y9H64hJp\nbz9WRGgSxpnm4WLwpZOnmBy0BxikjTfWGGJmNBaN3+q6WfPrSRKE9XjmiO4c\n2Zd3d0lfSDUS03AIKudNbMbyF0YTZ10ugWu/+E6mqD7Xxt4RhrmeGmdybloT\nHS5kELzp+A6MZcoDYtNcb5HyqOM1rwiwQAuVJWPhYrYsK/hvLKGckMiYeD5L\nX5Rr\r\n=OBaR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBGFSZ+b7ONuONRpRviF095asNDMdLB+VKGiCsHbJl5YAiBOtKCcQo13gNJXjjHIwTJT1eIPEGA1zlbmGCAEtejmjA=="}]},"maintainers":[{"name":"aberba","email":"karabutaworld@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hubtel_0.2.2_1542481932554_0.7532739294887503"},"_hasShrinkwrap":false}},"time":{"created":"2018-11-17T19:06:07.760Z","0.2.1":"2018-11-17T19:06:08.081Z","modified":"2022-04-04T10:58:59.835Z","0.2.2":"2018-11-17T19:12:12.682Z"},"maintainers":[{"name":"aberba","email":"karabutaworld@gmail.com"}],"description":"Hubtel API for Node.js","homepage":"https://github.com/aberba/hubtel-nodejs#readme","keywords":["hubtel","sms","mobile money","momo","payments"],"repository":{"type":"git","url":"git+https://github.com/aberba/hubtel-nodejs.git"},"author":{"name":"Lawrence Aberba","email":"karabutaworld@gmail.com"},"bugs":{"url":"https://github.com/aberba/hubtel-nodejs/issues"},"license":"BSL-1.0","readme":"# Hubtel API\nThis is an unofficial [Hubtel API](https://hubtel.com) for Node.js.\n\n## Installation\nUsing Node.js v8.X or latest, you install using:\n\n```sh\nnpm install hubtel-mx\n```\n\n> WARNING: Hubtel's APIs have some quirks, rules and restrictions you need to be aware of. Before using this package, I recommend you read on their [API reference](https://developers.hubtel.com/v1.0/reference) related to the service you're planning to use. Believe me, you'll use to save yourself days of...whew...hmm...frustration. \n\n> From a security standpoint, it much safer to store all account API keys and other credentials in environment variables instead of hard-coding them in your source code.\n\n\n## Mobile Money API\nThe `Config` class is used for API configuration. Substitute information provided below with your own account information. Check the [Hubtel Merhcant API Documentation](https://developers.hubtel.com/documentations/merchant-account-api) for more information.\n\n```js\nconst {\n    MobileMoney,\n    Config,\n    getErrorMessageFromResponseCode\n} = require(\"hubtel-mx\");\n\n// Use your own account credentials\nconst secret = {\n    clientId: \"XXXXXXXXX\",\n    clientSecret: \"XXXXXXXXXXXXXXXX\",\n    merchantAccountNumber: \"HMXXXXXXXXX\"\n};\n\nconst config = new Config({\n    clientId: secret.clientId,\n    clientSecret: secret.clientSecret,\n    merchantAccountNumber: secret.merchantAccountNumber\n});\n\nconst mobileMoney = new MobileMoney(config);\n\nmobileMoney\n    .receive({\n        CustomerName: \"Mary Doe\",\n        CustomerMsisdn: \"05XXXXXXXX\",\n        CustomerEmail: \"user@example.com\",\n        Channel: \"mtn-gh\",\n        Amount: 7.55,\n        PrimaryCallbackUrl: \"https://example.com/payment_callback\",\n        Description: \"A bowl of gari\",\n        ClientReference: \"UniqueXXXXX21XX\"\n    })\n    .then(responseJSON => {\n        console.log(responseJSON);\n        console.log(\n            \"Response message: \",\n            getErrorMessageFromResponseCode(responseJSON.ResponseCode)\n        );\n    })\n    .catch(err => console.log(err));\n\nmobileMoney\n    .send({\n        RecipientName: \"Adongo Samuel\",\n        RecipientMsisdn: \"23327XXXXXXX\",\n        CustomerEmail: \"user@example.com\",\n        Channel: \"tigo-gh\",\n        Amount: 60.05,\n        PrimaryCallbackUrl: \"https://example.com/payment_callback\",\n        SecondaryCallbackUrl: \"\",\n        Description: \"Monthly rent payment\",\n        ClientReference: \"UniqueXXXXX21XX\"\n    })\n    .then(responseJSON => console.log(responseJSON))\n    .catch(err => console.log(err));\n\n// Getting errors messages\nconsole.log(\"Code 0000 message:\", getErrorMessageFromResponseCode(\"0000\"));\n\n// Cool guys use fat arrows, async and await from ES6 ;)\nconst payUsualBills = async ClientReference => {\n    const paymentData = {\n        RecipientName: \"Tax tax tax!!\",\n        RecipientMsisdn: \"23327XXXXXXX\",\n        CustomerEmail: \"user@example.com\",\n        Channel: \"tigo-gh\",\n        Amount: 100000.01,\n        PrimaryCallbackUrl: \"https://example.com/payment_callback\",\n        SecondaryCallbackUrl: \"\",\n        Description: \"Monthly tax payment\"\n    };\n\n    return await mobileMoney.send(Object.assign(paymentData, ClientReference)); // object destructuring in future\n};\n\n// may throw, wrap in try catch block to handle errors\nconsole.log(payUsualBills(\"UniqueXXXXX21XX\"));\n```\n\n### Note (Mobile Money API)\nThe `String getErrorMessageFromResponseCode(String code)` function returns an error message using the API response code passed as an argument. Some of these messages are modified versions of what is available in the documentation... such that it is much clearer (in my judgement) when displayed to a customer than those provided by the API response (`responseJSON.Data.Description`). Use `responseJSON.Data.Description` to be on par with Hubtel.\n\n\n## SMS Messaging API\nThe `Config` class is used for API configuration. Substitute information provided below with your own account information. Check the [Hubtel SMS API Documentation](https://developers.hubtel.com/documentations/sendmessage) for more information.\n\n```js\nconst { SMSMessage, Config } = require(\"hubtel-mx\");\n\nconst secret = {\n    clientId: \"XXXXXXXXX\",\n    clientSecret: \"XXXXXXXXXXXXXXXX\",\n    merchantAccountNumber: \"HMXXXXXXXXX\"\n};\n\nconst config = new Config({\n    clientId: secret.clientId,\n    clientSecret: secret.clientSecret\n});\n\nconst message = new SMSMessage(config);\n\nmessage\n    .sendOne({\n        From: \"smsgh\",\n        To: \"+233248183797\",\n        Content: \"hello, world!\",\n        RegisteredDelivery: \"true\",\n        Time: \"2014-01-01 10:00:00\"\n    })\n    .then(responseJSON => {\n        console.log(responseJSON);\n    })\n    .catch(err => console.log(err));\n\n// Using ES6 async and await\n(async () => {\n    try {\n        // using GET request\n        const response = await message.get({\n            From: \"smsgh\",\n            To: \"+233248183797\",\n            Content: \"hello, world!\",\n            RegisteredDelivery: \"true\",\n            Time: \"2014-01-01 10:00:00\"\n        });\n\n        console.log(response);\n    } catch (error) {\n        console.error(error);\n    }\n})();\n```\n\n### Note (SMS Messaging API)\nOther functions are available for sending SMS messaging. See the SMS messaging documentation for other parameters they accept.  List include:\n\n* `sendOne(messageInfomation) {}`: Sends a single message\n* `schedule(messageInfomation) {}`: Schedule message to be sent later at time provided as `Time` argument.\n\n> The URL used in API configuration can be overridden by setting `apiBaseURL` parameter of `Config()` class during instantiation.\n\n> ```js\n> const config = new Config({\n>       apiBaseURL: \"https://api.hubtel.com/v1/messages/{MESSAGE_ID}\",\n>       clientId: secret.clientId,\n>       clientSecret: secret.clientSecret\n> });\n```\n\n* `reschedule(messageInfomation) {}`: Reschedule messages to be sent later at time provided as `Time` argument. Configuration URL must be in the format `https://api.hubtel.com/v1/messages/{messageId}` .\n* `cancelSchedule() {}`: Cancels a scheduled message that has not already been sent using the message ID provided as argument to the configuration  Configuration URL must be in the format `https://api.smsgh.com/v3/messages/{messageId}` .\n* `get(messageInfomation) {}`: Send message using GET request. Parameters are transformed to encoded URL query parameters.\n* ` query() {}`:  Query messages that have been sent or received on your account.\n\n\n## Todo\n* Create schema for send and receive payment data with in-built validation\n* Improve code test coverage\n    - `send()` and `receive()`\n    - API call responses\n* Improve API documentation\n\n\n## Hacking\nYou are welcomed to submit pull request on the code and documentation or make suggestions on the APIs.\n","readmeFilename":"README.md"}