add store invoice specs. update readme.

add store invoice endpoints.

update repo info, docker images.

add store_id to config.

Co-authored-by: snogrammer <btcpay-gem@snogram.com>
Reviewed-on: https://code.snogrammer.com/snogrammer/btcpay/pulls/1
This commit is contained in:
snogrammer 2020-11-21 14:51:14 -07:00
parent 7fbc4b935c
commit d3c5e2a2e7
19 changed files with 440 additions and 12 deletions

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
btcpay (0.1.0)
btcpay (0.1.2)
activesupport (> 5)
multi_json (~> 1.15)
rest-client (~> 2.1)

View File

@ -96,6 +96,15 @@ All endpoints are accessed via namespaced Api resource. Example: `client.users.c
1. `DELETE #delete(store_id)`
1. `PUT #update(store_id, payload)`
- ##### Invoices:
1. `GET #all(store_id)`
1. `POST #create(store_id, payload)`
1. `GET #get(store_id, invoice_id)`
1. `DELETE #delete(store_id, invoice_id)`
1. `POST #update_status(store_id, invoice_id, payload, status)`
1. `POST #unarchive(store_id, invoice_id)`
- ##### Payment Requests:
1. `GET #all(store_id)`

View File

@ -2,7 +2,7 @@
require_relative 'lib/btcpay/version'
Gem::Specification.new do |spec|
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
spec.name = 'btcpay'
spec.version = BtcPay::VERSION
spec.authors = ['snogrammer']
@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://gitlab.com/snogrammer/btcpay'
spec.metadata['changelog_uri'] = 'https://gitlab.com/snogrammer/btcpay/CHANGELOG.md'
spec.metadata['source_code_uri'] = 'https://code.snogrammer.com/snogrammer/btcpay'
spec.metadata['changelog_uri'] = "#{spec.metadata['source_code_uri']}/CHANGELOG.md"
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.

View File

@ -5,7 +5,7 @@ services:
bitcoind:
container_name: bitcoind
restart: unless-stopped
image: btcpayserver/bitcoin:0.19.0.1
image: btcpayserver/bitcoin:0.20.1
environment:
BITCOIN_NETWORK: regtest
BITCOIN_EXTRA_ARGS: |
@ -31,7 +31,7 @@ services:
nbxplorer:
container_name: nbxplorer
restart: unless-stopped
image: nicolasdorier/nbxplorer:2.1.34
image: nicolasdorier/nbxplorer:2.1.46
ports:
- "32838:32838"
environment:
@ -53,7 +53,7 @@ services:
btcpay:
container_name: btcpay
restart: unless-stopped
image: btcpayserver/btcpayserver:1.0.5.2
image: btcpayserver/btcpayserver:1.0.5.9
ports:
- "49392:49392"
environment:
@ -118,7 +118,7 @@ services:
btcpay_db:
container_name: btcpay_db
restart: unless-stopped
image: postgres:11.5-alpine
image: postgres:13-alpine
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password

View File

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

View File

@ -39,6 +39,10 @@ module BtcPay
##
# services
##
def invoices
@invoices ||= Api::StoreInvoices.new(client: client)
end
def payment_requests
@payment_requests ||= Api::StorePaymentRequests.new(client: client)
end

View File

@ -0,0 +1,54 @@
# frozen_string_literal: true
module BtcPay
module Client
module Api
class StoreInvoices < Base
PATH = '/stores/:store_id/invoices'
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Invoices_GetInvoices
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/Invoices_CreateInvoice
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/Invoices_GetInvoice
def get(store_id, invoice_id, **opts)
client.get(store_path(store_id, invoice_id), options: opts)
end
alias find get
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Invoices_ArchiveInvoice
def delete(store_id, invoice_id, **opts)
client.delete(store_path(store_id, invoice_id), options: opts)
end
alias archive delete
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Invoices_MarkInvoiceStatus
# @see https://github.com/btcpayserver/btcpayserver/blob/master/BTCPayServer.Client/Models/InvoiceStatus.cs
def update_status(store_id, invoice_id, status = 'Complete', **opts)
client.post(store_path(store_id, invoice_id, 'status'), payload: { status: status }, options: opts)
end
# @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Invoices_UnarchiveInvoice
def unarchive(store_id, invoice_id, **opts)
client.post(store_path(store_id, invoice_id, 'unarchive'), payload: {}, options: opts)
end
protected
def set_base_path
@base_path = PATH.dup
end
end
end
end
end

