btcpay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'btcpay/version'
4
+
5
+ require 'btcpay/client/config'
6
+ require 'btcpay/client/base'
7
+
8
+ module BtcPay
9
+ class Error < StandardError; end
10
+
11
+ module_function
12
+
13
+ def new(**args)
14
+ config = BtcPay::Client::Config.new(**args)
15
+ BtcPay::Client::Base.new(config: config, **args)
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class ApiKeys < Base
7
+ PATH = '/api-keys'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/API-Keys/paths/~1api~1v1~1api-keys~1current/get
10
+ def current(**opts)
11
+ client.get(path('current'), options: opts)
12
+ end
13
+
14
+ alias get current
15
+ alias info current
16
+
17
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/API-Keys/paths/~1api~1v1~1api-keys/post
18
+ def create(payload, **opts)
19
+ client.post(path, payload: payload, options: opts)
20
+ end
21
+
22
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/API-Keys/paths/~1api~1v1~1api-keys~1{apikey}/delete
23
+ def revoke(key, **opts)
24
+ client.delete(path(key), options: opts)
25
+ end
26
+
27
+ alias delete revoke
28
+
29
+ # https://docs.btcpayserver.org/API/Greenfield/v1/#tag/API-Keys/paths/~1api~1v1~1api-keys~1current/delete
30
+ def revoke!(**opts)
31
+ client.delete(path('current'), options: opts)
32
+ end
33
+
34
+ alias delete! revoke!
35
+
36
+ protected
37
+
38
+ def set_base_path
39
+ @base_path = PATH
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../service'
4
+
5
+ module BtcPay
6
+ module Client
7
+ module Api
8
+ class Base < Client::Service
9
+ require_relative './api_keys'
10
+ require_relative './health'
11
+ require_relative './lightning_node'
12
+ require_relative './pull_payments'
13
+ require_relative './server'
14
+ require_relative './store'
15
+ require_relative './store_payment_requests'
16
+ require_relative './store_payouts'
17
+ require_relative './store_pull_payments'
18
+ require_relative './users'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class Health < Base
7
+ PATH = '/health'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Health_GetHealth
10
+ def status(**opts)
11
+ client.get(path, options: opts)
12
+ end
13
+
14
+ alias get status
15
+ alias info status
16
+
17
+ protected
18
+
19
+ def set_base_path
20
+ @base_path = PATH
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class LightningNode < Base
7
+ PATH = '/server/lightning/'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Lightning-(Internal-Node)
10
+ def info(crypto_code, **opts)
11
+ client.get(path(crypto_code, 'info'), options: opts)
12
+ end
13
+
14
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_ConnectToNode
15
+ def connect(crypto_code, payload, **opts)
16
+ client.post(path(crypto_code, 'connect'), payload: payload, options: opts)
17
+ end
18
+
19
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_GetChannels
20
+ def channels(crypto_code, **opts)
21
+ client.get(path(crypto_code, 'channels'), options: opts)
22
+ end
23
+
24
+ alias get_channels channels
25
+
26
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_OpenChannel
27
+ def open(crypto_code, payload, **opts)
28
+ client.post(path(crypto_code, 'channels'), payload: payload, options: opts)
29
+ end
30
+
31
+ alias open_channels open
32
+
33
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_GetDepositAddress
34
+ def deposit_address(crypto_code, payload, **opts)
35
+ client.post(path(crypto_code, 'address'), payload: payload, options: opts)
36
+ end
37
+
38
+ alias address deposit_address
39
+
40
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_GetInvoice
41
+ def invoice(crypto_code, invoice_id, **opts)
42
+ client.get(path(crypto_code, 'invoices', invoice_id), options: opts)
43
+ end
44
+
45
+ alias get_invoice invoice
46
+
47
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_PayInvoice
48
+ def pay(crypto_code, payload, **opts)
49
+ client.post(path(crypto_code, 'invoices', 'pay'), payload: payload, options: opts)
50
+ end
51
+
52
+ alias pay_invoice pay
53
+
54
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/InternalLightningNodeApi_CreateInvoice
55
+ def create_invoice(crypto_code, payload, **opts)
56
+ client.post(path(crypto_code, 'invoices'), payload: payload, options: opts)
57
+ end
58
+
59
+ protected
60
+
61
+ def set_base_path
62
+ @base_path = PATH
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class PullPayments < Base
7
+ PATH = 'pull-payments'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Public)/paths/~1api~1v1~1pull-payments~1{pullPaymentId}/get
10
+ def get(pull_payment_id, **opts)
11
+ client.get(path(pull_payment_id), options: opts)
12
+ end
13
+
14
+ alias find get
15
+
16
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Public)/paths/~1api~1v1~1pull-payments~1{pullPaymentId}~1payouts/get
17
+ def payouts(pull_payment_id, **opts)
18
+ client.get(path(pull_payment_id, 'payouts'), options: opts)
19
+ end
20
+
21
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Public)/paths/~1api~1v1~1pull-payments~1{pullPaymentId}~1payouts/post
22
+ def create_payout(pull_payment_id, payload, **opts)
23
+ client.post(path(pull_payment_id, 'payouts'), payload: payload, options: opts)
24
+ end
25
+
26
+ protected
27
+
28
+ def set_base_path
29
+ @base_path = PATH.dup
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class Server < Base
7
+ PATH = '/server'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Health_GetHealth
10
+ def info(**opts)
11
+ client.get(path('info'), options: opts)
12
+ end
13
+
14
+ protected
15
+
16
+ def set_base_path
17
+ @base_path = PATH
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class Store < Base
7
+ PATH = '/stores'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Stores_GetStores
10
+ def all(**opts)
11
+ client.get(path, options: opts)
12
+ end
13
+
14
+ alias stores all
15
+ alias index all
16
+
17
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Stores/paths/~1api~1v1~1stores/post
18
+ def create(payload, **opts)
19
+ client.post(path, payload: payload, options: opts)
20
+ end
21
+
22
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Stores_GetStore
23
+ def get(store_id, **opts)
24
+ client.get(path(store_id), options: opts)
25
+ end
26
+
27
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Stores_UpdateStore
28
+ def update(store_id, payload, **opts)
29
+ client.put(path(store_id), payload: payload, options: opts)
30
+ end
31
+
32
+ alias put update
33
+
34
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Stores/paths/~1api~1v1~1stores~1{storeId}/delete
35
+ def delete(store_id, **opts)
36
+ client.delete(path(store_id), options: opts)
37
+ end
38
+
39
+ ##
40
+ # services
41
+ ##
42
+ def payment_requests
43
+ @payment_requests ||= Api::StorePaymentRequests.new(client: client)
44
+ end
45
+
46
+ def payouts
47
+ @payouts ||= Api::StorePayouts.new(client: client)
48
+ end
49
+
50
+ def pull_payments
51
+ @pull_payments ||= Api::StorePullPayments.new(client: client)
52
+ end
53
+
54
+ protected
55
+
56
+ def set_base_path
57
+ @base_path = PATH
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class StorePaymentRequests < Base
7
+ PATH = '/stores/:store_id/payment-requests'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_GetPaymentRequests
10
+ def all(store_id, **opts)
11
+ client.get(store_path(store_id), options: opts)
12
+ end
13
+
14
+ alias index all
15
+
16
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_CreatePaymentRequest
17
+ def create(store_id, payload, **opts)
18
+ client.post(store_path(store_id), payload: payload, options: opts)
19
+ end
20
+
21
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_GetPaymentRequests
22
+ def get(store_id, request_id, **opts)
23
+ client.get(store_path(store_id, request_id), options: opts)
24
+ end
25
+
26
+ alias find get
27
+
28
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_ArchivePaymentRequest
29
+ def delete(store_id, request_id, **opts)
30
+ client.delete(store_path(store_id, request_id), options: opts)
31
+ end
32
+
33
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_ArchivePaymentRequest
34
+ def update(store_id, request_id, payload, **opts)
35
+ client.put(store_path(store_id, request_id), payload: payload, options: opts)
36
+ end
37
+
38
+ protected
39
+
40
+ def set_base_path
41
+ @base_path = PATH.dup
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class StorePayouts < Base
7
+ PATH = '/stores/:store_id/payouts'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#/paths/~1api~1v1~1stores~1{storeId}~1payouts~1{payoutId}/post
10
+ def approve(store_id, payout_id, payload, **opts)
11
+ client.post(store_path(store_id, payout_id), payload: payload, options: opts)
12
+ end
13
+
14
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Management)/paths/~1api~1v1~1stores~1{storeId}~1payouts~1{payoutId}/delete
15
+ def delete(store_id, payout_id, **opts)
16
+ client.delete(store_path(store_id, payout_id), options: opts)
17
+ end
18
+
19
+ alias cancel delete
20
+
21
+ protected
22
+
23
+ def set_base_path
24
+ @base_path = PATH.dup
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class StorePullPayments < Base
7
+ PATH = '/stores/:store_id/pull-payments'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Management)/paths/~1api~1v1~1stores~1{storeId}~1pull-payments/get
10
+ def all(store_id, **opts)
11
+ client.get(store_path(store_id), options: opts)
12
+ end
13
+
14
+ alias index all
15
+
16
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_CreatePaymentRequest
17
+ def create(store_id, payload, **opts)
18
+ client.post(store_path(store_id), payload: payload, options: opts)
19
+ end
20
+
21
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Management)/paths/~1api~1v1~1stores~1{storeId}~1pull-payments~1{pullPaymentId}/delete
22
+ def delete(store_id, pull_payment_id, **opts)
23
+ client.delete(store_path(store_id, pull_payment_id), options: opts)
24
+ end
25
+
26
+ protected
27
+
28
+ def set_base_path
29
+ @base_path = PATH.dup
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BtcPay
4
+ module Client
5
+ module Api
6
+ class Users < Base
7
+ PATH = '/users'
8
+
9
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Users_GetCurrentUser
10
+ def me(**opts)
11
+ client.get(path('me'), options: opts)
12
+ end
13
+
14
+ alias get me
15
+
16
+ # @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Users/paths/~1api~1v1~1users/post
17
+ def create(payload, **opts)
18
+ client.post(path, payload: payload, options: opts)
19
+ end
20
+
21
+ protected
22
+
23
+ def set_base_path
24
+ @base_path = PATH
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end