├── .babelrc ├── .eslintrc.js ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── constants └── endpoints.js ├── flow-typed └── npm │ └── axios_v0.19.x.js ├── index.js ├── package.json ├── prettierrc.js ├── types └── index.js ├── utils └── error.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-flow"], 3 | "plugins": [ 4 | "@babel/plugin-proposal-export-default-from", 5 | "@babel/plugin-proposal-export-namespace-from", 6 | "@babel/plugin-transform-runtime", 7 | "@babel/plugin-proposal-optional-chaining" 8 | ], 9 | "sourceMaps": true, 10 | "retainLines": true 11 | } 12 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'airbnb-base', 4 | ], 5 | plugins: [ 6 | 'import', 7 | ], 8 | env: { 9 | node: true, 10 | jest: true, 11 | }, 12 | parser: 'babel-eslint', 13 | rules: { 14 | strict: 0, 15 | 'max-len': 120, 16 | 'import/prefer-default-export': 0, 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | 3 | [include] 4 | 5 | [libs] 6 | 7 | [lints] 8 | 9 | [options] 10 | 11 | [strict] 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | lib.js -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Zebedee, Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED 2 | 3 | # THIS SDK HAS BEEN DEPRECATED IN FAVOR OF `@zbd/node` NODEJS LIBRARY FOR ZEBEDEE API 4 | 5 | # [@zbd/node](https://github.com/zebedeeio/zbd-node) 6 | 7 | ------------------------------- 8 | 9 | 10 | # ZEBEDEE NodeJS SDK 11 | 12 | [![npm version](https://badge.fury.io/js/zebedee-nodejs.svg)](https://badge.fury.io/js/zebedee-nodejs) 13 | 14 | ZEBEDEE NodeJS SDK to integrate Bitcoin Lightning microtransactions into your game server or application server with ease. 15 | 16 | ## Documentation 17 | 18 | For detailed information about the endpoints available in the ZEBEDEE platform please refer to our [Documentation Website](https://documentation.zebedee.io) or the [RESTful API Reference Website](https://beta-docs.zebedee.io). 19 | 20 | ## Installation 21 | 22 | `zebedee-nodejs` is a JavaScript library that facilitates the interaction with the ZEBEDEE API in NodeJS projects. 23 | 24 | To install it run: 25 | 26 | ``` 27 | npm install zebedee-nodejs --save 28 | ``` 29 | or 30 | ``` 31 | yarn add zebedee-nodejs 32 | ``` 33 | 34 | That is all! You are now ready to hit the ground running adding Bitcoin Lightning microtransactions in your game or application server. Follow the examples below to get started. You will find detailed snippets of the many methods available to you through the NodeJS SDK. 35 | 36 | ## API Initialization 37 | 38 | ```js 39 | // Import the `initAPI` method 40 | import { initAPI } from 'zebedee-node'; 41 | 42 | // Configure the API (API Keys available at the ZEBEDEE Developers Dashboard) 43 | const apiOptions = { apiKey: 'XXXXXX' }; 44 | 45 | // Instantiate the API 46 | initAPI(apiOptions); 47 | ``` 48 | 49 | ### Initialize API Params 50 | 51 | |Parameter|Type|Required|Default|Description 52 | |-|-|-|-|- 53 | |apiKey|*string*|Yes||The key provided to you to instantiate the api 54 | 55 | ---- 56 | 57 | ## Get Wallet Details 58 | 59 | Retrieves wallet information including total balance. 60 | 61 | ```js 62 | // Import the `getWalletDetails` method 63 | import { getWalletDetails } from 'zebedee-nodejs'; 64 | 65 | // Get Wallet Details 66 | try { 67 | const response = await getWalletDetails(); 68 | 69 | // Response Example 70 | // { 71 | // "unit": "msats", 72 | // "balance": "1000000" 73 | // } 74 | } catch(error) { 75 | console.log({ error }); 76 | } 77 | ``` 78 | ---- 79 | 80 | ## Get All Charges 81 | 82 | Retrieves all Charges created by this Key. 83 | 84 | ```js 85 | // Import the `getAllCharges` method 86 | import { getAllCharges } from 'zebedee-nodejs'; 87 | 88 | // Get All Charges 89 | try { 90 | const response = await getAllCharges(); 91 | 92 | // Response Example 93 | // [ 94 | // { 95 | // "id": "c121356b-9671-4fbd-a751-987fb4b3d0b3", 96 | // "description": "Description of the Charge", 97 | // "createdAt": "2019-12-23T03:58:17.993Z", 98 | // "callbackUrl": "http://localhost/callback", 99 | // "internalId": "3451818", 100 | // "amount": "2000", 101 | // "status": "pending", 102 | // "invoice": { 103 | // "expiresAt": "2019-12-23T04:08:18.038Z", 104 | // "request": "lnbc20n1p0qqw66pp5lhjn2sshvh03h2lsxyzg5eyfwt0760207q3hake25fs7l3psegtqdpgg3jhxcmjd9c8g6t0dcsx7e3qw35x2gzrdpshyem9cqzpgxqzjcfppjramjf8sxnvy3k8dq84kv56dy5gq9mlqs9qy9qsqsp5jvf69w282jdxkyt824dn0crxdentx8nvncfdt0ulqp75lvkjpagqqwpgcttpmfzaxc3akfn85jlu8cmtv5l2hu8q3yqttru8vlryg3vnewssy8w00yyfsghzqj03j45kj3uhhjek6q6e8djfu5u4gna6wjcqdsdhwe", 105 | // "uri": "lightning:lnbc20n1p0qqw66pp5lhjn2sshvh03h2lsxyzg5eyfwt0760207q3hake25fs7l3psegtqdpgg3jhxcmjd9c8g6t0dcsx7e3qw35x2gzrdpshyem9cqzpgxqzjcfppjramjf8sxnvy3k8dq84kv56dy5gq9mlqs9qy9qsqsp5jvf69w282jdxkyt824dn0crxdentx8nvncfdt0ulqp75lvkjpagqqwpgcttpmfzaxc3akfn85jlu8cmtv5l2hu8q3yqttru8vlryg3vnewssy8w00yyfsghzqj03j45kj3uhhjek6q6e8djfu5u4gna6wjcqdsdhwe" 106 | // } 107 | // }, 108 | // { 109 | // "id": "562dc6c2-ccf9-4e54-b680-7e7c49874736", 110 | // "description": "Description of the Charge", 111 | // "createdAt": "2019-12-23T04:13:50.578Z", 112 | // "callbackUrl": "http://localhost/callback", 113 | // "internalId": "3451818", 114 | // "amount": "6000", 115 | // "status": "completed", 116 | // "invoice": { 117 | // "expiresAt": "2019-12-23T04:23:50.724Z", 118 | // "request": "lnbc60n1p0qq0h7pp5zrql5vkpn6507qffyt370eacp2pkedgx705h23yhsh0m0tkjyh2sdpgg3jhxcmjd9c8g6t0dcsx7e3qw35x2gzrdpshyem9cqzpgxqzjcfppjlq5hes6q5vvk904hku52e0a08hks64q89qy9qsqsp5ecnz3zm7ls3zkud3ppg3jg7l8h0ktesn4ru4mv6thrfke5fekcnqehgjsl8yqmumwj9f34dt82cad9tyww9xashl7c7r638tvv3pe8sspjkc5fqc8uyhadyh5gwj5az0xslhlhrd2q6gw9m9vvt6p9pfudqprdy7ks", 119 | // "uri": "lightning:lnbc60n1p0qq0h7pp5zrql5vkpn6507qffyt370eacp2pkedgx705h23yhsh0m0tkjyh2sdpgg3jhxcmjd9c8g6t0dcsx7e3qw35x2gzrdpshyem9cqzpgxqzjcfppjlq5hes6q5vvk904hku52e0a08hks64q89qy9qsqsp5ecnz3zm7ls3zkud3ppg3jg7l8h0ktesn4ru4mv6thrfke5fekcnqehgjsl8yqmumwj9f34dt82cad9tyww9xashl7c7r638tvv3pe8sspjkc5fqc8uyhadyh5gwj5az0xslhlhrd2q6gw9m9vvt6p9pfudqprdy7ks" 120 | // } 121 | // }, 122 | // { ... }, 123 | // { ... }, 124 | // { ... }, 125 | // { ... } 126 | // ] 127 | } catch(error) { 128 | console.log({ error }); 129 | } 130 | ``` 131 | ---- 132 | ## Creating Charge 133 | 134 | Creates a new Charge with a Lightning Invoice attached to it. 135 | 136 | ```js 137 | // Import the `createCharge` method 138 | import { createCharge } from 'zebedee-nodejs'; 139 | 140 | // Set the payload 141 | const payload = { 142 | expiresIn: 300, 143 | amount: "50000", 144 | description: 'My Custom Charge Description', 145 | callbackUrl: 'https://yourapp.com/callback', 146 | internalId: '11af01d092444a317cb33faa6b8304b8', 147 | }; 148 | 149 | // Create Charge 150 | try { 151 | const response = await createCharge(payload); 152 | 153 | // Response Example 154 | // 155 | // { 156 | // "id": "c8be70f8-6722-4bac-bfaa-504a24ac7082", 157 | // "unit": "msats", 158 | // "amount": "10000", 159 | // "createdAt": "2020-02-19T01:45:49.110Z", 160 | // "internalId": "11af01d092444a317cb33faa6b8304b8", 161 | // "callbackUrl": "http://your-website.com/callback", 162 | // "description": "My Custom Charge Description", 163 | // "status": "pending", 164 | // "invoice": { 165 | // "request": "lnbc100n1p0yey6dpp5fnutjajv9jjv78vpad370rrqzxufqxk3fk2r3m6mk5fxpapq0v8qdpdf4ujqsm4wd6x7mfqgd5xzun8v5sygetnvdexjur5d9hkucqzpgxqzfvsp5rr6v38qxwqu0tnsh5aaqg6kf5k4w8k68n5cpxklr8trdawpytfcs9qy9qsqkxpafcvqgkjvtka0jplgfzumgl7csc7q455au09ucm3q948dey5nvysnpj3vqnvnnqvpz0l2jehlxpzq9d0mqd2vr7x60xd7dpmddkspke8a9c", 166 | // "expiresAt": "2020-02-19T01:50:49.059Z" 167 | // "uri": "lightning:lnbc100n1p0yey6dpp5fnutjajv9jjv78vpad370rrqzxufqxk3fk2r3m6mk5fxpapq0v8qdpdf4ujqsm4wd6x7mfqgd5xzun8v5sygetnvdexjur5d9hkucqzpgxqzfvsp5rr6v38qxwqu0tnsh5aaqg6kf5k4w8k68n5cpxklr8trdawpytfcs9qy9qsqkxpafcvqgkjvtka0jplgfzumgl7csc7q455au09ucm3q948dey5nvysnpj3vqnvnnqvpz0l2jehlxpzq9d0mqd2vr7x60xd7dpmddkspke8a9c" 168 | // } 169 | // } 170 | 171 | } catch(error) { 172 | console.log({ error }); 173 | } 174 | ``` 175 | ### Create Charge Params 176 | 177 | |Attribute|Type|Required|Default|Description 178 | |-|-|-|-|- 179 | |expiresIn|*number*|No|300|The desired expiration time for this Charge (in seconds). 180 | |amount|*string*|Yes||The Charge amount (in millisatoshis). 181 | |description|*string*|No|ZEBEDEE Charge|The Charge description (also applied as the description to the associated BOLT11 Lightning invoice). 182 | |callbackUrl|*string*|No|`null`|The URL ZEBEDEE services will make a POST HTTP request to with information about the Charges's status updates. 183 | |internalId|*string*|No|`null`|An optional free-use attribute. Usually used by setting the Player/User ID of your Game/Application in order to link specific Charges to specific Players. 184 | 185 | ---- 186 | ## Get Charge Details 187 | 188 | Retrieves all the information related to a specific Charge. 189 | 190 | ```js 191 | // Import the `getChargeDetails` method 192 | import { getChargeDetails } from 'zebedee-nodejs'; 193 | 194 | // Get Charge ID 195 | const chargeId = 'c8be70f8-6722-4bac-bfaa-504a24ac7082'; 196 | 197 | // Get Charge Details 198 | try { 199 | const response = await getChargeDetails(chargeId); 200 | 201 | // Response Example 202 | // 203 | // { 204 | // "id": "c8be70f8-6722-4bac-bfaa-504a24ac7082", 205 | // "unit": "msats", 206 | // "amount": "10000", 207 | // "createdAt": "2020-02-19T01:45:49.110Z", 208 | // "internalId": "11af01d092444a317cb33faa6b8304b8", 209 | // "callbackUrl": "http://your-website.com/callback", 210 | // "description": "My Custom Charge Description", 211 | // "status": "pending", 212 | // "invoice": { 213 | // "request": "lnbc100n1p0yey6dpp5fnutjajv9jjv78vpad370rrqzxufqxk3fk2r3m6mk5fxpapq0v8qdpdf4ujqsm4wd6x7mfqgd5xzun8v5sygetnvdexjur5d9hkucqzpgxqzfvsp5rr6v38qxwqu0tnsh5aaqg6kf5k4w8k68n5cpxklr8trdawpytfcs9qy9qsqkxpafcvqgkjvtka0jplgfzumgl7csc7q455au09ucm3q948dey5nvysnpj3vqnvnnqvpz0l2jehlxpzq9d0mqd2vr7x60xd7dpmddkspke8a9c", 214 | // "expiresAt": "2020-02-19T01:50:49.059Z", 215 | // "uri": "lightning:lnbc100n1p0yey6dpp5fnutjajv9jjv78vpad370rrqzxufqxk3fk2r3m6mk5fxpapq0v8qdpdf4ujqsm4wd6x7mfqgd5xzun8v5sygetnvdexjur5d9hkucqzpgxqzfvsp5rr6v38qxwqu0tnsh5aaqg6kf5k4w8k68n5cpxklr8trdawpytfcs9qy9qsqkxpafcvqgkjvtka0jplgfzumgl7csc7q455au09ucm3q948dey5nvysnpj3vqnvnnqvpz0l2jehlxpzq9d0mqd2vr7x60xd7dpmddkspke8a9c" 216 | // } 217 | // } 218 | 219 | } catch(error) { 220 | console.log({ error }); 221 | } 222 | ``` 223 | ### Get Charge Params 224 | 225 | |Attribute|Type|Required|Default|Description 226 | |-|-|-|-|- 227 | |chargeId|*string*|YES||The ID for the Charge. 228 | 229 | ---- 230 | ## Get All Withdrawal Requests 231 | 232 | Retrieves all Withdrawal Requests 233 | 234 | ```js 235 | // Import the `getAllWithdrawalRequests` method 236 | import { getAllWithdrawalRequests } from 'zebedee-nodejs'; 237 | 238 | // Get All Withdrawal Requests 239 | try { 240 | const response = await getAllWithdrawalRequests(); 241 | 242 | // Response Example 243 | // [ 244 | // { 245 | // "id": "80d65490-ebf6-46ae-8371-d85b1ee74dc2", 246 | // "amount": "1000", 247 | // "status": "pending", 248 | // "internalId": "1234567890", 249 | // "description": "My Description", 250 | // "callbackUrl": "https://localhost/callback", 251 | // "createdAt": "2019-12-23T03:58:17.993Z", 252 | // "invoice": { 253 | // "request": "lnurl1dp68gup69uhkkmmwvukhzcfw0fjkyetyv4jjucmvda6kgw3cxqcrqtmkxqhhw6t5dpj8ycthv9kz6un9w96k2um5wvkhqcted3hkzeplwdjkxun9ws7nwc34vsenwvf5xymnqvpjxf3nxcnrx33nzc3cx5cnzdmyvcenydesv56kyerxxv6kgcenv4skyvnyx5ckzepjvgurgcmxv56rjep5vs30e289", 254 | // "expiresAt": "2019-12-23T04:08:18.038Z", 255 | // "uri": "lightning:lnurl1dp68gup69uhkkmmwvukhzcfw0fjkyetyv4jjucmvda6kgw3cxqcrqtmkxqhhw6t5dpj8ycthv9kz6un9w96k2um5wvkhqcted3hkzeplwdjkxun9ws7nwc34vsenwvf5xymnqvpjxf3nxcnrx33nzc3cx5cnzdmyvcenydesv56kyerxxv6kgcenv4skyvnyx5ckzepjvgurgcmxv56rjep5vs30e289" 256 | // } 257 | // }, 258 | // { 259 | // "id": "80d65490-ebf6-46ae-8371-d85b1ee74dc2", 260 | // "amount": "1000", 261 | // "status": "pending", 262 | // "internalId": "1234567890", 263 | // "description": "My Description", 264 | // "callbackUrl": "https://localhost/callback", 265 | // "createdAt": "2019-12-23T03:58:17.993Z", 266 | // "invoice": { 267 | // "request": "lnurl1dp68gup69uhkkmmwvukhzcfw0fjkyetyv4jjucmvda6kgw3cxqcrqtmkxqhhw6t5dpj8ycthv9kz6un9w96k2um5wvkhqcted3hkzeplwdjkxun9ws7nwc34vsenwvf5xymnqvpjxf3nxcnrx33nzc3cx5cnzdmyvcenydesv56kyerxxv6kgcenv4skyvnyx5ckzepjvgurgcmxv56rjep5vs30e289", 268 | // "expiresAt": "2019-12-23T04:08:18.038Z", 269 | // "uri": "lightning:lnurl1dp68gup69uhkkmmwvukhzcfw0fjkyetyv4jjucmvda6kgw3cxqcrqtmkxqhhw6t5dpj8ycthv9kz6un9w96k2um5wvkhqcted3hkzeplwdjkxun9ws7nwc34vsenwvf5xymnqvpjxf3nxcnrx33nzc3cx5cnzdmyvcenydesv56kyerxxv6kgcenv4skyvnyx5ckzepjvgurgcmxv56rjep5vs30e289" 270 | // } 271 | // }, 272 | // { ... }, 273 | // { ... }, 274 | // ] 275 | } catch(error) { 276 | console.log({ error }); 277 | } 278 | ``` 279 | ---- 280 | ## Creating Withdrawal Request 281 | 282 | Creates a Withdrawal Request with an attached LNURL code. 283 | 284 | ```js 285 | // Import the `createWithdrawalRequest` method 286 | import { createWithdrawalRequest } from 'zebedee-nodejs'; 287 | 288 | // Set the payload 289 | const payload = { 290 | expiresIn: 300, 291 | amount: "50000", 292 | description: 'My Custom Withdrawal Description', 293 | callbackUrl: 'https://yourapp.com/callback', 294 | internalId: '11af01d092444a317cb33faa6b8304b8', 295 | }; 296 | 297 | // Create Withdrawal Request 298 | try { 299 | const response = await createWithdrawalRequest(payload); 300 | 301 | // Example Response 302 | // 303 | // { 304 | // "id": "547c8a36-44d8-40de-80a1-9ad745354a45", 305 | // "unit": "msats", 306 | // "amount": "50000", 307 | // "createdAt": "2020-02-19T01:43:57.485Z", 308 | // "internalId": "11af01d092444a317cb33faa6b8304b8", 309 | // "description": "My Custom Withdrawal Description", 310 | // "callbackUrl": "http://your-website.com/callback", 311 | // "status": "pending", 312 | // "invoice": { 313 | // "request": "lnurl1dp68gurn8ghj7cn9w3sj6ctsdyh85etzv4jx2efwd9hj7a3s9acxz7tvdaskgtthd96xserjv9mkzmpdwfjhzat9wd6r7um9vdex2apav3skxdfev93rwvm9x43nwcf5vvekgdmpxq6rgvrrxumnxdp3vserqe35v4jr2efs8y6k2epkxf3rxc35vg6nwdrpx9jrqv3kxfjxxwqxmuhcd", 314 | // "expiresAt": "2020-02-19T01:48:57.482Z" 315 | // "uri": "lightning:lnurl1dp68gurn8ghj7cn9w3sj6ctsdyh85etzv4jx2efwd9hj7a3s9acxz7tvdaskgtthd96xserjv9mkzmpdwfjhzat9wd6r7um9vdex2apav3skxdfev93rwvm9x43nwcf5vvekgdmpxq6rgvrrxumnxdp3vserqe35v4jr2efs8y6k2epkxf3rxc35vg6nwdrpx9jrqv3kxfjxxwqxmuhcd", 316 | // } 317 | // } 318 | } catch(error) { 319 | console.log({ error }); 320 | } 321 | ``` 322 | 323 | 324 | ### Create Withdraw Request Params 325 | 326 | |Attribute|Type|Required|Default|Description 327 | |-|-|-|-|- 328 | |expiresIn|*number*|No|300|The desired expiration time for this Withdrawal Request (in seconds). 329 | |amount|*string*|Yes||The Withdrawal Request amount (in millisatoshis). 330 | |description|*string*|No|ZEBEDEE Withdrawal Request|The Withdrawal Request description (also applied as the description to the associated BOLT11 Lightning invoice). 331 | |callbackUrl|*string*|No|`null`|The URL ZEBEDEE services will make a POST HTTP request to with information about the Withdrawal Request's status updates. 332 | |internalId|*string*|No|`null`|An optional free-use attribute. Usually used by setting the Player/User ID of your Game/Application in order to link specific Withdrawal Requests to specific Players. 333 | 334 | ---- 335 | 336 | ## Get Withdrawal Request Details 337 | 338 | Retrieves information on a specific Withdrawal Request 339 | 340 | ```js 341 | // Import the `getWithdrawalRequestDetails` method 342 | import { getWithdrawalRequestDetails } from 'zebedee-nodejs'; 343 | 344 | const withdrawalRequestId = '80d65490-ebf6-46ae-8371-d85b1ee74dc2'; 345 | 346 | // Get Withdrawal Request Details 347 | try { 348 | const response = await getWithdrawalRequestDetails(withdrawalRequestId); 349 | 350 | // Response Example 351 | // { 352 | // "id": "80d65490-ebf6-46ae-8371-d85b1ee74dc2", 353 | // "amount": "1000", 354 | // "status": "pending", 355 | // "internalId": "1234567890", 356 | // "description": "My Description", 357 | // "callbackUrl": "https://localhost/callback", 358 | // "createdAt": "2019-12-23T03:58:17.993Z", 359 | // "invoice": { 360 | // "request": "lnurl1dp68gup69uhkkmmwvukhzcfw0fjkyetyv4jjucmvda6kgw3cxqcrqtmkxqhhw6t5dpj8ycthv9kz6un9w96k2um5wvkhqcted3hkzeplwdjkxun9ws7nwc34vsenwvf5xymnqvpjxf3nxcnrx33nzc3cx5cnzdmyvcenydesv56kyerxxv6kgcenv4skyvnyx5ckzepjvgurgcmxv56rjep5vs30e289", 361 | // "expiresAt": "2019-12-23T04:08:18.038Z", 362 | // "uri": "lightning:lnurl1dp68gup69uhkkmmwvukhzcfw0fjkyetyv4jjucmvda6kgw3cxqcrqtmkxqhhw6t5dpj8ycthv9kz6un9w96k2um5wvkhqcted3hkzeplwdjkxun9ws7nwc34vsenwvf5xymnqvpjxf3nxcnrx33nzc3cx5cnzdmyvcenydesv56kyerxxv6kgcenv4skyvnyx5ckzepjvgurgcmxv56rjep5vs30e289" 363 | // } 364 | // } 365 | } catch (error) { 366 | console.log({ error }); 367 | } 368 | ``` 369 | 370 | ### Get Withdraw Request Details Params 371 | 372 | |Attribute|Type|Required|Default|Description 373 | |-|-|-|-|- 374 | |withdrawalRequestId|*string*|Yes||The ID of the Withdrawal Request. 375 | 376 | ---- 377 | 378 | ## Get All Payments 379 | 380 | Retrieves all Payments created by this Key. 381 | 382 | ```js 383 | // Import the `getAllPayments` method 384 | import { getAllPayments } from 'zebedee-nodejs'; 385 | 386 | // Get All Payments 387 | try { 388 | const response = await getAllPayments(); 389 | 390 | // Response Example 391 | // [ 392 | // { 393 | // "id": "a15a3fbc-a9dc-493a-8497-1e428cf9c1ba", 394 | // "fee": "1000", 395 | // "amount": "1000", 396 | // "description": "My Payment Description", 397 | // "updatedAt": "2020-01-01T20:27:29.896Z", 398 | // "processedAt": "2020-01-01T20:27:29.896Z" 399 | // }, 400 | // { 401 | // "id": "d3fw3fbc-c2dc-393a-8s37-f28s8cf9c15b", 402 | // "fee": "1000", 403 | // "amount": "20001", 404 | // "description": "My Payment Description2", 405 | // "updatedAt": "2020-01-01T20:27:29.896Z", 406 | // "processedAt": "2020-01-01T20:27:29.896Z" 407 | // }, 408 | // { ... }, 409 | // { ... }, 410 | // ] 411 | } catch(error) { 412 | console.log({ error }); 413 | } 414 | ``` 415 | 416 | ---- 417 | 418 | ## Making a Payment 419 | 420 | Pays a Lightning Invoice. 421 | 422 | ```js 423 | // Import the `makePayment` method 424 | import { makePayment } from 'zebedee-nodejs'; 425 | 426 | // Set the payload 427 | const payload = { 428 | invoice: 'lnbc10.....', 429 | description: 'My New Description', 430 | internalId: '11af01d092444a317cb33faa6b8304b8', 431 | callbackUrl: 'https://myapp.com/callback', 432 | }; 433 | 434 | // Pay Invoice 435 | try { 436 | const response = await makePayment(payload); 437 | console.log({ response }); 438 | 439 | // Example Response 440 | // 441 | // { 442 | // "id": "2a0dc354-573f-4850-85f7-ab4a21e5143b", 443 | // "fee": "1000", 444 | // "unit": "msats", 445 | // "amount": "45000", 446 | // "invoice": "lnbc450n1p0yeytspp55yrs0j42wnkw0qutr8e0tgsf2yplxs9986t5gqmfpn7mfd0ckc8sdzq2pshjmt9de6zqen0wgsrgdfqwp5hsetvwvsxzapqwdshgmmndp5hxtnsd3skxefwxqzjccqp2sp5pyccqt6apxelz62d2ndrt0ssahndpcua4wklea80glaczx80t3wqrzjqfn4cln8jwe4dh4dmscddrmd6sdw6hzkn702l6ghwvr8lhad0ez5vzt8vyqqf2sqqqqqqqlgqqqqqqgq9q9qy9qsqqeft09gryr80aaghm7rmh7eeqfl7hxlcynp99730yk7qh534d9nyfwp0nc628rp8hpgp23fxzj5l2aet4y6sc4t79uj3wyjxffejmvgqrmxkvr", 447 | // "internalId": "11af01d092444a317cb33faa6b8304b8", 448 | // "processedAt": "2020-02-19T01:38:10.757Z", 449 | // "description": "My Custom Payment Description", 450 | // "status": "completed" 451 | // } 452 | } catch(error) { 453 | console.log({ error }); 454 | } 455 | ``` 456 | 457 | ### Make Payment Params 458 | 459 | |Attribute|Type|Required|Default|Description 460 | |-|-|-|-|- 461 | |invoice|*string*|Yes||The Lightning invoice that is meant to be paid. 462 | |description|*string*|No|"ZEBEDEE PAYMENT"|The Payment description (only used for internal record-keeping). 463 | |callbackUrl|*string*|No|`null`|The URL ZEBEDEE services will make a POST HTTP request to with information about the Payment's status updates. 464 | |internalId|*string*|No|`null`|An optional free-use attribute. Usually used by setting the Player/User ID of your Game/Application in order to link specific Payments to specific Players. 465 | 466 | ---- 467 | 468 | ## Get Payment Details 469 | 470 | Retrieves all the information related to a specific Payment. 471 | 472 | ```js 473 | // Import the `getPaymentDetails` method 474 | import { getPaymentDetails } from 'zebedee-nodejs'; 475 | 476 | const paymentId = 'a15a3fbc-a9dc-493a-8497-1e428cf9c1ba'; 477 | 478 | // Get Withdrawal Request Details 479 | try { 480 | const response = await getPaymentDetails(paymentId); 481 | 482 | // Response Example 483 | // { 484 | // "id": "a15a3fbc-a9dc-493a-8497-1e428cf9c1ba", 485 | // "fee": "1000", 486 | // "amount": "1000", 487 | // "description": "My Payment Description", 488 | // "updatedAt": "2020-01-01T20:27:29.896Z", 489 | // "processedAt": "2020-01-01T20:27:29.896Z" 490 | // } 491 | } catch (error) { 492 | console.log({ error }); 493 | } 494 | ``` 495 | 496 | ### Get Payment Details Params 497 | 498 | |Attribute|Type|Required|Default|Description 499 | |-|-|-|-|- 500 | |paymentId|*string*|Yes||The ID of the Payment. 501 | 502 | ---- 503 | 504 | ## Webhooks 505 | 506 | Use the `callbackUrl` properties in the `Charge` and `WithdrawalRequest` payloads to receive webhook calls. These webhooks are invoked when your Charge/WithdrawalRequest succeeds, fails, or when it eventually expires. 507 | 508 | Webhooks give you more access to these entities' lifecycle. 509 | 510 | ## Contributions 511 | 512 | ZEBEDEE is a big proponent of Open Source Software. We welcome PRs and contributions to the SDK and will try to review issues and PRs as soon as we can. 513 | -------------------------------------------------------------------------------- /constants/endpoints.js: -------------------------------------------------------------------------------- 1 | // BaseUrl 2 | export const API_URL = 'https://beta-api.zebedee.io'; 3 | 4 | // Endpoints 5 | export const WALLET_ENDPOINT = '/v0/wallet'; 6 | export const CHARGES_ENDPOINT = '/v0/charges'; 7 | export const PAYMENTS_ENDPOINT = '/v0/payments'; 8 | export const WITHDRAWAL_REQUESTS_ENDPOINT = '/v0/withdrawal-requests'; 9 | -------------------------------------------------------------------------------- /flow-typed/npm/axios_v0.19.x.js: -------------------------------------------------------------------------------- 1 | // flow-typed signature: fe7f00984c44d69833f19bc39895832f 2 | // flow-typed version: a4cc3d5e98/axios_v0.19.x/flow_>=v0.104.x 3 | 4 | declare module 'axios' { 5 | import type { Agent as HttpAgent } from 'http'; 6 | import type { Agent as HttpsAgent } from 'https'; 7 | 8 | declare type AxiosTransformer = ( 9 | data: T, 10 | headers?: { [key: string]: mixed, ...}, 11 | ) => mixed; 12 | 13 | declare type ProxyConfig = {| 14 | host: string, 15 | port: number, 16 | auth?: {| 17 | username: string, 18 | password: string, 19 | |}, 20 | protocol?: string, 21 | |}; 22 | 23 | declare class Cancel { 24 | constructor(message?: string): Cancel; 25 | message: string; 26 | } 27 | 28 | declare type Canceler = (message?: string) => void; 29 | 30 | declare type CancelTokenSource = {| 31 | token: CancelToken, 32 | cancel: Canceler, 33 | |}; 34 | 35 | declare class CancelToken { 36 | constructor(executor: (cancel: Canceler) => void): void; 37 | static source(): CancelTokenSource; 38 | promise: Promise; 39 | reason?: Cancel; 40 | throwIfRequested(): void; 41 | } 42 | 43 | declare type Method = 44 | | 'get' 45 | | 'GET' 46 | | 'delete' 47 | | 'DELETE' 48 | | 'head' 49 | | 'HEAD' 50 | | 'options' 51 | | 'OPTIONS' 52 | | 'post' 53 | | 'POST' 54 | | 'put' 55 | | 'PUT' 56 | | 'patch' 57 | | 'PATCH'; 58 | 59 | declare type ResponseType = 60 | | 'arraybuffer' 61 | | 'blob' 62 | | 'document' 63 | | 'json' 64 | | 'text' 65 | | 'stream'; 66 | 67 | declare type AxiosAdapter = ( 68 | config: AxiosXHRConfig 69 | ) => Promise>; 70 | 71 | declare type AxiosXHRConfigBase = { 72 | adapter?: AxiosAdapter, 73 | auth?: {| 74 | username: string, 75 | password: string, 76 | |}, 77 | baseURL?: string, 78 | cancelToken?: CancelToken, 79 | headers?: { [key: string]: mixed, ...}, 80 | httpAgent?: HttpAgent, 81 | httpsAgent?: HttpsAgent, 82 | maxContentLength?: number, 83 | maxRedirects?: number, 84 | socketPath?: string | null, 85 | params?: { [key: string]: mixed, ...}, 86 | paramsSerializer?: (params: { [key: string]: mixed, ...}) => string, 87 | onUploadProgress?: (progressEvent: ProgressEvent) => void, 88 | onDownloadProgress?: (progressEvent: ProgressEvent) => void, 89 | proxy?: ProxyConfig | false, 90 | responseType?: ResponseType, 91 | timeout?: number, 92 | transformRequest?: AxiosTransformer | Array>, 93 | transformResponse?: AxiosTransformer | Array>, 94 | validateStatus?: (status: number) => boolean, 95 | withCredentials?: boolean, 96 | xsrfCookieName?: string, 97 | xsrfHeaderName?: string, 98 | ... 99 | }; 100 | 101 | declare type AxiosXHRConfig = { 102 | ...$Exact>, 103 | data?: T, 104 | method?: Method, 105 | url: string, 106 | ... 107 | }; 108 | 109 | declare type AxiosXHRConfigShape = $Shape>; 110 | 111 | declare type AxiosXHR = {| 112 | config: AxiosXHRConfig, 113 | data: R, 114 | headers: ?{[key: string]: mixed, ...}, 115 | status: number, 116 | statusText: string, 117 | request: http$ClientRequest<> | XMLHttpRequest | mixed, 118 | |}; 119 | 120 | declare type AxiosInterceptorIdent = number; 121 | 122 | declare type AxiosRequestInterceptor = {| 123 | use( 124 | onFulfilled: ?( 125 | response: AxiosXHRConfig 126 | ) => Promise> | AxiosXHRConfig, 127 | onRejected: ?(error: mixed) => mixed 128 | ): AxiosInterceptorIdent, 129 | eject(ident: AxiosInterceptorIdent): void, 130 | |}; 131 | 132 | declare type AxiosResponseInterceptor = {| 133 | use( 134 | onFulfilled: ?(response: AxiosXHR) => mixed, 135 | onRejected: ?(error: mixed) => mixed 136 | ): AxiosInterceptorIdent, 137 | eject(ident: AxiosInterceptorIdent): void, 138 | |}; 139 | 140 | declare type AxiosPromise = Promise>; 141 | 142 | declare class Axios { 143 | ( 144 | config: AxiosXHRConfig | string, 145 | config?: AxiosXHRConfigShape 146 | ): AxiosPromise; 147 | constructor(config?: AxiosXHRConfigBase): void; 148 | request( 149 | config: AxiosXHRConfig | string, 150 | config?: AxiosXHRConfigShape 151 | ): AxiosPromise; 152 | delete( 153 | url: string, 154 | config?: AxiosXHRConfigBase 155 | ): AxiosPromise; 156 | get( 157 | url: string, 158 | config?: AxiosXHRConfigBase 159 | ): AxiosPromise; 160 | head( 161 | url: string, 162 | config?: AxiosXHRConfigBase 163 | ): AxiosPromise; 164 | options( 165 | url: string, 166 | config?: AxiosXHRConfigBase 167 | ): AxiosPromise; 168 | post( 169 | url: string, 170 | data?: T, 171 | config?: AxiosXHRConfigBase 172 | ): AxiosPromise; 173 | put( 174 | url: string, 175 | data?: T, 176 | config?: AxiosXHRConfigBase 177 | ): AxiosPromise; 178 | patch( 179 | url: string, 180 | data?: T, 181 | config?: AxiosXHRConfigBase 182 | ): AxiosPromise; 183 | interceptors: {| 184 | request: AxiosRequestInterceptor, 185 | response: AxiosResponseInterceptor, 186 | |}; 187 | defaults: {| 188 | ...$Exact>, 189 | headers: { [key: string]: mixed, ...}, 190 | |}; 191 | getUri(config?: AxiosXHRConfig): string; 192 | } 193 | 194 | declare class AxiosError extends Error { 195 | config: AxiosXHRConfig; 196 | request?: http$ClientRequest<> | XMLHttpRequest; 197 | response?: AxiosXHR; 198 | code?: string; 199 | isAxiosError: boolean; 200 | } 201 | 202 | declare interface AxiosExport extends Axios { 203 | ( 204 | config: AxiosXHRConfig | string, 205 | config?: AxiosXHRConfigShape 206 | ): AxiosPromise; 207 | Axios: typeof Axios; 208 | Cancel: typeof Cancel; 209 | CancelToken: typeof CancelToken; 210 | isCancel(value: mixed): boolean; 211 | create(config?: AxiosXHRConfigBase): Axios; 212 | all: typeof Promise.all; 213 | spread(callback: (...args: T) => R): (array: T) => R; 214 | } 215 | 216 | declare type $AxiosXHRConfigBase = AxiosXHRConfigBase; 217 | 218 | declare type $AxiosXHRConfig = AxiosXHRConfig; 219 | 220 | declare type $AxiosXHR = AxiosXHR; 221 | 222 | declare type $AxiosError = AxiosError; 223 | 224 | declare module.exports: AxiosExport; 225 | } 226 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // @flow 2 | import axios from 'axios'; 3 | import { throwError, throwClientErr } from './utils/error'; 4 | import { 5 | API_URL, 6 | WALLET_ENDPOINT, 7 | CHARGES_ENDPOINT, 8 | PAYMENTS_ENDPOINT, 9 | WITHDRAWAL_REQUESTS_ENDPOINT, 10 | } from './constants/endpoints'; 11 | 12 | import type { 13 | APIConfigurationType, 14 | ErrorResponseType, 15 | ErrorInputType, 16 | ChargeInputType, 17 | ChargeResponseType, 18 | WithdrawalRequestInputType, 19 | WithdrawalRequestResponseType, 20 | PaymentInputType, 21 | PaymentResponseType, 22 | WalletResponseType, 23 | } from './types'; 24 | 25 | // Globals 26 | let zAPI: Object = null; 27 | 28 | /** 29 | * Instantiates an Axios API instance connected to the ZEBEDEE API 30 | * @param {APIConfigurationType} apiConfig API Configuration Options 31 | * @returns {any} Axios API Instance 32 | */ 33 | export const initAPI = ({ apikey }: APIConfigurationType) => { 34 | if(!apikey) { 35 | throw throwClientErr('Missing required param: apiKey'); 36 | } 37 | 38 | // API Base URL 39 | const baseURL = API_URL; 40 | 41 | // Default ZEBEDEE API Headers 42 | const defaultHeaders = { 43 | Accept: 'application/json', 44 | 'Content-Type': 'application/json', 45 | apikey, 46 | }; 47 | 48 | // Axios API Instance 49 | zAPI = axios.create({ 50 | baseURL, 51 | headers: defaultHeaders, 52 | timeout: 10000, 53 | }); 54 | }; 55 | 56 | /** 57 | * Retrieves Wallet Details 58 | * @returns {(Object|ErrorResponseType)} Wallet Information or Error 59 | */ 60 | export const getWalletDetails = async () => { 61 | try { 62 | const response = await zAPI.get(WALLET_ENDPOINT); 63 | const walletDetails: WalletResponseType = response.data.data; 64 | 65 | return walletDetails; 66 | } catch (error) { 67 | throw throwError(error); 68 | } 69 | }; 70 | 71 | /** 72 | * Creates a New Charge 73 | * @param {ChargeInputType} chargeParams Parameters for the Charge 74 | * @returns {(Object|ErrorResponseType)} Charge Information or Error 75 | */ 76 | export const createCharge = async (chargeParams: ChargeInputType) => { 77 | try { 78 | const response = await zAPI.post(CHARGES_ENDPOINT, chargeParams); 79 | const chargeDetails: ChargeResponseType = response.data.data; 80 | 81 | return chargeDetails; 82 | } catch (error) { 83 | throw throwError(error); 84 | } 85 | }; 86 | 87 | /** 88 | * Retrieves All Charges 89 | * @returns {(Object|ErrorResponseType)} List of All Charges or Error 90 | */ 91 | export const getAllCharges = async () => { 92 | try { 93 | const response = await zAPI.get(CHARGES_ENDPOINT); 94 | const allCharges: Array = response.data.data; 95 | 96 | return allCharges; 97 | } catch (error) { 98 | throw throwError(error); 99 | } 100 | }; 101 | 102 | /** 103 | * Retrieves Single Charge Details 104 | * @param {string} chargeId The Charge ID 105 | * @returns {(Object|ErrorResponseType)} Charge Details or Error 106 | */ 107 | export const getChargeDetails = async (chargeId: string) => { 108 | try { 109 | const response = await zAPI.get(`${CHARGES_ENDPOINT}/${chargeId}`); 110 | const chargeDetails: ChargeResponseType = response.data.data; 111 | 112 | return chargeDetails; 113 | } catch (error) { 114 | throw throwError(error); 115 | } 116 | }; 117 | 118 | /** 119 | * Creates a New Withdrawal Request 120 | * @param {WithdrawalRequestInputType} withdrawalRequestParams Parameters for the Withdrawal Request 121 | * @returns {(Object|ErrorResponseType)} Charge Information or Error 122 | */ 123 | export const createWithdrawalRequest = async (withdrawalRequestParams: WithdrawalRequestInputType) => { 124 | try { 125 | const response = await zAPI.post(WITHDRAWAL_REQUESTS_ENDPOINT, withdrawalRequestParams); 126 | const withdrawalRequest: WithdrawalRequestResponseType = response.data.data; 127 | 128 | return withdrawalRequest; 129 | } catch (error) { 130 | throw throwError(error); 131 | } 132 | }; 133 | 134 | /** 135 | * Retrieves All WithdrawalRequests 136 | * @returns {(Object|ErrorResponseType)} List of All Withdrawal Requests or Error 137 | */ 138 | export const getAllWithdrawalRequests = async () => { 139 | try { 140 | const response = await zAPI.get(WITHDRAWAL_REQUESTS_ENDPOINT); 141 | const allWithdrawalRequests: Array = response.data.data; 142 | 143 | return allWithdrawalRequests; 144 | } catch (error) { 145 | throw throwError(error); 146 | } 147 | }; 148 | 149 | /** 150 | * Retrieves Single Withdrawal Request Details 151 | * @param {string} withdrawalRequestId The Withdrawal Request ID 152 | * @returns {(Object|ErrorResponseType)} Withdrawal Request Details or Error 153 | */ 154 | export const getWithdrawalRequestDetails = async (withdrawalRequestId: string) => { 155 | try { 156 | const response = await zAPI.get(`${WITHDRAWAL_REQUESTS_ENDPOINT}/${withdrawalRequestId}`); 157 | const withdrawalRequestDetails: WithdrawalRequestResponseType = response.data.data; 158 | 159 | return withdrawalRequestDetails; 160 | } catch (error) { 161 | throw throwError(error); 162 | } 163 | }; 164 | 165 | /** 166 | * Makes Payment for BOLT11 Invoice 167 | * @param {PaymentInputType} payment - Payment object 168 | * @returns {(Object|ErrorResponseType)} Payment Details or Error 169 | */ 170 | export const makePayment = async (payment: PaymentInputType) => { 171 | try { 172 | const response = await zAPI.post(PAYMENTS_ENDPOINT, payment); 173 | const paymentDetails: PaymentResponseType = response.data.data; 174 | 175 | return paymentDetails; 176 | } catch (error) { 177 | throw throwError(error); 178 | } 179 | }; 180 | 181 | /** 182 | * Retrieves All Payments 183 | * @returns {(Object|ErrorResponseType)} Payments List or Error 184 | */ 185 | export const getAllPayments = async () => { 186 | try { 187 | const response = await zAPI.get(PAYMENTS_ENDPOINT); 188 | const allPayments: Array = response.data.data; 189 | 190 | return allPayments; 191 | } catch (error) { 192 | throw throwError(error); 193 | } 194 | }; 195 | 196 | /** 197 | * Retrieves Single Payment Details 198 | * @param {string} paymentId The Payment ID 199 | * @returns {(Object|ErrorResponseType)} Payment Details or Error 200 | */ 201 | export const getPaymentDetails = async (paymentId: string) => { 202 | try { 203 | const response = await zAPI.get(`${PAYMENTS_ENDPOINT}/${paymentId}`); 204 | const paymentDetails: PaymentResponseType = response.data.data; 205 | 206 | return paymentDetails; 207 | } catch (error) { 208 | throw throwError(error); 209 | } 210 | }; 211 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zebedee-nodejs", 3 | "version": "0.4.1", 4 | "description": "NodeJS SDK for ZEBEDEE Bitcoin Lightning API", 5 | "license": "MIT", 6 | "main": "lib.js", 7 | "author": { 8 | "email": "andre@zebedee.io", 9 | "url": "https://zebedee.io", 10 | "name": "André Neves" 11 | }, 12 | "scripts": { 13 | "flow:precommit": "glow", 14 | "prebuild": "rm -rf lib.js", 15 | "build": "babel index.js --out-file lib.js" 16 | }, 17 | "engines": { 18 | "node": ">=10" 19 | }, 20 | "files": [ 21 | "lib.js" 22 | ], 23 | "pre-commit": [ 24 | "flow:precommit" 25 | ], 26 | "keywords": [ 27 | "lightning-network", 28 | "microtransactions", 29 | "lightning", 30 | "bitcoin", 31 | "zebedee", 32 | "nodejs", 33 | "sdk" 34 | ], 35 | "dependencies": { 36 | "axios": "^0.21.1" 37 | }, 38 | "devDependencies": { 39 | "@babel/cli": "^7.7.0", 40 | "@babel/core": "^7.7.2", 41 | "@babel/node": "^7.0.0", 42 | "@babel/plugin-proposal-export-default-from": "^7.0.0", 43 | "@babel/plugin-proposal-export-namespace-from": "^7.0.0", 44 | "@babel/plugin-proposal-optional-chaining": "^7.6.0", 45 | "@babel/plugin-transform-runtime": "^7.1.0", 46 | "@babel/preset-env": "^7.1.5", 47 | "@babel/preset-flow": "^7.0.0", 48 | "@babel/register": "^7.4.4", 49 | "babel-eslint": "^8.2.2", 50 | "eslint": "^4.19.1", 51 | "eslint-config-airbnb-base": "^13.1.0", 52 | "eslint-plugin-import": "^2.14.0", 53 | "flow-bin": "^0.112.0", 54 | "flow-typed": "^2.6.2", 55 | "glow": "^1.2.2", 56 | "pre-commit": "^1.2.2", 57 | "prettier": "^1.19.1" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | bracketSpacing: true, 3 | jsxBracketSameLine: true, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | semicolons: true, 7 | }; 8 | -------------------------------------------------------------------------------- /types/index.js: -------------------------------------------------------------------------------- 1 | 2 | // Types 3 | export type APIConfigurationType = { 4 | apikey: string, 5 | }; 6 | 7 | export type ErrorResponseType = { 8 | name: string, 9 | status: number, 10 | message: string, 11 | }; 12 | 13 | export type ErrorInputType = { 14 | status: string, 15 | response: Object, 16 | }; 17 | 18 | export type ChargeInputType = { 19 | name: string, 20 | amount: string, 21 | internalId: string, 22 | callbackUrl: string, 23 | description: string, 24 | }; 25 | 26 | export type ChargeResponseType = { 27 | id: string, 28 | name: string, 29 | unit: string, 30 | amount: string, 31 | status: string, 32 | createdAt: string, 33 | internalId: string, 34 | callbackUrl: string, 35 | description: string, 36 | invoice: { 37 | request: string, 38 | expiresAt: string, 39 | }, 40 | }; 41 | 42 | export type WithdrawalRequestInputType = { 43 | name: string, 44 | amount: string, 45 | internalId: string, 46 | callbackUrl: string, 47 | description: string, 48 | } 49 | 50 | export type WithdrawalRequestResponseType = { 51 | id: string, 52 | name: string, 53 | unit: string, 54 | amount: string, 55 | status: string, 56 | createdAt: string, 57 | internalId: string, 58 | callbackUrl: string, 59 | description: string, 60 | invoice: { 61 | request: string, 62 | expiresAt: string, 63 | }, 64 | } 65 | 66 | export type PaymentInputType = { 67 | invoice: string, 68 | internalId: string, 69 | description: string, 70 | } 71 | 72 | export type PaymentResponseType = { 73 | id: string, 74 | fee: string, 75 | unit: string, 76 | status: string, 77 | amount: string, 78 | invoice: string, 79 | internalId: string, 80 | processedAt: string, 81 | description: string, 82 | } 83 | 84 | export type WalletResponseType = { 85 | balance: string, 86 | unit: string, 87 | } -------------------------------------------------------------------------------- /utils/error.js: -------------------------------------------------------------------------------- 1 | import type { ErrorResponseType, ErrorInputType } from './types'; 2 | 3 | /** 4 | * Utility for handling and formatting Errors 5 | * @param {ErrorInputType} error Error 6 | * @returns {ErrorResponseType} Formatted Error 7 | */ 8 | export const throwError = (error: ErrorInputType): ErrorResponseType => { 9 | const errorMessage = error.response.data.errorString; 10 | const errorName = error.response.data.message; 11 | const errorStatus = error.response.status; 12 | 13 | const errorObj: Object = new Error(errorMessage); 14 | 15 | errorObj.name = errorName; 16 | errorObj.status = errorStatus; 17 | errorObj.message = errorMessage; 18 | 19 | return errorObj; 20 | }; 21 | 22 | /** 23 | * Utility for handling client errors 24 | * @param {message} message string 25 | * @returns {Object} Error 26 | */ 27 | export const throwClientErr = (message: string) => new Error(message); 28 | --------------------------------------------------------------------------------