View File

@ -6,11 +6,12 @@ module BtcPay
AUTH_TOKEN_TYPE = 'token'
BASIC_TOKEN_TYPE = 'Basic'
attr_reader :authorization, :auth_token, :basic_auth_token, :base_url, :user_agent
attr_reader :authorization, :auth_token, :basic_auth_token, :base_url, :user_agent, :store_id
def initialize(**kwargs)
@base_url = load_url(kwargs[:base_url])
@user_agent = kwargs[:user_agent] || "btcpay_ruby/#{BtcPay::VERSION}"
@store_id = kwargs[:store_id]
load_auth_token(kwargs)
set_authorization
@ -21,7 +22,8 @@ module BtcPay
auth_token: auth_token,
basic_auth_token: basic_auth_token,
base_url: base_url,
user_agent: user_agent
user_agent: user_agent,
store_id: store_id
}.compact
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module BtcPay
VERSION = '0.1.1'
VERSION = '0.1.2'
end

View File

@ -2,7 +2,7 @@
RSpec.describe BtcPay do
it 'has a version number' do
expect(BtcPay::VERSION).to eq('0.1.1')
expect(BtcPay::VERSION).to eq('0.1.2')
end
describe '.new' do

View File

@ -0,0 +1,45 @@
---
http_interactions:
- request:
method: delete
uri: http://localhost:49392/api/v1/stores/Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh/invoices/PA1t8RJWYq78rTAeGBZmkJ
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.2
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 8662bc1847a02b460e71d20d8408da73a877a127
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sat, 21 Nov 2020 21:37:43 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: Sat, 21 Nov 2020 21:37:44 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/Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh/invoices
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.2
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 8662bc1847a02b460e71d20d8408da73a877a127
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sat, 07 Nov 2020 23:05:00 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: Sat, 07 Nov 2020 23:05:00 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/Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh/invoices/PA1t8RJWYq78rTAeGBZmkJ
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.2
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 8662bc1847a02b460e71d20d8408da73a877a127
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sat, 21 Nov 2020 21:09:12 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '374'
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":"PA1t8RJWYq78rTAeGBZmkJ","status":"New","additionalStatus":"None","monitoringExpiration":1606079998,"expirationTime":1605993598,"createdTime":1605992698,"amount":0.00005848597885459439,"currency":"btc","metadata":{"orderId":"12345"},"checkout":{"speedPolicy":"HighSpeed","paymentMethods":["BTC"],"expirationMinutes":15,"monitoringMinutes":1440,"paymentTolerance":0.0}}'
recorded_at: Sat, 21 Nov 2020 21:09:13 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/Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh/invoices
body:
encoding: UTF-8
string: '{"amount":0.014421449041276548,"currency":"btc","metadata":{"orderId":12345},"checkout":{"speedPolicy":"HighSpeed","paymentMethods":["BTC"],"expirationMinutes":15,"monitoringMinutes":1440,"paymentTolerance":0}}'
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.2
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 8662bc1847a02b460e71d20d8408da73a877a127
Content-Length:
- '210'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sat, 21 Nov 2020 21:08:49 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '372'
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":"XbAeqLEdarysaPZVfLkNvG","status":"New","additionalStatus":"None","monitoringExpiration":1606080230,"expirationTime":1605993830,"createdTime":1605992930,"amount":0.014421449041276548,"currency":"btc","metadata":{"orderId":"12345"},"checkout":{"speedPolicy":"HighSpeed","paymentMethods":["BTC"],"expirationMinutes":15,"monitoringMinutes":1440,"paymentTolerance":0.0}}'
recorded_at: Sat, 21 Nov 2020 21:08:50 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/Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh/invoices/PA1t8RJWYq78rTAeGBZmkJ/unarchive
body:
encoding: UTF-8
string: "{}"
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.2
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 8662bc1847a02b460e71d20d8408da73a877a127
Content-Length:
- '2'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sat, 21 Nov 2020 21:37:18 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '380'
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":"PA1t8RJWYq78rTAeGBZmkJ","status":"Invalid","additionalStatus":"Marked","monitoringExpiration":1606079998,"expirationTime":1605993598,"createdTime":1605992698,"amount":0.00005848597885459439,"currency":"btc","metadata":{"orderId":"12345"},"checkout":{"speedPolicy":"HighSpeed","paymentMethods":["BTC"],"expirationMinutes":15,"monitoringMinutes":1440,"paymentTolerance":0.0}}'
recorded_at: Sat, 21 Nov 2020 21:37:19 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/Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh/invoices/PA1t8RJWYq78rTAeGBZmkJ/status
body:
encoding: UTF-8
string: '{"status":"Invalid"}'
headers:
Accept:
- application/json
User-Agent:
- btcpay_ruby/0.1.2
Content-Type:
- application/json
Accept-Encoding:
- deflate, gzip
Authorization:
- token 8662bc1847a02b460e71d20d8408da73a877a127
Content-Length:
- '20'
Host:
- localhost:49392
response:
status:
code: 200
message: OK
headers:
Date:
- Sat, 21 Nov 2020 21:23:02 GMT
Content-Type:
- application/json; charset=utf-8
Server:
- Kestrel
Content-Length:
- '380'
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":"PA1t8RJWYq78rTAeGBZmkJ","status":"Invalid","additionalStatus":"Marked","monitoringExpiration":1606079998,"expirationTime":1605993598,"createdTime":1605992698,"amount":0.00005848597885459439,"currency":"btc","metadata":{"orderId":"12345"},"checkout":{"speedPolicy":"HighSpeed","paymentMethods":["BTC"],"expirationMinutes":15,"monitoringMinutes":1440,"paymentTolerance":0.0}}'
recorded_at: Sat, 21 Nov 2020 21:23:02 GMT
recorded_with: VCR 6.0.0

