blockbee 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c080ab8111b7508dc3daca4996dd881cf24a1efad69689cd3657bc954932e656
4
+ data.tar.gz: e7887ce185ad0f67b40dd219964238cfabd58ee07ce4c1dd9476ceb4f7f8f65c
5
+ SHA512:
6
+ metadata.gz: ec6e38347c2af3918cbd4f04e52978698ace2c662c8762f4f371ce69684daa1b04795b2dd4225daa182af5bfc1b6e43a6682e73e9a462744f06ddc8e71b17ad1
7
+ data.tar.gz: e300deeb203d4da1c92f9093889ef1e3c8329c9c47f50c7318944932203d07a2b648a2d94232dc2539ed26ed69d689147eb4d09c2ff0d439dd6172f97b9a2ebf
data/.DS_Store ADDED
Binary file
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ ### Features
6
+ - Support for BlockBee API, Payouts and Checkout page
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 BlockBee
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.
data/README.md ADDED
@@ -0,0 +1,601 @@
1
+ [<img src="https://blockbee.io/static/assets/images/blockbee_logo_nospaces.png" width="300"/>](image.png)
2
+
3
+ # BlockBee's Ruby Library
4
+ Ruby implementation of BlockBee's payment gateway
5
+
6
+ ## Table of Contents
7
+ 1. [Requirements](#requirements)
8
+ 2. [Installation](#installation)
9
+ 3. [API and utils](#api-and-utils)
10
+ 4. [Checkout](#checkout)
11
+ 5. [Payouts](#payouts)
12
+ 6. [Help](#help)
13
+
14
+ ## Requirements:
15
+
16
+ ```
17
+ Ruby >= 3
18
+ ```
19
+
20
+ ## Installation
21
+
22
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
23
+
24
+ Install the gem and add to the application's Gemfile by executing:
25
+
26
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
27
+
28
+ If bundler is not being used to manage dependencies, install the gem by executing:
29
+
30
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
31
+
32
+ ## API and utils
33
+
34
+ ### Importing in your project file
35
+
36
+ ```ruby
37
+ require 'blockbee'
38
+ ```
39
+
40
+ ### Get information (service of regarding a cryptocurrency)
41
+
42
+ ```ruby
43
+ require 'blockbee'
44
+
45
+ info = BlockBee::API.get_info(coin, api_key, prices)
46
+
47
+ # or if you wish to get full BlockBee service information
48
+
49
+ info = BlockBee::API.get_info(nil, api_key, prices)
50
+
51
+ ```
52
+
53
+ ### Where
54
+ * ``coin`` is the coin you wish to use, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...).
55
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
56
+ * ``prices`` by default `0`. If `1` will return the prices of the cryptocurrencies converted to all supported FIAT currencies.
57
+
58
+ ### Generating a new Address
59
+
60
+ ```ruby
61
+ require 'blockbee'
62
+
63
+ blockbee_helper = BlockBee::API.new(coin, own_address, callback_url, parameters, bb_params, api_key)
64
+
65
+ address = blockbee_helper.get_address
66
+
67
+ # or address['address_in'] if you just wish the address string
68
+ ```
69
+
70
+ #### Where:
71
+
72
+ * ``coin`` is the coin you wish to use, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...).
73
+ * ``own_address`` is your own crypto address, where your funds will be sent to.
74
+ * ``callback_url`` is the URL that will be called upon payment.
75
+ * ``parameters`` is any parameter you wish to send to identify the payment, such as `{orderId: 1234}`.
76
+ * ``bb_params`` parameters that will be passed to BlockBee _(check which extra parameters are available here: https://docs.blockbee.io/#operation/create).
77
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
78
+
79
+ #### Response sample:
80
+
81
+ ```json
82
+ {
83
+ "status": "success",
84
+ "address_in": "0xe10818d4037B7C427109dFbCFC2c8757c0352FE8",
85
+ "address_out": "0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d",
86
+ "callback_url": "https://webhook.site/ef8e2859-12a9-4028-8a94-51582e83dd05?order_id=13435",
87
+ "minimum_transaction_coin": "1.00000000",
88
+ "priority": "default",
89
+ "multi_token": true
90
+ }
91
+ ```
92
+
93
+ ### Getting notified when the user pays
94
+
95
+ > Once your customer makes a payment, BlockBee will send a callback to your `callbackUrl`. This callback information is by default in ``GET`` but you can se it to ``POST`` by setting ``post => 1`` in ``bb_params``. The parameters sent by BlockBee in this callback can be consulted here: https://docs.blockbee.io/#operation/confirmedcallbackget
96
+
97
+ ### Checking the logs of a request
98
+
99
+ ```ruby
100
+ require 'blockbee'
101
+
102
+ blockbee_helper = BlockBee::API.new(coin, own_address, callback_url, parameters, bb_params, api_key)
103
+
104
+ logs = blockbee_helper.get_logs
105
+ ```
106
+ > Same parameters as before, the ```data``` returned can b e checked here: https://docs.blockbee.io/#operation/logs
107
+
108
+ #### Response sample:
109
+
110
+ ```json
111
+ {
112
+ "status": "success",
113
+ "callback_url": "https://example.com/?order_id=1235",
114
+ "address_in": "0x58e90D31530A5566dA97e34205730323873eb88B",
115
+ "address_out": "0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d",
116
+ "notify_pending": false,
117
+ "notify_confirmations": 1,
118
+ "priority": "default",
119
+ "callbacks": []
120
+ }
121
+ ```
122
+
123
+ ### Generating a QR code
124
+
125
+ ```ruby
126
+ require 'blockbee'
127
+
128
+ blockbee_helper = BlockBee::API.new(coin, own_address, callback_url, parameters, bb_params, api_key)
129
+
130
+ qrcode = blockbee_helper.get_qrcode(value, size)
131
+ ```
132
+
133
+ #### Where:
134
+
135
+ * ``value`` is the value requested to the user in the coin to which the request was done. **Optional**, can be empty if you don't wish to add the value to the QR Code.
136
+ * ``size`` Size of the QR Code image in pixels. Optional, leave empty to use the default size of 512.
137
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
138
+
139
+ > Response is an object with `qr_code` (base64 encoded image data) and `payment_uri` (the value encoded in the QR), see https://docs.blockbee.io/#operation/qrcode for more information.
140
+
141
+ #### Response sample:
142
+ ```json
143
+ {
144
+ "status": "success",
145
+ "qr_code": "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAYeklEQVR4nO3daZQdZZkH8Od5q+quvXenO3tCQtg3WQLDOiwi4FEGRA96RhkRlEUd9cw5Ojif/DTOHEcF4YAwntFRhBEHBPWoKAECGNnXSICQBEL23m/fvkvV+8yHut3pEPoSaop6qjv/3wcOSbrurVv3/vutW8/7vMUiQgCgx2jvAMD+DiEEUIYQAihDCAGUIYQAyhB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L/MmUh9efhkjidGQgBlCCGAMoQQQBlCCKAMIQRQhhACKEMIAZRFaepNs2QaNONtEdZtOFbvqY33oWbiYtYYCQGUIYQAyhBCAGUIIYAyhBBAGUIIoAwhBFCGEAIoa1asn85MbF2Nt1YegXpFOALsWDI3fsZICKAMIQRQhhACKEMIAZQhhADKEEIAZQghgDKEEEBZlGJ9EzEWvhMryMa4Ane8dX/1lQ1wBCKIUN/HSAigDCEEUIYQAihDCAGUIYQAyhBCAGUIIYCymOuEqZXMms2JLbOdTAEt3lJtjPXYeMV7MCPsM0ZCAGUIIYAyhBBAGUIIoAwhBFCGEAIoQwgBlCGEAMr2l2J9vOItIiezzHMyNxKPMMFA/QbX6guNYyQEUIYQAihDCAGUIYQAyhBCAGUIIYAyhBBAGSdT2IlXMh26EUQ7MjGW49K8Wm4yTb3qtU0s/gsw8yCEAMoQQgBlCCGAMoQQQBlCCKAMIQRQhhACKItSrE8z3fKuet05AvVVw5PpkI79iWKEkRBAGUIIoAwhBFCGEAIoQwgBlCGEAMoQQgBlzeqEAJAAjIQAyhBCAGUIIYAyhBBAGUIIoAwhBFCGEAIoQwgBlP0fDDJ0PYOZxyEAAAAASUVORK5CYII=",
146
+ "payment_uri": "0x0E945b1554c8029A6B9bE1F7A24ae75d2F44d8DB"
147
+ }
148
+ ```
149
+
150
+ #### Usage
151
+ ```html.erb
152
+ <img src={"data:image/png;base64,#{qr_code}"}/>
153
+ ```
154
+
155
+ ### Estimating transaction fees
156
+
157
+ ```ruby
158
+ require 'blockbee'
159
+
160
+ estimation = BlockBee::API.get_estimate(coin, addresses, priority, api_key)
161
+ ```
162
+
163
+ #### Where:
164
+ * ``coin`` is the coin you wish to check, from BlockBee's supported currencies (e.g 'btc', 'eth', 'erc20_usdt', ...)
165
+ * ``addresses`` The number of addresses to forward the funds to. Optional, defaults to 1.
166
+ * ``priority`` Confirmation priority, (check [this](https://support.blockbee.io/article/how-the-priority-parameter-works) article to learn more about it). Optional, defaults to ``default``.
167
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
168
+
169
+ > Response is an object with ``estimated_cost`` and ``estimated_cost_usd``, see https://docs.blockbee.io/#operation/estimate for more information.
170
+
171
+ #### Response sample:
172
+
173
+ ```json
174
+ {
175
+ "status": "success",
176
+ "estimated_cost": "0.00637010",
177
+ "estimated_cost_currency": {
178
+ "AED": "0.03",
179
+ "AUD": "0.01",
180
+ "BGN": "0.01",
181
+ "BRL": "0.04"
182
+ }
183
+ }
184
+ ```
185
+
186
+ ### Converting between coins and fiat
187
+
188
+ ```ruby
189
+ require 'blockbee'
190
+
191
+ blockbee_helper = BlockBee::API.new(coin, own_address, callback_url, parameters, bb_params, api_key)
192
+
193
+ conversion = blockbee_helper.get_conversion(from_coin, value)
194
+ ```
195
+
196
+ #### Where:
197
+
198
+ * ``value`` value to convert in `from`.
199
+ * ``from_coin`` currency to convert from, FIAT or crypto.
200
+
201
+ > Response is an object with ``value_coin`` and ``exchange_rate``, see https://docs.blockbee.io/#operation/convert for more information.
202
+
203
+ #### Response sample:
204
+
205
+ ```json
206
+ {
207
+ "status": "success",
208
+ "value_coin": "241.126",
209
+ "exchange_rate": "0.803753"
210
+ }
211
+ ```
212
+
213
+ ### Getting supported coins
214
+
215
+ ```ruby
216
+ require 'blockbee'
217
+
218
+ supported_coins = BlockBee::API.get_supported_coins(api_key)
219
+ ```
220
+
221
+ ### Where:
222
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
223
+
224
+ > Response is an array with all supported coins.
225
+
226
+ #### Response sample:
227
+
228
+ ```json
229
+ {
230
+ "btc": {
231
+ "coin": "Bitcoin",
232
+ "logo": "https://api.cryptapi.io/media/token_logos/btc.png",
233
+ "ticker": "btc",
234
+ "minimum_transaction": 8000,
235
+ "minimum_transaction_coin": "0.00008000",
236
+ "minimum_fee": 546,
237
+ "minimum_fee_coin": "0.00000546",
238
+ "fee_percent": "1.000",
239
+ "network_fee_estimation": "0.00002518"
240
+ },
241
+ "bch": {
242
+ "coin": "Bitcoin Cash",
243
+ "logo": "https://api.cryptapi.io/media/token_logos/bch.png",
244
+ "ticker": "bch",
245
+ "minimum_transaction": 50000,
246
+ "minimum_transaction_coin": "0.00050000",
247
+ "minimum_fee": 546,
248
+ "minimum_fee_coin": "0.00000546",
249
+ "fee_percent": "1.000",
250
+ "network_fee_estimation": "0.00000305"
251
+ }
252
+ }
253
+ ```
254
+
255
+ ## Checkout
256
+
257
+ ### Requesting Payment
258
+
259
+ ```ruby
260
+ require 'blockbee'
261
+
262
+ blockbee_helper = BlockBee::Checkout.new(notify_url: NOTIFY_URL, api_key: API_KEY, parameters: {
263
+ 'order_id': 2022
264
+ }, bb_params: {
265
+ 'post' => 1
266
+ })
267
+
268
+ payment_page = blockbee_helper.payment_request(redirect_url, value)
269
+ ```
270
+
271
+ #### Where:
272
+ * ``api_key`` is the API Key provided by our [Dashboard](https://dash.blockbee.io/).
273
+ * ``parameters`` is any parameter you wish to send to identify the payment, such as `{'order_id': 1234}`.
274
+ * ``bb_params`` parameters that will be passed to BlockBee _(check which extra parameters are available here: https://docs.blockbee.io/#operation/create).
275
+ * ``redirect_url`` URL in your platform, where the user will be redirected to following the payment. Should be able to process the payment using the `success_token`.
276
+ * ``notify_url`` URL in your platform, where the IPN will be sent notifying that a payment was completed. Parameters are available here: https://docs.blockbee.io/#operation/paymentipn.
277
+ * ``value`` amount in currency set in Payment Settings you want to receive from the user.
278
+
279
+ #### Getting notified when the user completes the Payment
280
+ > When receiving payments, you have the option to receive them in either the ``notify_url`` or the ``redirect_url``, but adding the ``redirect_url`` is required (refer to our documentation at https://docs.blockbee.io/#operation/paymentipn).
281
+
282
+ #### Payment samples:
283
+ ```json
284
+ {
285
+ "status": "success",
286
+ "success_token": "G4asA2xwEr0UeY2IZqlZjX3IYrNofmnIAkzHPAoxmpmlYP9ZLTvQUolKN0X27Z0B",
287
+ "payment_url": "https://pay.blockbee.io/payment/OcRrZGsKQFGsoi0asqZkr97WbitMxFMb/",
288
+ "payment_id": "OcRrZGsKQFGsoi0asqZkr97WbitMxFMb"
289
+ }
290
+ ```
291
+
292
+ ### Payment Logs
293
+
294
+ Fetch Payment information and IPN logs.
295
+
296
+ ```ruby
297
+ require 'blockbee'
298
+
299
+ logs = BlockBee::Checkout.payment_logs(token, api_key)
300
+ ```
301
+
302
+ #### Where:
303
+
304
+ * ```token``` is the `payment_id` returned by the payment creation endpoint.
305
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
306
+
307
+ #### Response sample:
308
+
309
+ ```json
310
+ {
311
+ "status": "success",
312
+ "is_paid": false,
313
+ "is_pending": false,
314
+ "is_expired": false,
315
+ "is_partial": false,
316
+ "payment_data": [
317
+ {
318
+ "value": "0.000137",
319
+ "value_paid": "0",
320
+ "value_outstanding": "0.000137",
321
+ "exchange_rate": "0.0000137489",
322
+ "coin": "btc",
323
+ "txid": []
324
+ }
325
+ ],
326
+ "notifications": []
327
+ }
328
+ ```
329
+
330
+ ### Requesting Deposit
331
+ ```ruby
332
+ require 'blockbee'
333
+
334
+ blockbee_helper = BlockBee::Checkout.new(notify_url: NOTIFY_URL, api_key: API_KEY, parameters: {
335
+ 'order_id': 2022
336
+ }, bb_params: {
337
+ 'post' => 1
338
+ })
339
+
340
+ deposit_page = blockbee_helper.deposit_request
341
+ ```
342
+
343
+ #### Where:
344
+ * ``api_key`` is the API Key provided by our [Dashboard](https://dash.blockbee.io/).
345
+ * ``parameters`` is any parameter you wish to send to identify the payment, such as `{'order_id': 1234}`.
346
+ * ``bb_params`` parameters that will be passed to BlockBee (check which extra parameters are available here: https://docs.blockbee.io/#operation/deposit).
347
+ * ``notify_url`` URL in your platform, where the IPN will be sent notifying that a deposit was done. Parameters are available here: https://docs.blockbee.io/#operation/depositipn.
348
+
349
+ #### Response sample:
350
+ ```json
351
+ {
352
+ "status": "success",
353
+ "payment_url": "https://pay.blockbee.io/deposit/jv12du8IWqS96WVDjZK2J285WOBOBycc/",
354
+ "payment_id": "jv12du8IWqS96WVDjZK2J285WOBOBycc"
355
+ }
356
+ ```
357
+
358
+ ### Deposit Logs
359
+
360
+ Fetch Deposit information and IPN logs.
361
+
362
+ ```ruby
363
+ require 'blockbee'
364
+
365
+ logs = BlockBee::Checkout.deposit_logs(token, api_key)
366
+ ```
367
+
368
+ #### Where:
369
+
370
+ * ```token``` is the `payment_id` returned by the deposit creation endpoint.
371
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
372
+
373
+ #### Response sample:
374
+
375
+ ```json
376
+ {
377
+ "status": "success",
378
+ "deposits": [],
379
+ "total_deposited": "0",
380
+ "currency": "USDT",
381
+ "notifications": []
382
+ }
383
+ ```
384
+
385
+ ## Payouts
386
+
387
+ ### Create Payout / Payout Request
388
+
389
+ This function can be used by you to create [Payouts](https://docs.blockbee.io/#tag/Payouts).
390
+
391
+ ```ruby
392
+ require 'blockbee'
393
+
394
+ coin = 'polygon_matic'
395
+
396
+ requests = {
397
+ '0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d' => 0.5,
398
+ '0x18B211A1Ba5880C7d62C250B6441C2400d588589' => 0.1
399
+ }
400
+
401
+ create_payout = BlockBee::API.create_payout(coin, payout_requests, api_key, process)
402
+ ```
403
+
404
+ #### Where:
405
+ * ``coin`` The cryptocurrency you want to request the Payout in (e.g `btc`, `eth`, `erc20_usdt`, ...).
406
+ * ``requests`` Address(es) together with the amount that must be sent.
407
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
408
+ * ``process`` If the Payout Requests will be sent right away. Defaults to `False`. **Note**: if `True` will instantly queue the payouts to be sent to the destination addresses.
409
+
410
+ #### Response sample:
411
+
412
+ If `process` is `false`.
413
+ ```json
414
+ {
415
+ "status": "success",
416
+ "request_ids": [
417
+ 103227,
418
+ 103228
419
+ ]
420
+ }
421
+ ```
422
+
423
+ If `process` is `true`.
424
+ ```json
425
+ {
426
+ "status": "success",
427
+ "queued": true
428
+ }
429
+ ```
430
+
431
+ ### List Payouts / Payout Requests
432
+
433
+ List all Payouts or Payout Requests in your account.
434
+
435
+ **Note:** If `requests` is `True` it will fetch a Payout Requests list.
436
+
437
+ ```ruby
438
+ require 'blockbee'
439
+
440
+ list_payouts = BlockBee::API.list_payouts(coin, status, page, api_key, payout_request)
441
+ ```
442
+
443
+ #### Where:
444
+ * ``coin`` The cryptocurrency you want to request the lists in (e.g `btc`, `eth`, `erc20_usdt`, ...).
445
+ * ``status`` The status of the Payout / Payout Request. Possible statuses are:
446
+ * Payout Request: [`all`, `pending`, `rejected`, `processing`, `done`]
447
+ * Payout: [`created`, `processing`, `done`, `error`]
448
+ * ``page`` This endpoint is paginated and will show only `50` items per page. Defaults to `1`.
449
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
450
+ * ``payout_request`` If `True` will fetch Payout Requests, otherwise will fetch Payouts. Defaults to `False`.
451
+
452
+ #### Response sample:
453
+
454
+ ```json
455
+ {
456
+ "status": "success",
457
+ "payouts": [
458
+ {
459
+ "id": 2460,
460
+ "status": "Done",
461
+ "total_requested": "0.6",
462
+ "total_with_fee": "0.606",
463
+ "total_fiat": "",
464
+ "fee": "0.006",
465
+ "coin": "polygon_matic",
466
+ "timestamp": "13/03/2024 17:48:39"
467
+ }
468
+ ],
469
+ "num_pages": 1
470
+ }
471
+ ```
472
+
473
+ ### Get Payout Wallet
474
+
475
+ Gets your Payout Wallet for the specified `coin`. Can algo get the balance.
476
+
477
+ ```ruby
478
+ require 'blockbee'
479
+
480
+ wallet = BlockBee::API.get_payout_wallet(coin, api_key, balance)
481
+ ```
482
+
483
+ #### Where:
484
+ * ``coin`` The cryptocurrency you want to request the lists in (e.g `btc`, `eth`, `erc20_usdt`, ...).
485
+ * ``api_key`` is the API Key provided by BlockBee's [dashboard](https://dash.blockbee.io/).
486
+ * ``balance`` If `True` will also fetch the balance of the address.
487
+
488
+ #### Response sample:
489
+ ```json
490
+ {
491
+ "address": "0x18B211A1Ba5880C7d62C250B6441C2400d588589",
492
+ "balance": "2.7"
493
+ }
494
+ ```
495
+
496
+ ### Create Payout with Payout Request ID(s)
497
+
498
+ With this function you can create a Payout in the `created` status by simply providing an array with the Payout Requests `ID`.
499
+
500
+ ```ruby
501
+ require 'blockbee'
502
+
503
+ payout_ids = [52211, 52212]
504
+
505
+ payout = BlockBee::API.create_payout_by_ids(api_key, payout_ids)
506
+ ```
507
+
508
+ #### Where:
509
+ * ``payout_ids`` its an array with the Payout Requests `ID`.
510
+
511
+ #### Response sample:
512
+
513
+ ```json
514
+ {
515
+ "status": "success",
516
+ "payout_info": {
517
+ "id": 2461,
518
+ "status": "Created",
519
+ "from": "",
520
+ "requests": {
521
+ "0xA8EbeD50f2e05fB4a25b2DdCdc651A7CA769B5CF": "0.300000000000000000",
522
+ "0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d": "0.200000000000000000"
523
+ },
524
+ "total_requested": "0.5",
525
+ "total_with_fee": "0.505",
526
+ "total_fiat": "",
527
+ "fee": "0.005",
528
+ "coin": "bep20_usdt",
529
+ "txid": "",
530
+ "timestamp": "05/03/2024 15:00:00"
531
+ }
532
+ }
533
+ ```
534
+
535
+ ### Process Payout by ID
536
+
537
+ By default, a Payout when created will be in `created` state. With this function you may finish it using its `ID`.
538
+
539
+ ```ruby
540
+ require 'blockbee'
541
+
542
+ payout = BlockBee::API.process_payout(api_key, payout_ids)
543
+ ```
544
+
545
+ #### Where:
546
+
547
+ * ``payout_ids`` Its the `ID` (or multiple `ID`) of the Payout you wish to fulfill.
548
+
549
+ #### Response sample:
550
+
551
+ ```json
552
+ {
553
+ "status": "success",
554
+ "queued": true
555
+ }
556
+ ```
557
+
558
+ ### Check the Payout status
559
+
560
+ Will return all important information regarding a Payout, specially its status.
561
+
562
+ ```ruby
563
+ require 'blockbee'
564
+
565
+ payout_id = 51621
566
+
567
+ status = BlockBee::API.check_payout_status(api_key, payout_id)
568
+ ```
569
+
570
+ #### Where:
571
+
572
+ * ``payout_id`` Its the `ID` of the Payout you wish to check.
573
+
574
+ #### Response sample:
575
+
576
+ ```json
577
+ {
578
+ "status": "success",
579
+ "payout_info": {
580
+ "id": 2463,
581
+ "status": "Done",
582
+ "from": "0x18B211A1Ba5880C7d62C250B6441C2400d588589",
583
+ "requests": {
584
+ "0xA6B78B56ee062185E405a1DDDD18cE8fcBC4395d": "0.500000000000000000",
585
+ "0x18B211A1Ba5880C7d62C250B6441C2400d588589": "0.100000000000000000"
586
+ },
587
+ "total_requested": "0.6",
588
+ "total_with_fee": "0.606",
589
+ "total_fiat": "",
590
+ "fee": "0.006",
591
+ "coin": "polygon_matic",
592
+ "txid": "0xf9aa1618a7e460f8c68b6a02369b5058282c53a4ee23f967abef0d35203f328c",
593
+ "timestamp": "13/03/2024 18:10:35"
594
+ }
595
+ }
596
+ ```
597
+
598
+ ## Help
599
+
600
+ Need help?
601
+ Contact us @ https://blockbee.io/contacts/
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
data/lib/blockbee.rb ADDED
@@ -0,0 +1,371 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ module BlockBee
8
+ class Error < StandardError; end
9
+
10
+ VERSION = "1.0.0"
11
+
12
+ BLOCKBEE_URL = 'https://api.blockbee.io/'
13
+ BLOCKBEE_HOST = 'api.blockbee.io'
14
+
15
+ class API
16
+ def initialize(coin, own_address = '', callback_url, parameters, bb_params, api_key)
17
+ raise 'API Key Missing' if api_key.nil?
18
+
19
+ raise 'Callback URL Missing' if callback_url.nil?
20
+
21
+ @callback_url = callback_url
22
+ @coin = coin
23
+ @own_address = own_address
24
+ @parameters = parameters || {}
25
+ @bb_params = bb_params || {}
26
+ @api_key = api_key
27
+ @payment_address = ''
28
+
29
+ if parameters
30
+ _cb = URI::parse(callback_url)
31
+
32
+ @callback_url = URI::HTTPS.build(
33
+ host: _cb.host,
34
+ path: _cb.path,
35
+ query: URI.encode_www_form(parameters)
36
+ )
37
+ end
38
+ end
39
+
40
+ def get_address
41
+ return nil if @coin.nil?
42
+
43
+ _params = {
44
+ 'callback' => @callback_url,
45
+ 'apikey' => @api_key
46
+ }.merge(@bb_params)
47
+
48
+ if !@own_address.nil? && !@own_address.empty?
49
+ (_params['address'] = @own_address)
50
+ end
51
+
52
+ _address = BlockBee::process_request_get(@coin, 'create', _params)
53
+
54
+ return nil unless _address
55
+
56
+ @payment_address = _address['address_in']
57
+
58
+ _address
59
+ end
60
+
61
+ def get_logs
62
+ _params = {
63
+ 'callback' => @callback_url,
64
+ 'apikey' => @api_key
65
+ }
66
+
67
+ _logs = BlockBee::process_request_get(@coin, 'logs', _params)
68
+
69
+ return nil unless _logs
70
+
71
+ p _logs
72
+
73
+ _logs
74
+ end
75
+
76
+ def get_qrcode(value = '', size = 300)
77
+ return nil if @coin.nil?
78
+
79
+ address = @payment_address
80
+
81
+ address = get_address['address_in'] if address.empty?
82
+
83
+ _params = {
84
+ 'address' => address,
85
+ 'size' => size,
86
+ 'apikey' => @api_key
87
+ }
88
+
89
+ _params['value'] = value unless value.empty?
90
+
91
+ _qrcode = BlockBee::process_request_get(@coin, 'qrcode', _params)
92
+
93
+ return nil unless _qrcode
94
+
95
+ _qrcode
96
+ end
97
+
98
+ def get_conversion(from_coin, value)
99
+ _params = {
100
+ 'from' => from_coin,
101
+ 'value' => value,
102
+ 'apikey' => @api_key
103
+ }
104
+
105
+ _conversion = BlockBee::process_request_get(@coin, 'convert', _params)
106
+
107
+ return nil unless _conversion
108
+
109
+ _conversion
110
+ end
111
+
112
+ def self.get_info(coin, api_key, prices = 0)
113
+ raise 'API Key Missing' if api_key.nil?
114
+
115
+ _params = {
116
+ 'prices' => prices,
117
+ 'apikey' => api_key
118
+ }
119
+
120
+ _info = BlockBee::process_request_get(coin, 'info', _params)
121
+
122
+ return nil unless _info
123
+
124
+ _info
125
+ end
126
+
127
+ def self.get_supported_coins(api_key)
128
+ raise 'API Key Missing' if api_key.nil?
129
+
130
+ _info = get_info(nil, api_key )
131
+
132
+ _info.delete('fee_tiers')
133
+
134
+ _coins = {}
135
+
136
+ _info.each do |ticker, coin_info|
137
+ if coin_info.key?('coin')
138
+ _coins[ticker] = coin_info['coin']
139
+ else
140
+ coin_info.each do |token, token_info|
141
+ _coins[ticker + '_' + token] = token_info['coin'] + ' (' + ticker.upcase + ')'
142
+ end
143
+ end
144
+ end
145
+
146
+ _coins
147
+ end
148
+
149
+ def self.get_estimate(coin, addresses = 1, priority = 'default', api_key)
150
+ raise 'API Key Missing' if api_key.nil?
151
+
152
+ params = {
153
+ 'addresses' => addresses,
154
+ 'priority' => priority,
155
+ 'apikey' => api_key
156
+ }
157
+
158
+ _estimate = BlockBee::process_request_get(coin, 'estimate', params)
159
+
160
+ return nil unless _estimate
161
+
162
+ _estimate
163
+ end
164
+
165
+ def self.create_payout(coin, payout_requests, api_key, process = false)
166
+ raise 'No requests provided' if payout_requests.nil? || payout_requests.empty?
167
+
168
+ body = { 'outputs' => payout_requests }
169
+
170
+ endpoint = 'payout/request/bulk'
171
+
172
+ endpoint += '/process' if process
173
+
174
+ _payout = BlockBee::process_request_post(coin, endpoint, api_key, body, true)
175
+
176
+ return nil unless _payout['status'] == 'success'
177
+
178
+ _payout
179
+ end
180
+
181
+ def self.list_payouts(coin, status: 'all', page: 1, api_key:, payout_request: false)
182
+ return nil if api_key.nil?
183
+
184
+ _params = {
185
+ 'apikey' => api_key,
186
+ 'status' => status,
187
+ 'page' => page
188
+ }
189
+
190
+ endpoint = 'payout/list'
191
+
192
+ endpoint = 'payout/request/list' if payout_request
193
+
194
+ _payouts = BlockBee::process_request_get(coin, endpoint, _params)
195
+
196
+ return nil unless _payouts['status'] == 'success'
197
+
198
+ _payouts
199
+ end
200
+
201
+ def self.get_payout_wallet(coin, api_key, balance = false)
202
+ wallet = BlockBee::process_request_get(coin, 'payout/address', 'apikey' => api_key)
203
+
204
+ return nil unless wallet['status'] == 'success'
205
+
206
+ output = { 'address' => wallet['address'] }
207
+
208
+ if balance
209
+ wallet_balance = BlockBee::process_request_get(coin, 'payout/balance', 'apikey' => api_key)
210
+
211
+ if wallet_balance['status'] == 'success'
212
+ output['balance'] = wallet_balance['balance']
213
+ end
214
+ end
215
+
216
+ output
217
+ end
218
+
219
+ def self.create_payout_by_ids(api_key, payout_ids)
220
+ raise 'Please provide the Payout Request(s) ID(s)' if payout_ids.nil? || payout_ids.empty?
221
+
222
+ _payout = BlockBee::process_request_post(nil, 'payout/create', api_key, { 'request_ids' => payout_ids.join(',') })
223
+
224
+ return nil unless _payout['status'] == 'success'
225
+
226
+ _payout
227
+ end
228
+
229
+ def self.process_payout(api_key, payout_id)
230
+ return nil if payout_id.nil?
231
+
232
+ _process = BlockBee::process_request_post(nil, 'payout/process', api_key, { 'payout_id' => payout_id })
233
+
234
+ return nil unless _process['status'] == 'success'
235
+
236
+ _process
237
+ end
238
+
239
+ def self.check_payout_status(api_key, payout_id)
240
+ raise 'Please provide the Payout ID' if payout_id.nil? or (payout_id.is_a? String and payout_id.empty?)
241
+
242
+ _status = BlockBee::process_request_post(nil, 'payout/status', api_key, { 'payout_id' => payout_id })
243
+
244
+ return nil unless _status['status'] == 'success'
245
+
246
+ _status
247
+ end
248
+ end
249
+
250
+ class Checkout
251
+ def initialize(parameters: {}, bb_params: {}, notify_url:, api_key:)
252
+ raise 'API Key Missing' if api_key.nil?
253
+
254
+ @parameters = parameters
255
+ @bb_params = bb_params
256
+ @api_key = api_key
257
+ @notify_url = notify_url
258
+
259
+ if @parameters
260
+ _nu = URI::parse(notify_url)
261
+
262
+ @notify_url = URI::HTTPS.build(
263
+ host: _nu.host,
264
+ path: _nu.path,
265
+ query: URI.encode_www_form(parameters)
266
+ )
267
+ end
268
+ end
269
+
270
+ def payment_request(redirect_url, value)
271
+ raise 'Please provide a redirect url' if redirect_url.nil? or redirect_url.empty?
272
+
273
+ raise 'Value must be a integer' unless value.is_a?(Integer)
274
+
275
+ _params = {
276
+ 'redirect_url' => redirect_url,
277
+ 'notify_url' => @notify_url,
278
+ 'value' => value,
279
+ 'apikey' => @api_key
280
+ }.merge(@bb_params)
281
+
282
+ _request = BlockBee::process_request_get(nil, 'checkout/request', _params)
283
+
284
+ return nil unless _request['status'] == 'success'
285
+
286
+ _request
287
+ end
288
+
289
+ def self.payment_logs(token, api_key)
290
+ raise 'API Key required' if api_key.nil? or api_key.empty?
291
+
292
+ raise 'Token required' if token.nil? or token.empty?
293
+
294
+ _params = {
295
+ 'apikey' => api_key,
296
+ 'token' => token
297
+ }
298
+
299
+ _logs = BlockBee::process_request_get(nil, 'checkout/logs', _params)
300
+
301
+ return nil unless _logs['status'] == 'success'
302
+
303
+ _logs
304
+ end
305
+
306
+ def deposit_request()
307
+ _params = {
308
+ 'notify_url' => @notify_url,
309
+ 'apikey' => @api_key
310
+ }.merge(@bb_params)
311
+
312
+ _request = BlockBee::process_request_get(nil, 'deposit/request', _params)
313
+
314
+ return nil unless _request['status'] == 'success'
315
+
316
+ _request
317
+ end
318
+
319
+ def self.deposit_logs(token, api_key)
320
+ raise 'API Key required' if api_key.nil? or api_key.empty?
321
+
322
+ raise 'Token required' if token.nil? or token.empty?
323
+
324
+ _params = {
325
+ 'apikey' => api_key,
326
+ 'token' => token
327
+ }
328
+
329
+ _logs = BlockBee::process_request_get(nil, 'deposit/logs', _params)
330
+
331
+ return nil unless _logs['status'] == 'success'
332
+
333
+ _logs
334
+ end
335
+ end
336
+
337
+ private
338
+
339
+ def self.process_request_get(coin = '', endpoint = '', params = nil)
340
+ coin = coin.nil? ? '' : "#{coin.tr('_', '/')}/"
341
+
342
+ response = Net::HTTP.get(URI.parse("#{BLOCKBEE_URL}#{coin}#{endpoint}/?#{URI.encode_www_form(params)}"))
343
+
344
+ JSON.parse(response)
345
+ end
346
+
347
+ def self.process_request_post(coin = '', endpoint = '', api_key = '', body = nil, is_json = false)
348
+ coin_path = coin.nil? ? '' : "#{coin.tr('_', '/')}/"
349
+
350
+ p coin_path
351
+
352
+ url = "#{BLOCKBEE_URL}#{coin_path}#{endpoint}/?apikey=#{api_key}"
353
+ uri = URI.parse(url)
354
+
355
+ p url
356
+
357
+ req = Net::HTTP::Post.new(uri)
358
+ req['Host'] = BLOCKBEE_HOST
359
+
360
+ if is_json
361
+ req.content_type = 'application/json'
362
+ req.body = body.to_json
363
+ else
364
+ req.set_form_data(body)
365
+ end
366
+
367
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
368
+
369
+ JSON.parse(res.body)
370
+ end
371
+ end
data/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/sig/blockbee.rbs ADDED
@@ -0,0 +1,103 @@
1
+ module BlockBee
2
+ BLOCKBEE_HOST: string
3
+ BLOCKBEE_URL: string
4
+ VERSION: String
5
+
6
+ class API
7
+ @callback_url: string
8
+ @coin: string
9
+ @own_address: string
10
+ @coin: string
11
+ @parameters: Hash[untyped, untyped]
12
+ @bb_params: Hash[untyped, untyped]
13
+ @api_key: string
14
+ @payment_address: string
15
+
16
+ def get_address: -> string
17
+
18
+ def get_conversion: -> untyped
19
+
20
+ def get_logs: -> untyped
21
+
22
+ def get_qrcode: -> untyped
23
+
24
+ def get_info: -> untyped
25
+
26
+ def self.get_supported_coins: -> untyped
27
+
28
+ def self.get_estimate: -> untyped
29
+
30
+ def self.create_payout: -> untyped
31
+
32
+ def self.list_payouts: -> untyped
33
+
34
+ def self.get_payout_wallet: -> untyped
35
+
36
+ def self.create_payout_by_ids: -> untyped
37
+
38
+ def self.process_payout: -> untyped
39
+
40
+ def self.check_payout_status: -> untyped
41
+
42
+ end
43
+
44
+ class Checkout
45
+
46
+ @api_key: string
47
+ @bb_params: hash[untyped, untyped]
48
+ @parameters: hash[untyped, untyped]
49
+ @notify_url: string
50
+
51
+ def self.deposit_logs: -> untyped
52
+
53
+ def self.payment_logs: -> untyped
54
+
55
+ def deposit_request: -> untyped
56
+
57
+ def payment_request: -> untyped
58
+
59
+ end
60
+
61
+ private
62
+
63
+ def self.process_request_get: -> untyped
64
+ def self.process_request_post: -> untyped
65
+ end
66
+
67
+ class TestBlockBee
68
+ def test_can_check_payout_status: -> TrueClass
69
+
70
+ def test_can_create_checkout_payment: -> TrueClass
71
+
72
+ def test_can_create_deposit: -> TrueClass
73
+
74
+ def test_can_create_payout_by_is: -> TrueClass
75
+
76
+ def test_can_create_payouts: -> TrueClass
77
+
78
+ def test_can_fetch_deposit_logs: -> TrueClass
79
+
80
+ def test_can_fetch_logs: -> TrueClass
81
+
82
+ def test_can_fetch_payment_logs: -> TrueClass
83
+
84
+ def test_can_generate_address: -> TrueClass
85
+
86
+ def test_can_get_conversion: -> TrueClass
87
+
88
+ def test_can_get_estimate: -> TrueClass
89
+
90
+ def test_can_get_info: -> TrueClass
91
+
92
+ def test_can_get_payout_wallet: -> TrueClass
93
+
94
+ def test_can_get_qrcode: -> TrueClass
95
+
96
+ def test_can_get_supported_coins: -> TrueClass
97
+
98
+ def test_can_list_payouts: -> TrueClass
99
+
100
+ def test_can_process_payout_by_id: -> TrueClass
101
+
102
+ def test_that_it_has_a_version_number: -> TrueClass
103
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blockbee
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - BlockBee
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - info@blockbee.io
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".DS_Store"
21
+ - CHANGELOG.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/blockbee.rb
26
+ - setup
27
+ - sig/blockbee.rbs
28
+ homepage: https://blockbee.io
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ homepage_uri: https://blockbee.io
33
+ source_code_uri: https://github.com/blockbee-io/ruby-blockbee
34
+ changelog_uri: https://github.com/blockbee-io/ruby-blockbee/blob/main/CHANGELOG.md
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.5.9
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Ruby implementation of BlockBee's payment gateway
54
+ test_files: []