store payouts endpoints and specs added.

This commit is contained in:
ZippyDev 2020-08-03 19:07:13 -06:00
parent ef65b3f325
commit 9a4192a2b8
11 changed files with 181 additions and 4 deletions

View File

@ -73,6 +73,12 @@ All endpoints are accessed via namespaced Api resource. Example: `client.users.c
1. TODO - Set up local lightning network, testing, etc.
#### Pull Payments:
1. `GET #get(pull_payment_id)`
1. `GET #payouts`
1. `POST #create_payout(pull_payment_id, payload)`
#### Store:
- ##### Payment Requests:
@ -83,6 +89,11 @@ All endpoints are accessed via namespaced Api resource. Example: `client.users.c
1. `DELETE #delete(store_id, request_id)`
1. `PUT #update(store_id, request_id, payload)`
- ##### Payouts:
1. `POST #approve(store_id, payout_id, payload)`
1. `DELETE #delete(store_id, payout_id)`
- ##### Pull Payments:
1. `GET #all(store_id)`

View File

@ -9,7 +9,9 @@ module BtcPay
require_relative './api_keys'
require_relative './health'
require_relative './lightning_node'
require_relative './pull_payments'
require_relative './store_payment_requests'
require_relative './store_payouts'
require_relative './store_pull_payments'
require_relative './users'
end

View File

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

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
module BtcPay
module Client
module Api
class StorePayouts < Base
PATH = '/stores/:store_id/payouts'
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#/paths/~1api~1v1~1stores~1{storeId}~1payouts~1{payoutId}/post
def approve(store_id, payout_id, payload, **opts)
client.post(store_path(store_id, payout_id), payload: payload, options: opts)
end
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Management)/paths/~1api~1v1~1stores~1{storeId}~1payouts~1{payoutId}/delete
def delete(store_id, payout_id, **opts)
client.delete(store_path(store_id, payout_id), options: opts)
end
alias cancel delete
protected
def set_base_path
@base_path = PATH.dup
end
end
end
end
end

View File

@ -12,7 +12,6 @@ module BtcPay
end
alias get me
alias show me
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Users/paths/~1api~1v1~1users/post
def create(payload, **opts)

View File

@ -48,7 +48,7 @@ module BtcPay
# @param options [Hash]
# @param headers [Hash]
# @return [Result]
def post(uri, payload:, options: {}, headers: {})
def post(uri, payload: {}, options: {}, headers: {})
data = payload.is_a?(Hash) ? payload.to_json : payload
request(uri, method: :post, payload: data, options: options, headers: headers)
end
@ -91,9 +91,16 @@ module BtcPay
@lightning ||= OpenStruct.new(node: Api::LightningNode.new(client: self))
end
def pull_payments
@pull_payments ||= Api::PullPayments.new(client: self)
end
alias payments pull_payments
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)
)
end

View File

@ -0,0 +1,45 @@
---
http_interactions:
- request:
method: delete
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payouts/2aZ1fde5X1QHpVTcMSbuqmr9B78m
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:
- Tue, 04 Aug 2020 01:02:48 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: Tue, 04 Aug 2020 01:02:49 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,49 @@
---
http_interactions:
- request:
method: post
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/payouts/2aZ1fde5X1QHpVTcMSbuqmr9B78m
body:
encoding: UTF-8
string: '{"amount":0.21451067150576175,"title":"btcpaygem-spec-182e3749158244892465aeda7f3fa60f","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:
- '105'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Tue, 04 Aug 2020 00:41:55 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '290'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"date":1596501003,"id":"2aZ1fde5X1QHpVTcMSbuqmr9B78m","pullPaymentId":"emenWTiqGdphbmbegTiRAe87kjX","destination":"bcrt1q55ktna5ygaf2dzn8qlzvgx4684x3tgnlgsh6az","paymentMethod":"BTC","amount":"0.015019329136042226","paymentMethodAmount":"0.01501932","state":"AwaitingPayment","revision":0}'
recorded_at: Tue, 04 Aug 2020 00:41:56 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,24 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BtcPay::Client::Api::StorePayouts, :vcr do
let(:store_id) { 'EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ' }
let(:payout_id) { '2aZ1fde5X1QHpVTcMSbuqmr9B78m' }
let(:client) { build(:client) }
subject { described_class.new(client: client) }
describe 'POST #approve' do
let(:payload) { build(:store_payment_requests_payload) }
let(:response) { subject.approve(store_id, payout_id, payload) }
it { expect(response).to be_success }
end
describe 'DELETE #delete' do
let(:payout_id) { '2aZ1fde5X1QHpVTcMSbuqmr9B78m' }
let(:response) { subject.delete(store_id, payout_id) }
it { expect(response).to be_success }
end
end

View File

@ -11,7 +11,9 @@ 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.pull_payments).to be_a(BtcPay::Client::Api::PullPayments) }
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) }
it { expect(subject.users).to be_a(BtcPay::Client::Api::Users) }
end

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
FactoryBot.define do
factory :store_payouts_payload, class: Hash do
revision { 0 }
rateRule { 'kraken(BTC_USD)' }
initialize_with { attributes }
end
end