cryptopay-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +36 -0
  3. data/.gitignore +38 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +104 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +521 -0
  9. data/Rakefile +8 -0
  10. data/bin/console +15 -0
  11. data/cryptopay.gemspec +40 -0
  12. data/lib/cryptopay/api/accounts.rb +51 -0
  13. data/lib/cryptopay/api/channels.rb +142 -0
  14. data/lib/cryptopay/api/coin_withdrawals.rb +115 -0
  15. data/lib/cryptopay/api/customers.rb +85 -0
  16. data/lib/cryptopay/api/exchange_transfers.rb +64 -0
  17. data/lib/cryptopay/api/invoices.rb +163 -0
  18. data/lib/cryptopay/api/rates.rb +50 -0
  19. data/lib/cryptopay/api/risks.rb +32 -0
  20. data/lib/cryptopay/api/transactions.rb +47 -0
  21. data/lib/cryptopay/authentication.rb +30 -0
  22. data/lib/cryptopay/callbacks.rb +38 -0
  23. data/lib/cryptopay/client.rb +39 -0
  24. data/lib/cryptopay/config.rb +48 -0
  25. data/lib/cryptopay/connection.rb +48 -0
  26. data/lib/cryptopay/encoder.rb +113 -0
  27. data/lib/cryptopay/errors.rb +32 -0
  28. data/lib/cryptopay/models/account.rb +88 -0
  29. data/lib/cryptopay/models/account_list_result.rb +70 -0
  30. data/lib/cryptopay/models/callback.rb +25 -0
  31. data/lib/cryptopay/models/channel.rb +156 -0
  32. data/lib/cryptopay/models/channel_list_result.rb +82 -0
  33. data/lib/cryptopay/models/channel_params.rb +102 -0
  34. data/lib/cryptopay/models/channel_payment.rb +216 -0
  35. data/lib/cryptopay/models/channel_payment_callback.rb +92 -0
  36. data/lib/cryptopay/models/channel_payment_callback_event.rb +21 -0
  37. data/lib/cryptopay/models/channel_payment_list_result.rb +82 -0
  38. data/lib/cryptopay/models/channel_payment_result.rb +68 -0
  39. data/lib/cryptopay/models/channel_payment_status.rb +21 -0
  40. data/lib/cryptopay/models/channel_payment_status_context.rb +18 -0
  41. data/lib/cryptopay/models/channel_result.rb +68 -0
  42. data/lib/cryptopay/models/channel_status.rb +18 -0
  43. data/lib/cryptopay/models/channel_update_params.rb +85 -0
  44. data/lib/cryptopay/models/coin_withdrawal.rb +205 -0
  45. data/lib/cryptopay/models/coin_withdrawal_callback.rb +92 -0
  46. data/lib/cryptopay/models/coin_withdrawal_callback_event.rb +18 -0
  47. data/lib/cryptopay/models/coin_withdrawal_list_result.rb +82 -0
  48. data/lib/cryptopay/models/coin_withdrawal_params.rb +135 -0
  49. data/lib/cryptopay/models/coin_withdrawal_result.rb +68 -0
  50. data/lib/cryptopay/models/coin_withdrawal_status.rb +24 -0
  51. data/lib/cryptopay/models/customer.rb +81 -0
  52. data/lib/cryptopay/models/customer_list_result.rb +82 -0
  53. data/lib/cryptopay/models/customer_params.rb +81 -0
  54. data/lib/cryptopay/models/customer_result.rb +68 -0
  55. data/lib/cryptopay/models/customer_update_params.rb +68 -0
  56. data/lib/cryptopay/models/exchange.rb +89 -0
  57. data/lib/cryptopay/models/exchange_transfer.rb +116 -0
  58. data/lib/cryptopay/models/exchange_transfer_params.rb +101 -0
  59. data/lib/cryptopay/models/exchange_transfer_result.rb +68 -0
  60. data/lib/cryptopay/models/invoice.rb +276 -0
  61. data/lib/cryptopay/models/invoice_callback.rb +90 -0
  62. data/lib/cryptopay/models/invoice_callback_event.rb +22 -0
  63. data/lib/cryptopay/models/invoice_list_result.rb +82 -0
  64. data/lib/cryptopay/models/invoice_params.rb +131 -0
  65. data/lib/cryptopay/models/invoice_recalculation.rb +178 -0
  66. data/lib/cryptopay/models/invoice_recalculation_params.rb +61 -0
  67. data/lib/cryptopay/models/invoice_recalculation_result.rb +68 -0
  68. data/lib/cryptopay/models/invoice_refund.rb +154 -0
  69. data/lib/cryptopay/models/invoice_refund_list_result.rb +70 -0
  70. data/lib/cryptopay/models/invoice_refund_params.rb +61 -0
  71. data/lib/cryptopay/models/invoice_refund_result.rb +68 -0
  72. data/lib/cryptopay/models/invoice_result.rb +68 -0
  73. data/lib/cryptopay/models/invoice_status.rb +21 -0
  74. data/lib/cryptopay/models/invoice_status_context.rb +20 -0
  75. data/lib/cryptopay/models/invoice_transaction.rb +76 -0
  76. data/lib/cryptopay/models/network_fee.rb +84 -0
  77. data/lib/cryptopay/models/network_fee_level.rb +19 -0
  78. data/lib/cryptopay/models/network_fee_list_result.rb +70 -0
  79. data/lib/cryptopay/models/pagination.rb +72 -0
  80. data/lib/cryptopay/models/rate.rb +74 -0
  81. data/lib/cryptopay/models/rate_result.rb +68 -0
  82. data/lib/cryptopay/models/rates_result.rb +64 -0
  83. data/lib/cryptopay/models/risk.rb +98 -0
  84. data/lib/cryptopay/models/risk_level.rb +19 -0
  85. data/lib/cryptopay/models/risk_params.rb +86 -0
  86. data/lib/cryptopay/models/risk_result.rb +68 -0
  87. data/lib/cryptopay/models/transaction.rb +174 -0
  88. data/lib/cryptopay/models/transaction_list_result.rb +82 -0
  89. data/lib/cryptopay/models/transaction_reference_type.rb +25 -0
  90. data/lib/cryptopay/request.rb +46 -0
  91. data/lib/cryptopay/require.rb +79 -0
  92. data/lib/cryptopay/types.rb +11 -0
  93. data/lib/cryptopay/version.rb +5 -0
  94. data/lib/cryptopay.rb +26 -0
  95. metadata +256 -0