View File

@ -0,0 +1,51 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BtcPay::Client::Api::StoreInvoices, :vcr do
let(:store_id) { 'Ej6iMSnPKNyh9mEnTE7FmP4CH8pQ689CnNeQouNDShzh' }
let(:invoice_id) { 'PA1t8RJWYq78rTAeGBZmkJ' }
let(:client) do
config = build(:config, auth_token: '8662bc1847a02b460e71d20d8408da73a877a127')
build(:client, config: config)
end
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_invoices_payload) }
let(:response) { subject.create(store_id, payload) }
it { expect(response).to be_success }
end
describe 'GET #get' do
let(:response) { subject.get(store_id, invoice_id) }
it { expect(response).to be_success }
end
describe 'DELETE #delete' do
let(:response) { subject.delete(store_id, invoice_id) }
it { expect(response).to be_success }
end
describe 'POST #update_status' do
let(:response) { subject.update_status(store_id, invoice_id, 'Invalid') }
it { expect(response).to be_success }
end
describe 'POST #unarchive' do
let(:response) { subject.unarchive(store_id, invoice_id) }
it { expect(response).to be_success }
end
end

View File

@ -14,6 +14,7 @@ RSpec.describe BtcPay::Client::Base do
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.invoices).to be_a(BtcPay::Client::Api::StoreInvoices) }
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,20 @@
# frozen_string_literal: true
FactoryBot.define do
factory :store_invoices_payload, class: Hash do
amount { SecureRandom.rand(0.0000..0.10000) }
currency { 'btc' }
metadata { { orderId: 12_345 } }
checkout do
{
speedPolicy: 'HighSpeed',
paymentMethods: ['BTC'],
expirationMinutes: 15,
monitoringMinutes: 1440,
paymentTolerance: 0
}
end
initialize_with { attributes }
end
end