add pull-payments endpoint.

This commit is contained in:
ZippyDev 2020-08-03 18:33:37 -06:00
parent 0833758504
commit ef65b3f325
6 changed files with 216 additions and 0 deletions

View File

@ -0,0 +1,34 @@
# frozen_string_literal: true
module BtcPay
module Client
module Api
class PullPayments < Base
PATH = 'pull-payments'
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Public)/paths/~1api~1v1~1pull-payments~1{pullPaymentId}/get
def get(pull_payment_id, **opts)
client.get(path(pull_payment_id), options: opts)
end
alias find_by 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)
client.get(path(pull_payment_id, 'payouts'), options: opts)
end
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Public)/paths/~1api~1v1~1pull-payments~1{pullPaymentId}~1payouts/post
def create_payout(pull_payment_id, payload, **opts)
client.post(path(pull_payment_id, 'payouts'), payload: payload, options: opts)
end
protected
def set_base_path
@base_path = PATH.dup
end
end
end
end
end

View File

@ -0,0 +1,47 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:49392/api/v1/pull-payments/emenWTiqGdphbmbegTiRAe87kjX
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 00:30:36 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '288'
Referrer-Policy:
- same-origin
X-Xss-Protection:
- 1; mode=block
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
body:
encoding: UTF-8
string: '{"startsAt":1596412999,"expiresAt":null,"id":"emenWTiqGdphbmbegTiRAe87kjX","name":"btcpaygem-spec-b78450cd35a96f91e0255fdf14020bdc","currency":"BTC","amount":"0.5594830804631368","period":null,"archived":false,"viewLink":"http://localhost:49392/pull-payments/emenWTiqGdphbmbegTiRAe87kjX"}'
recorded_at: Tue, 04 Aug 2020 00:30:36 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,47 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:49392/api/v1/pull-payments/emenWTiqGdphbmbegTiRAe87kjX/payouts
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 00:30:37 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '285'
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":null,"state":"AwaitingApproval","revision":0}]'
recorded_at: Tue, 04 Aug 2020 00:30:37 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,49 @@
---
http_interactions:
- request:
method: post
uri: http://localhost:49392/api/v1/pull-payments/emenWTiqGdphbmbegTiRAe87kjX/payouts
body:
encoding: UTF-8
string: '{"amount":0.015019329136042226,"paymentMethod":"BTC","destination":"bcrt1q55ktna5ygaf2dzn8qlzvgx4684x3tgnlgsh6az"}'
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.0
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 9133b8ef3ae9a4b7f2d9a6efef1d5cf738067c68
Content-Length:
- '114'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Tue, 04 Aug 2020 00:30:03 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '283'
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":null,"state":"AwaitingApproval","revision":0}'
recorded_at: Tue, 04 Aug 2020 00:30:03 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BtcPay::Client::Api::PullPayments, :vcr do
let(:pull_payment_id) { 'emenWTiqGdphbmbegTiRAe87kjX' }
let(:client) { build(:client) }
subject { described_class.new(client: client) }
describe 'GET #get' do
let(:response) { subject.get(pull_payment_id) }
it { expect(response).to be_success }
end
describe 'GET #payouts' do
let(:response) { subject.payouts(pull_payment_id) }
it { expect(response).to be_success }
end
describe 'POST #create_payout' do
let(:payload) { build(:pull_payments_payout_payload) }
let(:response) { subject.create_payout(pull_payment_id, payload) }
it { expect(response).to be_success }
end
end

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
FactoryBot.define do
factory :pull_payments_payout_payload, class: Hash do
amount { SecureRandom.rand(0.0..0.1) }
paymentMethod { 'BTC' }
destination { 'bcrt1q55ktna5ygaf2dzn8qlzvgx4684x3tgnlgsh6az' }
initialize_with { attributes }
end
end