data/README.md ADDED
@@ -0,0 +1,521 @@
1
+ # Cryptopay Ruby Library
2
+
3
+ Cryptopay - the official Ruby gem for the Cryptopay API
4
+
5
+ Cryptopay is a payment gateway and business wallet that allows merchants to automate the processes of accepting cryptocurrency payments and payouts from their customers, as well as making currency exchange transactions and receiving data on the transaction history and account balance statuses for reporting.
6
+
7
+ For more information, please visit [Cryptopay API docs](https://developers.cryptopay.me).
8
+
9
+ # Table of contents
10
+
11
+ * [Installation](#installation)
12
+ * [Configuration](#configuration)
13
+ * [Usage](#usage)
14
+ * [Accounts](#accounts)
15
+ * [Channels](#channels)
16
+ * [CoinWithdrawals](#coinwithdrawals)
17
+ * [Customers](#customers)
18
+ * [ExchangeTransfers](#exchangetransfers)
19
+ * [Invoices](#invoices)
20
+ * [Rates](#rates)
21
+ * [Risks](#risks)
22
+ * [Transactions](#transactions)
23
+ * [Callbacks](#callbacks)
24
+ * [Development](#development)
25
+ * [Contributing](#contributing)
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'cryptopay-ruby'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install cryptopay-ruby
42
+
43
+ ### Requirements
44
+
45
+ * Ruby 2.6+
46
+
47
+ ## Configuration
48
+
49
+ ### Create API credentials
50
+
51
+ Learn mode about API credentials at [Developers guide](https://developers.cryptopay.me/guides/api-credentials)
52
+
53
+ ### Configure library
54
+
55
+ ```ruby
56
+ require 'cryptopay'
57
+
58
+ client = Cryptopay::Client.new do |config|
59
+ config.api_url = Cryptopay::SANDBOX # Or Cryptopay::PRODUCTION
60
+ config.api_key = 'your api key'
61
+ config.api_secret = 'your api secret'
62
+ config.callback_secret = '' # Optional
63
+ end
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ ### Accounts
69
+
70
+ [Accounts API docs](https://developers.cryptopay.me/reference/accounts)
71
+
72
+ #### List accounts
73
+
74
+
75
+ ```ruby
76
+ result = client.accounts.list
77
+ p result # => <AccountListResult data=...>
78
+ ```
79
+
80
+ #### List account transactions
81
+
82
+
83
+ ```ruby
84
+ account_id = '31804390-d44e-49e9-8698-ca781e0eb806'
85
+
86
+ result = client.accounts.list_transactions(account_id)
87
+ p result # => <TransactionListResult data=...>
88
+ ```
89
+
90
+ ### Channels
91
+
92
+ A channel is a static cryptocurrency address that may be assigned to each one of your customers.
93
+
94
+ [Channels API docs](https://developers.cryptopay.me/reference/payment-channels)
95
+
96
+ #### Create a channel
97
+
98
+
99
+ ```ruby
100
+ params = Cryptopay::ChannelParams.new(
101
+ name: 'Channel name',
102
+ pay_currency: 'BTC',
103
+ receiver_currency: 'EUR'
104
+ )
105
+
106
+ result = client.channels.create(params)
107
+ p result # => <ChannelResult data=...>
108
+ ```
109
+
110
+ #### List channels
111
+
112
+
113
+ ```ruby
114
+ result = client.channels.list
115
+ p result # => <ChannelListResult data=...>
116
+ ```
117
+
118
+ #### List channel payments
119
+
120
+
121
+ ```ruby
122
+ channel_id = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1'
123
+
124
+ result = client.channels.list_payments(channel_id)
125
+ p result # => <ChannelPaymentListResult data=...>
126
+ ```
127
+
128
+ #### Retrieve a channel
129
+
130
+
131
+ ```ruby
132
+ channel_id = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1'
133
+
134
+ result = client.channels.retrieve(channel_id)
135
+ p result # => <ChannelResult data=...>
136
+ ```
137
+
138
+ #### Retrieve a channel by custom id
139
+
140
+
141
+ ```ruby
142
+ custom_id = 'CHANNEL-123'
143
+
144
+ result = client.channels.retrieve_by_custom_id(custom_id)
145
+ p result # => <ChannelResult data=...>
146
+ ```
147
+
148
+ #### Retrieve a channel payment
149
+
150
+
151
+ ```ruby
152
+ channel_id = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1'
153
+ channel_payment_id = '704291ec-0b90-4118-89aa-0c9681c3213c'
154
+
155
+ result = client.channels.retrieve_payment(channel_id, channel_payment_id)
156
+ p result # => <ChannelPaymentResult data=...>
157
+ ```
158
+
159
+ #### Update a channel
160
+
161
+
162
+ ```ruby
163
+ channel_id = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1'
164
+ params = Cryptopay::ChannelUpdateParams.new(
165
+ status: 'disabled'
166
+ )
167
+
168
+ result = client.channels.update(channel_id, params)
169
+ p result # => <ChannelResult data=...>
170
+ ```
171
+
172
+ ### CoinWithdrawals
173
+
174
+ In addition to accepting payments through the Cryptopay payment gateway, it is also possible to make payments to your customers in any of the cryptocurrency currently supported by Cryptopay. In Cryptopay, these payments are called “Coin Withdrawal”. The process of requesting coin withdrawal is almost the same for a customer in Cashier as the process of making a deposit with one exception - the customer will need to specify the address of the wallet he wants to send the cryptocurrency to.
175
+
176
+ [Coin withdrawals API docs](https://developers.cryptopay.me/reference/coin-withdrawals)
177
+
178
+ #### Commit a withdrawal
179
+
180
+
181
+ ```ruby
182
+ coin_withdrawal = client.coin_withdrawals.create(Cryptopay::CoinWithdrawalParams.new(
183
+ address: '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
184
+ charged_amount: '100.0',
185
+ charged_currency: 'EUR',
186
+ received_currency: 'BTC',
187
+ force_commit: false
188
+ )).data
189
+
190
+ result = client.coin_withdrawals.commit(coin_withdrawal.id)
191
+ p result # => <CoinWithdrawalResult data=...>
192
+ ```
193
+
194
+ #### Create a withdrawal
195
+
196
+ [Documentation](https://developers.cryptopay.me/guides/payouts/create-a-coin-withdrawal)
197
+
198
+ ```ruby
199
+ params = Cryptopay::CoinWithdrawalParams.new(
200
+ address: '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
201
+ charged_amount: '100.0',
202
+ charged_currency: 'EUR',
203
+ received_currency: 'BTC',
204
+ force_commit: true
205
+ )
206
+
207
+ result = client.coin_withdrawals.create(params)
208
+ p result # => <CoinWithdrawalResult data=...>
209
+ ```
210
+
211
+ #### List withdrawals
212
+
213
+
214
+ ```ruby
215
+ result = client.coin_withdrawals.list
216
+ p result # => <CoinWithdrawalListResult data=...>
217
+ ```
218
+
219
+ #### List network fees
220
+
221
+
222
+ ```ruby
223
+ result = client.coin_withdrawals.list_network_fees
224
+ p result # => <NetworkFeeListResult data=...>
225
+ ```
226
+
227
+ #### Retrieve a withdrawal
228
+
229
+
230
+ ```ruby
231
+ coin_withdrawal_id = '3cf9d1c4-6191-4826-8cae-2c717810c7e9'
232
+
233
+ result = client.coin_withdrawals.retrieve(coin_withdrawal_id)
234
+ p result # => <CoinWithdrawalResult data=...>
235
+ ```
236
+
237
+ #### Retrieve a withdrawal by custom id
238
+
239
+
240
+ ```ruby
241
+ custom_id = 'PAYMENT-123'
242
+
243
+ result = client.coin_withdrawals.retrieve_by_custom_id(custom_id)
244
+ p result # => <CoinWithdrawalResult data=...>
245
+ ```
246
+
247
+ ### Customers
248
+
249
+ Customer objects allow you to reject High-Risk transactions automatically, and to track multiple transactions, that are associated with the same customer
250
+
251
+ [Customers API docs](https://developers.cryptopay.me/reference/customers)
252
+
253
+ #### Create a customer
254
+
255
+
256
+ ```ruby
257
+ params = Cryptopay::CustomerParams.new(
258
+ id: 'e2abd0899bada2814e6f6aa08aae61f8',
259
+ currency: 'EUR'
260
+ )
261
+
262
+ result = client.customers.create(params)
263
+ p result # => <CustomerResult data=...>
264
+ ```
265
+
266
+ #### List customers
267
+
268
+
269
+ ```ruby
270
+ result = client.customers.list
271
+ p result # => <CustomerListResult data=...>
272
+ ```
273
+
274
+ #### Retrieve a customer
275
+
276
+
277
+ ```ruby
278
+ customer_id = 'CUSTOMER-123'
279
+
280
+ result = client.customers.retrieve(customer_id)
281
+ p result # => <CustomerResult data=...>
282
+ ```
283
+
284
+ #### Update a customer
285
+
286
+
287
+ ```ruby
288
+ customer_id = 'CUSTOMER-123'
289
+ params = Cryptopay::CustomerUpdateParams.new(
290
+ refund_addresses: {
291
+ 'BTC' => '2N9wPGx67zdSeAbXi15qHgoZ9Hb9Uxhd2uQ'
292
+ }
293
+ )
294
+
295
+ result = client.customers.update(customer_id, params)
296
+ p result # => <CustomerResult data=...>
297
+ ```
298
+
299
+ ### ExchangeTransfers
300
+
301
+ [Exchange transfers API docs](https://developers.cryptopay.me/reference/exchange)
302
+
303
+ #### Commit an exchange transfer
304
+
305
+
306
+ ```ruby
307
+ exchange_transfer = client.exchange_transfers.create(Cryptopay::ExchangeTransferParams.new(
308
+ charged_currency: 'EUR',
309
+ charged_amount: '100.0',
310
+ received_currency: 'BTC',
311
+ received_amount: nil,
312
+ force_commit: false
313
+ )).data
314
+
315
+ result = client.exchange_transfers.commit(exchange_transfer.id)
316
+ p result # => <ExchangeTransferResult data=...>
317
+ ```
318
+
319
+ #### Create an exchange transfer
320
+
321
+
322
+ ```ruby
323
+ params = Cryptopay::ExchangeTransferParams.new(
324
+ charged_currency: 'EUR',
325
+ charged_amount: '100.0',
326
+ received_currency: 'BTC',
327
+ received_amount: nil,
328
+ force_commit: true
329
+ )
330
+
331
+ result = client.exchange_transfers.create(params)
332
+ p result # => <ExchangeTransferResult data=...>
333
+ ```
334
+
335
+ #### Retrieve an exchange transfer
336
+
337
+
338
+ ```ruby
339
+ exchange_transfer_id = '2c090f99-7cc1-40da-9bca-7caa57b4ebfb'
340
+
341
+ result = client.exchange_transfers.retrieve(exchange_transfer_id)
342
+ p result # => <ExchangeTransferResult data=...>
343
+ ```
344
+
345
+ ### Invoices
346
+
347
+ An invoice is a request for a cryptocurrency payment which contains a unique BTC, LTC, ETH or XRP address and the amount that has to be paid while the invoice is valid.
348
+
349
+ [Invoices API docs](https://developers.cryptopay.me/reference/invoices)
350
+
351
+ #### Commit invoice recalculation
352
+
353
+
354
+ ```ruby
355
+ invoice_id = 'c8233d57-78c8-4c36-b35e-940ae9067c78'
356
+ recalculation = client.invoices.create_recalculation(invoice_id, {}).data
357
+
358
+ result = client.invoices.commit_recalculation(invoice_id, recalculation.id)
359
+ p result # => <InvoiceRecalculationResult data=...>
360
+ ```
361
+
362
+ #### Create an invoice
363
+
364
+
365
+ ```ruby
366
+ params = Cryptopay::InvoiceParams.new(
367
+ price_amount: '100.0',
368
+ price_currency: 'EUR',
369
+ pay_currency: 'BTC'
370
+ )
371
+
372
+ result = client.invoices.create(params)
373
+ p result # => <InvoiceResult data=...>
374
+ ```
375
+
376
+ #### Create invoice recalculation
377
+
378
+
379
+ ```ruby
380
+ invoice_id = '440d0d3a-52c4-4097-b5b1-d9b137aaca60'
381
+ invoice_recalculation_params = Cryptopay::InvoiceRecalculationParams.new(force_commit: true)
382
+
383
+ result = client.invoices.create_recalculation(invoice_id, invoice_recalculation_params)
384
+ p result # => <InvoiceRecalculationResult data=...>
385
+ ```
386
+
387
+ #### Create invoice refund
388
+
389
+
390
+ ```ruby
391
+ invoice_id = '7e274430-e20f-4321-8748-20824287ae44'
392
+ invoice_refund_params = Cryptopay::InvoiceRefundParams.new(address: '0xf3532c1fd002665ec54d46a50787e0c69c76cd44')
393
+
394
+ result = client.invoices.create_refund(invoice_id, invoice_refund_params)
395
+ p result # => <InvoiceRefundResult data=...>
396
+ ```
397
+
398
+ #### List invoices
399
+
400
+
401
+ ```ruby
402
+ result = client.invoices.list
403
+ p result # => <InvoiceListResult data=...>
404
+ ```
405
+
406
+ #### List invoice refunds
407
+
408
+
409
+ ```ruby
410
+ invoice_id = '7e274430-e20f-4321-8748-20824287ae44'
411
+
412
+ result = client.invoices.list_refunds(invoice_id)
413
+ p result # => <InvoiceRefundListResult data=...>
414
+ ```
415
+
416
+ #### Retrieve an invoice
417
+
418
+
419
+ ```ruby
420
+ invoice_id = 'c8233d57-78c8-4c36-b35e-940ae9067c78'
421
+
422
+ result = client.invoices.retrieve(invoice_id)
423
+ p result # => <InvoiceResult data=...>
424
+ ```
425
+
426
+ #### Retrieve an invoice by custom_id
427
+
428
+
429
+ ```ruby
430
+ custom_id = 'PAYMENT-123'
431
+
432
+ result = client.invoices.retrieve_by_custom_id(custom_id)
433
+ p result # => <InvoiceResult data=...>
434
+ ```
435
+
436
+ ### Rates
437
+
438
+ [Public rates API docs](https://developers.cryptopay.me/reference/public-rates)
439
+
440
+ #### Retrieve all rates
441
+
442
+
443
+ ```ruby
444
+ result = client.rates.all
445
+ p result # => <RatesResult data=...>
446
+ ```
447
+
448
+ #### Retrieve a pair rate
449
+
450
+
451
+ ```ruby
452
+ base_currency = 'BTC'
453
+ quote_currency = 'EUR'
454
+
455
+ result = client.rates.retrieve(base_currency, quote_currency)
456
+ p result # => <RateResult data=...>
457
+ ```
458
+
459
+ ### Risks
460
+
461
+ [Risks API docs](https://developers.cryptopay.me/reference/risks)
462
+
463
+ #### Score a coin address
464
+
465
+
466
+ ```ruby
467
+ params = Cryptopay::RiskParams.new(
468
+ address: '2N9wPGx67zdSeAbXi15qHgoZ9Hb9Uxhd2uQ',
469
+ currency: 'BTC',
470
+ type: 'source_of_funds'
471
+ )
472
+
473
+ result = client.risks.score(params)
474
+ p result # => <RiskResult data=...>
475
+ ```
476
+
477
+ ### Transactions
478
+
479
+ [Transactions API docs](https://developers.cryptopay.me/reference/transactions)
480
+
481
+ #### List transactions
482
+
483
+
484
+ ```ruby
485
+ result = client.transactions.list
486
+ p result # => <TransactionListResult data=...>
487
+ ```
488
+
489
+
490
+ ## Callbacks
491
+
492
+ [Documentation](https://developers.cryptopay.me/guides/api-basics/callbacks)
493
+
494
+ Every callback request contains a `X-Cryptopay-Signature` header which is needed to verify webhook body
495
+
496
+ ```ruby
497
+ client = Cryptopay::Client.new do |config|
498
+ # ...
499
+ config.callback_secret = 'your callback secret'
500
+ end
501
+
502
+ body = '{"type":"Invoice","event":"status_changed","data":{"id":"c8233d57-78c8-4c36-b35e-940ae9067c78","custom_id":null,"customer_id":null,"status":"completed","status_context":null,"address":"0x516cf64763b17893f9defa60e35d6bee26535ef9","uri":"ethereum:0x23a2e5f75cdfe03763d929379f5dc3f14f7045cd/transfer?address=0x516cf64763b17893f9defa60e35d6bee26535ef9&uint256=0.5e2","price_amount":"0.00005","price_currency":"USDT","pay_amount":"0.00005","pay_currency":"USDT","fee":"0.000001","fee_currency":"USDT","paid_amount":"0.00005","transactions":[{"txid":"0x549ae0eade6c33f087eceb0f2b586486b0442775fe8ab90c56c211e774ce27b1","risk":{"score":7.3,"level":"medium","resource_name":"default","resource_category":"unknown"}}],"name":null,"description":null,"metadata":null,"success_redirect_url":null,"unsuccess_redirect_url":null,"hosted_page_url":"https://hosted-business-sandbox.cryptopay.me/invoices/c8233d57-78c8-4c36-b35e-940ae9067c78","created_at":"2021-06-16T08:20:13+00:00","expires_at":"2021-06-16T10:20:13+00:00"}}'
503
+ signature = '7c021857107203da4af1d24007bb0f752e2f04478e5e5bff83719101f2349b54' # Value of the `X-Cryptopay-Signature` header
504
+
505
+ result = client.callbacks.verify(body, signature)
506
+ p result # => <InvoiceCallback event='status_changed' type='Invoice' data=<Invoice ...>>
507
+ ```
508
+
509
+ ## Development
510
+
511
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
512
+
513
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
514
+
515
+ ## Contributing
516
+
517
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cryptopay-dev/cryptopay-ruby.
518
+
519
+ ## License
520
+
521
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'dotenv/load'
6
+ require 'cryptopay'
7
+ require 'pry-byebug'
8
+
9
+ client = Cryptopay::Client.new do |config|
10
+ config.api_url = Cryptopay::SANDBOX
11
+ config.api_key = ENV.fetch('API_KEY')
12
+ config.api_secret = ENV.fetch('API_SECRET')
13
+ end
14
+
15
+ Pry.start
data/cryptopay.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'cryptopay/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'cryptopay-ruby'
10
+ s.version = Cryptopay::VERSION
11
+ s.authors = 'Cryptopay'
12
+ s.email = 'support@cryptopay.me'
13
+ s.homepage = 'https://developers.cryptopay.me'
14
+ s.summary = 'The official Ruby gem for the Cryptopay API'
15
+ s.description = ''
16
+ s.license = 'MIT'
17
+ s.required_ruby_version = '>= 2.6.0'
18
+
19
+ s.metadata = {
20
+ 'bug_tracker_uri' => 'https://github.com/cryptopay-dev/cryptopay-ruby/issues',
21
+ 'source_code_uri' => 'https://github.com/cryptopay-dev/cryptopay-ruby',
22
+ 'rubygems_mfa_required' => 'true'
23
+ }
24
+
25
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ s.executables = []
29
+ s.require_paths = ['lib']
30
+
31
+ s.add_runtime_dependency('faraday', '~> 1.0', '>= 1.0.1')
32
+
33
+ s.add_development_dependency('dotenv')
34
+ s.add_development_dependency('pry-byebug')
35
+ s.add_development_dependency('rake')
36
+ s.add_development_dependency('rspec')
37
+ s.add_development_dependency('rubocop')
38
+ s.add_development_dependency('vcr')
39
+ s.add_development_dependency('webmock')
40
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Auto-generated file
4
+ # DO NOT EDIT
5
+
6
+ module Cryptopay
7
+ class Accounts
8
+ def initialize(connection)
9
+ @connection = connection
10
+ end
11
+
12
+ # List accounts
13
+ # @param [Hash] opts the optional parameters
14
+ # @return [AccountListResult]
15
+ def list(_opts = {})
16
+ path = '/api/accounts'
17
+
18
+ req = Request.new(
19
+ method: :get,
20
+ path: path
21
+ )
22
+
23
+ connection.call(req, return_type: AccountListResult)
24
+ end
25
+
26
+ # List account transactions
27
+ # @param account_id [String] Account ID
28
+ # @param [Hash] opts the optional parameters
29
+ # @option opts [String] :starting_after Pagination parameter. ID to start after
30
+ # @return [TransactionListResult]
31
+ def list_transactions(account_id, opts = {})
32
+ path = '/api/accounts/{account_id}/transactions'
33
+ path = path.sub('{account_id}', CGI.escape(account_id.to_s))
34
+
35
+ query_params = {}
36
+ query_params[:starting_after] = opts[:starting_after] unless opts[:starting_after].nil?
37
+
38
+ req = Request.new(
39
+ method: :get,
40
+ path: path,
41
+ query_params: query_params
42
+ )
43
+
44
+ connection.call(req, return_type: TransactionListResult)
45
+ end
46
+
47
+ private
48
+
49
+ attr_reader :connection
50
+ end
51
+ end