add pull-payments endpoint with specs.

This commit is contained in:
ZippyDev 2020-08-02 17:10:15 -06:00
parent 3bfaf18654
commit 0833758504
10 changed files with 227 additions and 2 deletions

View File

@ -78,11 +78,17 @@ All endpoints are accessed via namespaced Api resource. Example: `client.users.c
- ##### Payment Requests:
1. `GET #all(store_id)`
1. `POST #create(payload)`
1. `POST #create(store_id, payload)`
1. `GET #get(store_id, request_id)`
1. `DELETE #delete(store_id, request_id)`
1. `PUT #update(store_id, request_id, payload)`
- ##### Pull Payments:
1. `GET #all(store_id)`
1. `POST #create(store_id, payload)`
1. `DELETE #delete(store_id, pull_payment_id)`
#### Users:
1. `GET #me`

View File

@ -10,6 +10,7 @@ module BtcPay
require_relative './health'
require_relative './lightning_node'
require_relative './store_payment_requests'
require_relative './store_pull_payments'
require_relative './users'
end
end

View File

@ -0,0 +1,34 @@
# frozen_string_literal: true
module BtcPay
module Client
module Api
class StorePullPayments < Base
PATH = '/stores/:store_id/pull-payments'
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#tag/Pull-payments-(Management)/paths/~1api~1v1~1stores~1{storeId}~1pull-payments/get
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/#tag/Pull-payments-(Management)/paths/~1api~1v1~1stores~1{storeId}~1pull-payments~1{pullPaymentId}/delete
def delete(store_id, pull_payment_id, **opts)
client.delete(store_path(store_id, pull_payment_id), options: opts)
end
protected
def set_base_path
@base_path = PATH.dup
end
end
end
end
end

View File

@ -93,7 +93,8 @@ module BtcPay
def store
@store ||= OpenStruct.new(
payment_requests: Api::StorePaymentRequests.new(client: self)
payment_requests: Api::StorePaymentRequests.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/pull-payments/3gedGdcqeiFNR5j4SKD6tcD4T1nq
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 23:08:06 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 23:08:06 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,47 @@
---
http_interactions:
- request:
method: get
uri: http://localhost:49392/api/v1/stores/EiGimqCJGwRGkCL8DbdeArVApkvHZdaZARofiSApKdpQ/pull-payments
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 23:04:44 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '2'
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 23:04:45 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/pull-payments
body:
encoding: UTF-8
string: '{"name":"btcpaygem-spec-f0b7d1d54176f6dc19e62ad8f74e5d6e","amount":0.7054181059655215,"currency":"BTC","paymentMethods":["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:
- '128'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sun, 02 Aug 2020 23:07:24 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: '{"startsAt":1596409645,"expiresAt":null,"id":"3gedGdcqeiFNR5j4SKD6tcD4T1nq","name":"btcpaygem-spec-f0b7d1d54176f6dc19e62ad8f74e5d6e","currency":"BTC","amount":"0.7054181059655215","period":null,"archived":false,"viewLink":"http://localhost:49392/pull-payments/3gedGdcqeiFNR5j4SKD6tcD4T1nq"}'
recorded_at: Sun, 02 Aug 2020 23:07:25 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BtcPay::Client::Api::StorePullPayments, :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_pull_payments_payload) }
let(:response) { subject.create(store_id, payload) }
it { expect(response).to be_success }
end
describe 'DELETE #delete' do
let(:request_id) { '3gedGdcqeiFNR5j4SKD6tcD4T1nq' }
let(:response) { subject.delete(store_id, request_id) }
it { expect(response).to be_success }
end
end

View File

@ -12,6 +12,7 @@ RSpec.describe BtcPay::Client::Base do
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.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,12 @@
# frozen_string_literal: true
FactoryBot.define do
factory :store_pull_payments_payload, class: Hash do
name { "btcpaygem-spec-#{SecureRandom.hex}" }
amount { SecureRandom.rand(0.0..1.0) }
currency { 'BTC' }
paymentMethods { %w[BTC] }
initialize_with { attributes }
end
end