store payment requests client and specs. updates to base_url init.
This commit is contained in:
parent
8e3da9c708
commit
3bfaf18654
16
README.md
16
README.md
|
@ -71,18 +71,28 @@ All endpoints are accessed via namespaced Api resource. Example: `client.users.c
|
|||
|
||||
#### Lightning:
|
||||
|
||||
1. TODO - Set up local lightning network
|
||||
1. TODO - Set up local lightning network, testing, etc.
|
||||
|
||||
#### Store:
|
||||
|
||||
- ##### Payment Requests:
|
||||
|
||||
1. `GET #all(store_id)`
|
||||
1. `POST #create(payload)`
|
||||
1. `GET #get(store_id, request_id)`
|
||||
1. `DELETE #delete(store_id, request_id)`
|
||||
1. `PUT #update(store_id, request_id, payload)`
|
||||
|
||||
#### Users:
|
||||
|
||||
1. `GET #me`
|
||||
1. `POST #create(payload)`
|
||||
|
||||
### Request helpers
|
||||
## Request helpers
|
||||
|
||||
#### Api Keys:
|
||||
|
||||
##### Authorize
|
||||
- ##### Authorize
|
||||
|
||||
1. `GET #html(permissions: [], application_name:, strict: true, selective_stores: false)`
|
||||
1. `#link(permissions: [], application_name:, strict: true, selective_stores: false)`
|
||||
|
|
|
@ -35,8 +35,8 @@ module BtcPay
|
|||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
PATH
|
||||
def set_base_path
|
||||
@base_path = PATH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@ module BtcPay
|
|||
require_relative './api_keys'
|
||||
require_relative './health'
|
||||
require_relative './lightning_node'
|
||||
require_relative './store_payment_requests'
|
||||
require_relative './users'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,8 +16,8 @@ module BtcPay
|
|||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
PATH
|
||||
def set_base_path
|
||||
@base_path = PATH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,8 +58,8 @@ module BtcPay
|
|||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
PATH
|
||||
def set_base_path
|
||||
@base_path = PATH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module BtcPay
|
||||
module Client
|
||||
module Api
|
||||
class StorePaymentRequests < Base
|
||||
PATH = '/stores/:store_id/payment-requests'
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_GetPaymentRequests
|
||||
def all(store_id, **opts)
|
||||
client.get(store_path(store_id), options: opts)
|
||||
end
|
||||
|
||||
alias index all
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_CreatePaymentRequest
|
||||
def create(store_id, payload, **opts)
|
||||
client.post(store_path(store_id), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_GetPaymentRequests
|
||||
def get(store_id, request_id, **opts)
|
||||
client.get(store_path(store_id, request_id), options: opts)
|
||||
end
|
||||
|
||||
alias show get
|
||||
alias by_id get
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_ArchivePaymentRequest
|
||||
def delete(store_id, request_id, **opts)
|
||||
client.delete(store_path(store_id, request_id), options: opts)
|
||||
end
|
||||
|
||||
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_ArchivePaymentRequest
|
||||
def update(store_id, request_id, payload, **opts)
|
||||
client.put(store_path(store_id, request_id), payload: payload, options: opts)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_base_path
|
||||
@base_path = PATH.dup
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,8 +21,8 @@ module BtcPay
|
|||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
PATH
|
||||
def set_base_path
|
||||
@base_path = PATH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,6 +53,18 @@ module BtcPay
|
|||
request(uri, method: :post, payload: data, options: options, headers: headers)
|
||||
end
|
||||
|
||||
# PUT request
|
||||
#
|
||||
# @param uri [String]
|
||||
# @param payload [Hash]
|
||||
# @param options [Hash]
|
||||
# @param headers [Hash]
|
||||
# @return [Result]
|
||||
def put(uri, payload:, options: {}, headers: {})
|
||||
data = payload.is_a?(Hash) ? payload.to_json : payload
|
||||
request(uri, method: :put, payload: data, options: options, headers: headers)
|
||||
end
|
||||
|
||||
# DELETE request
|
||||
#
|
||||
# @param uri [String]
|
||||
|
@ -79,6 +91,12 @@ module BtcPay
|
|||
@lightning ||= OpenStruct.new(node: Api::LightningNode.new(client: self))
|
||||
end
|
||||
|
||||
def store
|
||||
@store ||= OpenStruct.new(
|
||||
payment_requests: Api::StorePaymentRequests.new(client: self)
|
||||
)
|
||||
end
|
||||
|
||||
def users
|
||||
@users ||= Api::Users.new(client: self)
|
||||
end
|
||||
|
|
|
@ -8,9 +8,7 @@ module BtcPay
|
|||
Authorize.new(client: client)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def base_path; end
|
||||
def set_base_path; end
|
||||
|
||||
class Authorize
|
||||
PATH = '/api-keys/authorize'
|
||||
|
|
|
@ -4,24 +4,30 @@ module BtcPay
|
|||
module Client
|
||||
class Service
|
||||
def initialize(client:)
|
||||
@base_path = set_base_path
|
||||
@client = client
|
||||
@logger = @client.logger
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def base_path
|
||||
raise NotImplementedError.new
|
||||
end
|
||||
|
||||
def path(*args)
|
||||
request_path = args.prepend(base_path.presence).compact.join('/')
|
||||
request_path[0].eql?('/') ? request_path : '/' + request_path
|
||||
end
|
||||
|
||||
def store_path(store_id, *args)
|
||||
base_path.gsub!(':store_id', store_id)
|
||||
path(*args)
|
||||
end
|
||||
|
||||
def set_base_path
|
||||
raise NotImplementedError.new
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :client, :logger
|
||||
attr_reader :client, :logger, :base_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: delete
|
||||
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payment-requests/007b9ad8-49f1-4b99-942b-3917ceb20eef
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ''
|
||||
headers:
|
||||
Accept:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- btcpay_ruby/0.1.0
|
||||
Content-Type:
|
||||
- application/json
|
||||
Accept-Encoding:
|
||||
- deflate, gzip
|
||||
Authorization:
|
||||
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
|
||||
Host:
|
||||
- localhost:49392
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Date:
|
||||
- Sun, 02 Aug 2020 22:34:17 GMT
|
||||
Server:
|
||||
- Kestrel
|
||||
Content-Length:
|
||||
- '0'
|
||||
Referrer-Policy:
|
||||
- same-origin
|
||||
X-Xss-Protection:
|
||||
- 1; mode=block
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: ''
|
||||
recorded_at: Sun, 02 Aug 2020 22:34:18 GMT
|
||||
recorded_with: VCR 6.0.0
|
|
@ -0,0 +1,48 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: get
|
||||
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payment-requests
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ''
|
||||
headers:
|
||||
Accept:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- btcpay_ruby/0.1.0
|
||||
Content-Type:
|
||||
- application/json
|
||||
Accept-Encoding:
|
||||
- deflate, gzip
|
||||
Authorization:
|
||||
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
|
||||
Host:
|
||||
- localhost:49392
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Date:
|
||||
- Sun, 02 Aug 2020 22:01:36 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Server:
|
||||
- Kestrel
|
||||
Content-Length:
|
||||
- '313'
|
||||
Referrer-Policy:
|
||||
- same-origin
|
||||
X-Xss-Protection:
|
||||
- 1; mode=block
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '[{"status":"Pending","created":"2020-08-02T21:43:31.785466+00:00","id":"bb592ecf-c06e-4d62-8421-f7089d32be47","archived":false,"amount":1.0,"currency":"BTC","expiryDate":null,"title":"test
|
||||
payment request","description":null,"email":null,"embeddedCSS":null,"customCSSLink":null,"allowCustomPaymentAmounts":false}]'
|
||||
recorded_at: Sun, 02 Aug 2020 22:01:36 GMT
|
||||
recorded_with: VCR 6.0.0
|
|
@ -0,0 +1,47 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: get
|
||||
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payment-requests/007b9ad8-49f1-4b99-942b-3917ceb20eef
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ''
|
||||
headers:
|
||||
Accept:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- btcpay_ruby/0.1.0
|
||||
Content-Type:
|
||||
- application/json
|
||||
Accept-Encoding:
|
||||
- deflate, gzip
|
||||
Authorization:
|
||||
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
|
||||
Host:
|
||||
- localhost:49392
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Date:
|
||||
- Sun, 02 Aug 2020 22:32:20 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Server:
|
||||
- Kestrel
|
||||
Content-Length:
|
||||
- '353'
|
||||
Referrer-Policy:
|
||||
- same-origin
|
||||
X-Xss-Protection:
|
||||
- 1; mode=block
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"status":"Pending","created":"2020-08-02T22:26:48.765377+00:00","id":"007b9ad8-49f1-4b99-942b-3917ceb20eef","archived":false,"amount":0.0263030198908152,"currency":"BTC","expiryDate":null,"title":"btcpaygem-spec-99e62cfe560e7fb2907c4f04c2581751","description":null,"email":null,"embeddedCSS":null,"customCSSLink":null,"allowCustomPaymentAmounts":false}'
|
||||
recorded_at: Sun, 02 Aug 2020 22:32:21 GMT
|
||||
recorded_with: VCR 6.0.0
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: post
|
||||
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payment-requests
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"amount":0.026303019890815182,"title":"btcpaygem-spec-99e62cfe560e7fb2907c4f04c2581751","currency":"BTC"}'
|
||||
headers:
|
||||
Accept:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- btcpay_ruby/0.1.0
|
||||
Content-Type:
|
||||
- application/json
|
||||
Accept-Encoding:
|
||||
- deflate, gzip
|
||||
Authorization:
|
||||
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
|
||||
Content-Length:
|
||||
- '106'
|
||||
Host:
|
||||
- localhost:49392
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Date:
|
||||
- Sun, 02 Aug 2020 22:26:48 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Server:
|
||||
- Kestrel
|
||||
Content-Length:
|
||||
- '354'
|
||||
Referrer-Policy:
|
||||
- same-origin
|
||||
X-Xss-Protection:
|
||||
- 1; mode=block
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"status":"Pending","created":"2020-08-02T22:26:48.7653777+00:00","id":"007b9ad8-49f1-4b99-942b-3917ceb20eef","archived":false,"amount":0.0263030198908152,"currency":"BTC","expiryDate":null,"title":"btcpaygem-spec-99e62cfe560e7fb2907c4f04c2581751","description":null,"email":null,"embeddedCSS":null,"customCSSLink":null,"allowCustomPaymentAmounts":false}'
|
||||
recorded_at: Sun, 02 Aug 2020 22:26:48 GMT
|
||||
recorded_with: VCR 6.0.0
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: put
|
||||
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payment-requests/bb592ecf-c06e-4d62-8421-f7089d32be47
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"amount":0.2819996798190125,"title":"btcpaygem-spec-d1bf6f3b5696cfa4685cd94a5da3fe5b","currency":"BTC"}'
|
||||
headers:
|
||||
Accept:
|
||||
- application/json
|
||||
User-Agent:
|
||||
- btcpay_ruby/0.1.0
|
||||
Content-Type:
|
||||
- application/json
|
||||
Accept-Encoding:
|
||||
- deflate, gzip
|
||||
Authorization:
|
||||
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
|
||||
Content-Length:
|
||||
- '104'
|
||||
Host:
|
||||
- localhost:49392
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
headers:
|
||||
Date:
|
||||
- Sun, 02 Aug 2020 22:40:41 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Server:
|
||||
- Kestrel
|
||||
Content-Length:
|
||||
- '352'
|
||||
Referrer-Policy:
|
||||
- same-origin
|
||||
X-Xss-Protection:
|
||||
- 1; mode=block
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
body:
|
||||
encoding: UTF-8
|
||||
string: '{"status":"Pending","created":"2020-08-02T21:43:31.785466+00:00","id":"bb592ecf-c06e-4d62-8421-f7089d32be47","archived":false,"amount":0.281999679819012,"currency":"BTC","expiryDate":null,"title":"btcpaygem-spec-d1bf6f3b5696cfa4685cd94a5da3fe5b","description":null,"email":null,"embeddedCSS":null,"customCSSLink":null,"allowCustomPaymentAmounts":false}'
|
||||
recorded_at: Sun, 02 Aug 2020 22:40:41 GMT
|
||||
recorded_with: VCR 6.0.0
|
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe BtcPay::Client::Api::StorePaymentRequests, :vcr do
|
||||
let(:store_id) { 'EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ' }
|
||||
let(:client) { build(:client) }
|
||||
subject { described_class.new(client: client) }
|
||||
|
||||
describe 'GET #all' do
|
||||
let(:response) { subject.all(store_id) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:payload) { build(:store_payment_requests_payload) }
|
||||
let(:response) { subject.create(store_id, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'GET #get' do
|
||||
let(:request_id) { '007b9ad8-49f1-4b99-942b-3917ceb20eef' }
|
||||
let(:response) { subject.get(store_id, request_id) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'DELETE #delete' do
|
||||
let(:request_id) { '007b9ad8-49f1-4b99-942b-3917ceb20eef' }
|
||||
let(:response) { subject.delete(store_id, request_id) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
let(:request_id) { 'bb592ecf-c06e-4d62-8421-f7089d32be47' }
|
||||
let(:payload) { build(:store_payment_requests_payload) }
|
||||
let(:response) { subject.update(store_id, request_id, payload) }
|
||||
|
||||
it { expect(response).to be_success }
|
||||
end
|
||||
end
|
|
@ -11,6 +11,7 @@ RSpec.describe BtcPay::Client::Base do
|
|||
it { expect(subject.api_keys_helper).to be_a(BtcPay::Client::Helpers::ApiKeys) }
|
||||
it { expect(subject.health).to be_a(BtcPay::Client::Api::Health) }
|
||||
it { expect(subject.lightning.node).to be_a(BtcPay::Client::Api::LightningNode) }
|
||||
it { expect(subject.store.payment_requests).to be_a(BtcPay::Client::Api::StorePaymentRequests) }
|
||||
it { expect(subject.users).to be_a(BtcPay::Client::Api::Users) }
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :store_payment_requests_payload, class: Hash do
|
||||
amount { SecureRandom.rand(0.0..1.0) }
|
||||
title { "btcpaygem-spec-#{SecureRandom.hex}" }
|
||||
currency { 'BTC' }
|
||||
|
||||
initialize_with { attributes }
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue