add stores endpoint with specs.

This commit is contained in:
ZippyDev 2020-08-04 18:53:00 -06:00
parent ddc0619c34
commit edee8b197a
13 changed files with 362 additions and 7 deletions

View File

@ -11,6 +11,7 @@ module BtcPay
require_relative './lightning_node'
require_relative './pull_payments'
require_relative './server'
require_relative './store'
require_relative './store_payment_requests'
require_relative './store_payouts'
require_relative './store_pull_payments'

View File

@ -11,7 +11,7 @@ module BtcPay
client.get(path(pull_payment_id), options: opts)
end
alias find_by get
alias find get
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Public)/paths/~1api~1v1~1pull-payments~1{pullPaymentId}~1payouts/get
def payouts(pull_payment_id, **opts)

View File

@ -0,0 +1,62 @@
# frozen_string_literal: true
module BtcPay
module Client
module Api
class Store < Base
PATH = '/stores'
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Stores_GetStores
def all(**opts)
client.get(path, options: opts)
end
alias stores all
alias index all
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Stores/paths/~1api~1v1~1stores/post
def create(payload, **opts)
client.post(path, payload: payload, options: opts)
end
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Stores_GetStore
def get(store_id, **opts)
client.get(path(store_id), options: opts)
end
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Stores_UpdateStore
def update(store_id, payload, **opts)
client.put(path(store_id), payload: payload, options: opts)
end
alias put update
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Stores/paths/~1api~1v1~1stores~1{storeId}/delete
def delete(store_id, **opts)
client.delete(path(store_id), options: opts)
end
##
# services
##
def payment_requests
@payment_requests ||= Api::StorePaymentRequests.new(client: client)
end
def payouts
@payouts ||= Api::StorePayouts.new(client: client)
end
def pull_payments
@pull_payments ||= Api::StorePullPayments.new(client: client)
end
protected
def set_base_path
@base_path = PATH
end
end
end
end
end

View File

@ -23,7 +23,7 @@ module BtcPay
client.get(store_path(store_id, request_id), options: opts)
end
alias find_by get
alias find get
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/PaymentRequests_ArchivePaymentRequest
def delete(store_id, request_id, **opts)

View File

@ -102,11 +102,7 @@ module BtcPay
end
def store
@store ||= OpenStruct.new(
payment_requests: Api::StorePaymentRequests.new(client: self),
payouts: Api::StorePayouts.new(client: self),
pull_payments: Api::StorePullPayments.new(client: self)
)
@store ||= Api::Store.new(client: self)
end
def users

View File

@ -0,0 +1,45 @@
---
http_interactions:
- request:
method: delete
uri: http://localhost:49392/api/v1/stores/5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS
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:
- Wed, 05 Aug 2020 00:52:30 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: Wed, 05 Aug 2020 00:52:31 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,49 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:49392/api/v1/stores
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:
- Wed, 05 Aug 2020 00:34:10 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '1187'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '[{"id":"GL1rwX9rxFMYJR26Yxa1pDpzPaSvmk78CQ4khrr64z93","name":"blocklux","website":null,"invoiceExpiration":900,"monitoringExpiration":86400,"speedPolicy":"MediumSpeed","lightningDescriptionTemplate":"Paid
to {StoreName} (Order ID: {OrderId})","paymentTolerance":0.0,"anyoneCanCreateInvoice":false,"showRecommendedFee":true,"recommendedFeeBlockTarget":1,"lightningAmountInSatoshi":false,"customLogo":null,"customCSS":null,"htmlTitle":null,"redirectAutomatically":false,"requiresRefundEmail":false,"networkFeeMode":"MultiplePaymentsOnly","payJoinEnabled":false,"lightningPrivateRouteHints":false},{"id":"EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ","name":"foobar","website":null,"invoiceExpiration":900,"monitoringExpiration":86400,"speedPolicy":"MediumSpeed","lightningDescriptionTemplate":"Paid
to {StoreName} (Order ID: {OrderId})","paymentTolerance":0.0,"anyoneCanCreateInvoice":false,"showRecommendedFee":true,"recommendedFeeBlockTarget":1,"lightningAmountInSatoshi":false,"customLogo":null,"customCSS":null,"htmlTitle":null,"redirectAutomatically":false,"requiresRefundEmail":false,"networkFeeMode":"MultiplePaymentsOnly","payJoinEnabled":false,"lightningPrivateRouteHints":false}]'
recorded_at: Wed, 05 Aug 2020 00:34:10 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,48 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:49392/api/v1/stores/5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS
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:
- Wed, 05 Aug 2020 00:48:35 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '692'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"id":"5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS","name":"btcpaygem-spec-a8041e9f5c3701a801cffe12fe3a56fb","website":"https://btcpaygem-spec-6db2fa05c09f12cdf0cd91c7011bafae.com","invoiceExpiration":900,"monitoringExpiration":3600,"speedPolicy":"MediumSpeed","lightningDescriptionTemplate":"Paid
to {StoreName} (Order ID: {OrderId})","paymentTolerance":0.0,"anyoneCanCreateInvoice":false,"showRecommendedFee":true,"recommendedFeeBlockTarget":1,"defaultLang":"en","lightningAmountInSatoshi":false,"customLogo":null,"customCSS":null,"htmlTitle":null,"redirectAutomatically":false,"requiresRefundEmail":false,"networkFeeMode":"Never","payJoinEnabled":false,"lightningPrivateRouteHints":false}'
recorded_at: Wed, 05 Aug 2020 00:48:35 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,50 @@
---
http_interactions:
- request:
method: post
uri: http://localhost:49392/api/v1/stores
body:
encoding: UTF-8
string: '{"name":"btcpaygem-spec-a8041e9f5c3701a801cffe12fe3a56fb","website":"https://btcpaygem-spec-6db2fa05c09f12cdf0cd91c7011bafae.com","speedPolicy":"MediumSpeed","networkFeeMod":"Always"}'
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.0
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
Content-Length:
- '183'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Wed, 05 Aug 2020 00:43:58 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '692'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"id":"5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS","name":"btcpaygem-spec-a8041e9f5c3701a801cffe12fe3a56fb","website":"https://btcpaygem-spec-6db2fa05c09f12cdf0cd91c7011bafae.com","invoiceExpiration":900,"monitoringExpiration":3600,"speedPolicy":"MediumSpeed","lightningDescriptionTemplate":"Paid
to {StoreName} (Order ID: {OrderId})","paymentTolerance":0.0,"anyoneCanCreateInvoice":false,"showRecommendedFee":true,"recommendedFeeBlockTarget":1,"defaultLang":"en","lightningAmountInSatoshi":false,"customLogo":null,"customCSS":null,"htmlTitle":null,"redirectAutomatically":false,"requiresRefundEmail":false,"networkFeeMode":"Never","payJoinEnabled":false,"lightningPrivateRouteHints":false}'
recorded_at: Wed, 05 Aug 2020 00:43:59 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,50 @@
---
http_interactions:
- request:
method: put
uri: http://localhost:49392/api/v1/stores/5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS
body:
encoding: UTF-8
string: '{"name":"btcpaygem-spec-8d5388e3826e34b9615af8bc39505f89","website":"https://btcpaygem-spec-a7330a20e4bbb2d08ce866d061cc1408.com","speedPolicy":"MediumSpeed","networkFeeMod":"Always"}'
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.0
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
Content-Length:
- '183'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Wed, 05 Aug 2020 00:51:02 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '692'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"id":"5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS","name":"btcpaygem-spec-8d5388e3826e34b9615af8bc39505f89","website":"https://btcpaygem-spec-a7330a20e4bbb2d08ce866d061cc1408.com","invoiceExpiration":900,"monitoringExpiration":3600,"speedPolicy":"MediumSpeed","lightningDescriptionTemplate":"Paid
to {StoreName} (Order ID: {OrderId})","paymentTolerance":0.0,"anyoneCanCreateInvoice":false,"showRecommendedFee":true,"recommendedFeeBlockTarget":1,"defaultLang":"en","lightningAmountInSatoshi":false,"customLogo":null,"customCSS":null,"htmlTitle":null,"redirectAutomatically":false,"requiresRefundEmail":false,"networkFeeMode":"Never","payJoinEnabled":false,"lightningPrivateRouteHints":false}'
recorded_at: Wed, 05 Aug 2020 00:51:02 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,41 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BtcPay::Client::Api::Store, :vcr do
let(:store_id) { '5wDCC8j1d7jEF8fVh2jJKjHw6eZdzeAZZLhogqf1njMS' }
let(:client) { build(:client) }
subject { described_class.new(client: client) }
describe 'GET #all' do
let(:response) { subject.all }
it { expect(response).to be_success }
end
describe 'POST #create' do
let(:payload) { build(:store_payload) }
let(:response) { subject.create(payload) }
it { expect(response).to be_success }
end
describe 'GET #get' do
let(:response) { subject.get(store_id) }
it { expect(response).to be_success }
end
describe 'PUT #update' do
let(:payload) { build(:store_payload) }
let(:response) { subject.update(store_id, payload) }
it { expect(response).to be_success }
end
describe 'DELETE #delete' do
let(:response) { subject.delete(store_id) }
it { expect(response).to be_success }
end
end

View File

@ -13,6 +13,7 @@ RSpec.describe BtcPay::Client::Base do
it { expect(subject.lightning.node).to be_a(BtcPay::Client::Api::LightningNode) }
it { expect(subject.pull_payments).to be_a(BtcPay::Client::Api::PullPayments) }
it { expect(subject.server).to be_a(BtcPay::Client::Api::Server) }
it { expect(subject.store).to be_a(BtcPay::Client::Api::Store) }
it { expect(subject.store.payment_requests).to be_a(BtcPay::Client::Api::StorePaymentRequests) }
it { expect(subject.store.payouts).to be_a(BtcPay::Client::Api::StorePayouts) }
it { expect(subject.store.pull_payments).to be_a(BtcPay::Client::Api::StorePullPayments) }

View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
FactoryBot.define do
factory :store_payload, class: Hash do
name { "btcpaygem-spec-#{SecureRandom.hex}" }
website { "https://btcpaygem-spec-#{SecureRandom.hex}.com" }
speedPolicy { 'MediumSpeed' }
networkFeeMod { 'Always' }
initialize_with { attributes }
end
end