paymentrails 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/paymentrails/Gateway.rb +3 -0
- data/lib/paymentrails/Invoice.rb +22 -0
- data/lib/paymentrails/gateways/InvoiceGateway.rb +78 -0
- data/lib/paymentrails.rb +2 -0
- data/paymentrails.gemspec +1 -1
- data/spec/integration/InvoiceTest.rb +126 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6818800d6c8daa4b91989f23d36b04b5f305b74e4e7c5df76e26eb3d197e0e8a
|
4
|
+
data.tar.gz: a624db096ea5ce2a3ec3d1125b8eda90a6874d0fec8e6bbcd884402f3910e3f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c97846bb5a20a0e01a7fe8a9748835ca338e0003ce97f5785c3c4218d71f7b2043073c7675490be7bdff4df06290648d7cccd6b36de35fc3464f2293e8bb0e43
|
7
|
+
data.tar.gz: 128cfd64efe0cff9403cb197c13a787768e101257b7cbc746cef0851964513bf8ac6bb3b9318ba47e979abdab35952b0266a9227770b4ecd194c2751e58c0ad8
|
data/lib/paymentrails/Gateway.rb
CHANGED
@@ -24,6 +24,8 @@ module PaymentRails
|
|
24
24
|
attr_reader :offline_payment
|
25
25
|
attr_writer :offline_payment
|
26
26
|
|
27
|
+
attr_accessor :invoice
|
28
|
+
|
27
29
|
def initialize(config)
|
28
30
|
@config = config
|
29
31
|
@client = Client.new(config)
|
@@ -33,6 +35,7 @@ module PaymentRails
|
|
33
35
|
@payment = PaymentGateway.new(client)
|
34
36
|
@balance = BalanceGateway.new(client)
|
35
37
|
@offline_payment = OfflinePaymentGateway.new(client)
|
38
|
+
@invoice = InvoiceGateway.new(client)
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PaymentRails
|
2
|
+
class Invoice
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:description,
|
6
|
+
:externalId,
|
7
|
+
:invoiceDate,
|
8
|
+
:dueDate,
|
9
|
+
:invoiceNumber,
|
10
|
+
:status,
|
11
|
+
:releaseAfter,
|
12
|
+
:createdAt,
|
13
|
+
:updatedAt,
|
14
|
+
:totalAmount,
|
15
|
+
:paidAmount,
|
16
|
+
:dueAmount,
|
17
|
+
:tags,
|
18
|
+
:recipientId,
|
19
|
+
:lines,
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
require_relative '../Client.rb'
|
3
|
+
require_relative 'GatewayHelper'
|
4
|
+
|
5
|
+
module PaymentRails
|
6
|
+
class InvoiceGateway
|
7
|
+
include GatewayHelper
|
8
|
+
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(body)
|
14
|
+
response = @client.post('/v1/invoices/get', body)
|
15
|
+
invoice_builder(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(body)
|
19
|
+
response = @client.post('/v1/invoices/create', body)
|
20
|
+
invoice_builder(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_line(body)
|
24
|
+
response = @client.post('/v1/invoices/create-lines', body)
|
25
|
+
invoice_builder(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def search(body)
|
29
|
+
response = @client.post('/v1/invoices/search', body)
|
30
|
+
invoice_list_builder(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update(body)
|
34
|
+
@client.post('/v1/invoices/update', body)
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def update_line(body)
|
39
|
+
@client.post('/v1/invoices/update-lines', body)
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete(body)
|
44
|
+
@client.post('/v1/invoices/delete', body)
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_line(body)
|
49
|
+
@client.post('/v1/invoices/delete-lines', body)
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def invoice_builder(response)
|
54
|
+
invoice = Invoice.new
|
55
|
+
data = JSON.parse(response)
|
56
|
+
data.each do |key, value|
|
57
|
+
next unless key === 'invoice'
|
58
|
+
loosely_hydrate_model(invoice, value)
|
59
|
+
end
|
60
|
+
invoice
|
61
|
+
end
|
62
|
+
|
63
|
+
def invoice_list_builder(response)
|
64
|
+
invoices = []
|
65
|
+
data = JSON.parse(response)
|
66
|
+
|
67
|
+
data.each do |key, value|
|
68
|
+
next unless key === 'invoices'
|
69
|
+
value.each do |newKey, _newValue|
|
70
|
+
invoices.push(
|
71
|
+
loosely_hydrate_model(Invoice.new, newKey)
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
invoices
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/paymentrails.rb
CHANGED
@@ -7,6 +7,7 @@ require 'paymentrails/gateways/PaymentGateway'
|
|
7
7
|
require 'paymentrails/gateways/RecipientGateway'
|
8
8
|
require 'paymentrails/gateways/RecipientAccountGateway'
|
9
9
|
require 'paymentrails/gateways/OfflinePaymentGateway'
|
10
|
+
require 'paymentrails/gateways/InvoiceGateway'
|
10
11
|
|
11
12
|
require 'paymentrails/Balance'
|
12
13
|
require 'paymentrails/Batch'
|
@@ -16,6 +17,7 @@ require 'paymentrails/Payment'
|
|
16
17
|
require 'paymentrails/Recipient'
|
17
18
|
require 'paymentrails/RecipientAccount'
|
18
19
|
require 'paymentrails/OfflinePayment'
|
20
|
+
require 'paymentrails/Invoice'
|
19
21
|
|
20
22
|
module PaymentRails
|
21
23
|
def self.client(key, secret, environment = 'production', **optionals)
|
data/paymentrails.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = "paymentrails"
|
5
5
|
s.summary = "PaymentRails Ruby SDK"
|
6
6
|
s.description = "Ruby SDK for interacting with the PaymentRails API"
|
7
|
-
s.version = '0.2.
|
7
|
+
s.version = '0.2.8'
|
8
8
|
s.homepage = 'https://www.paymentrails.com/'
|
9
9
|
s.email = ['joshua@paymentrails.com']
|
10
10
|
s.license = "MIT"
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class InvoiceTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = PaymentRails.client(
|
6
|
+
ENV.fetch('SANDBOX_API_KEY'),
|
7
|
+
ENV.fetch('SANDBOX_SECRET_KEY'),
|
8
|
+
'production',
|
9
|
+
proxy_uri: ENV['PROXY_URI']
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_recipient
|
14
|
+
uuid = SecureRandom.uuid.to_s
|
15
|
+
recipient = @client.recipient.create(
|
16
|
+
type: 'individual',
|
17
|
+
firstName: 'Tom',
|
18
|
+
lastName: 'Jones',
|
19
|
+
email: 'test.batch' + uuid + '@example.com',
|
20
|
+
address: {
|
21
|
+
street1: '123 Wolfstrasse',
|
22
|
+
city: 'Berlin',
|
23
|
+
country: 'DE',
|
24
|
+
postalCode: '123123'
|
25
|
+
}
|
26
|
+
)
|
27
|
+
@client.recipient_account.create(recipient.id, type: 'bank-transfer', currency: 'EUR', country: 'DE', iban: 'DE89 3704 0044 0532 0130 00')
|
28
|
+
recipient
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create
|
32
|
+
recipient = create_recipient
|
33
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
34
|
+
assert_not_nil(invoice)
|
35
|
+
assert_not_nil(invoice.id)
|
36
|
+
|
37
|
+
invoice = @client.invoice.search({})
|
38
|
+
assert_true(invoice.count > 0)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_create_line
|
42
|
+
recipient = create_recipient
|
43
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
44
|
+
assert_not_nil(invoice)
|
45
|
+
assert_not_nil(invoice.id)
|
46
|
+
assert_equal([], invoice.lines)
|
47
|
+
|
48
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: {value: '2000', currency: 'USD' }}])
|
49
|
+
assert_not_nil(invoice_line.lines)
|
50
|
+
assert_not_nil(invoice_line.lines.first["id"])
|
51
|
+
|
52
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
53
|
+
assert_true(findInvoice.lines.count > 0)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_update
|
57
|
+
recipient = create_recipient
|
58
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
59
|
+
assert_not_nil(invoice)
|
60
|
+
assert_not_nil(invoice.id)
|
61
|
+
|
62
|
+
invoices = @client.invoice.search({})
|
63
|
+
assert_true(invoices.count > 0)
|
64
|
+
|
65
|
+
response = @client.invoice.update(invoiceId: invoice.id, description: 'Integration Test Invoice Update')
|
66
|
+
assert_true(response)
|
67
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
68
|
+
assert_equal('Integration Test Invoice Update', findInvoice.description)
|
69
|
+
assert_equal('open', findInvoice.status)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_update_line
|
73
|
+
recipient = create_recipient
|
74
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
75
|
+
assert_not_nil(invoice)
|
76
|
+
assert_not_nil(invoice.id)
|
77
|
+
assert_equal([], invoice.lines)
|
78
|
+
|
79
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: {value: '2000', currency: 'USD' }}])
|
80
|
+
assert_not_nil(invoice_line.lines)
|
81
|
+
assert_not_nil(invoice_line.lines.first["id"])
|
82
|
+
|
83
|
+
response = @client.invoice.update_line(
|
84
|
+
invoiceId: invoice.id,
|
85
|
+
lines: [{
|
86
|
+
invoiceLineId: invoice_line.lines.first["id"],
|
87
|
+
unitAmount: {value: '3000', currency: 'USD' }
|
88
|
+
}]
|
89
|
+
)
|
90
|
+
assert_true(response)
|
91
|
+
|
92
|
+
findInvoice = @client.invoice.find(invoiceId: invoice.id)
|
93
|
+
assert_equal('3000.00', findInvoice.lines.first["unitAmount"]["value"])
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_delete
|
97
|
+
recipient = create_recipient
|
98
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
99
|
+
assert_not_nil(invoice)
|
100
|
+
assert_not_nil(invoice.id)
|
101
|
+
|
102
|
+
invoices = @client.invoice.search({})
|
103
|
+
assert_true(invoices.count > 0)
|
104
|
+
|
105
|
+
response = @client.invoice.delete(invoiceIds: invoices.map(&:id))
|
106
|
+
assert_true(response)
|
107
|
+
|
108
|
+
final_invoices = @client.invoice.search({})
|
109
|
+
assert_true(final_invoices.count == 0)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_delete_line
|
113
|
+
recipient = create_recipient
|
114
|
+
invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
|
115
|
+
assert_not_nil(invoice)
|
116
|
+
assert_not_nil(invoice.id)
|
117
|
+
assert_equal([], invoice.lines)
|
118
|
+
|
119
|
+
invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: {value: '2000', currency: 'USD' }}])
|
120
|
+
assert_not_nil(invoice_line.lines)
|
121
|
+
assert_not_nil(invoice_line.lines.first["id"])
|
122
|
+
|
123
|
+
response = @client.invoice.delete_line(invoiceId: invoice.id, invoiceLineIds: [invoice_line.lines.first['id']])
|
124
|
+
assert_true(response)
|
125
|
+
end
|
126
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paymentrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PaymentRails
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/paymentrails/Configuration.rb
|
83
83
|
- lib/paymentrails/Exceptions.rb
|
84
84
|
- lib/paymentrails/Gateway.rb
|
85
|
+
- lib/paymentrails/Invoice.rb
|
85
86
|
- lib/paymentrails/OfflinePayment.rb
|
86
87
|
- lib/paymentrails/Payment.rb
|
87
88
|
- lib/paymentrails/Recipient.rb
|
@@ -89,12 +90,14 @@ files:
|
|
89
90
|
- lib/paymentrails/gateways/BalanceGateway.rb
|
90
91
|
- lib/paymentrails/gateways/BatchGateway.rb
|
91
92
|
- lib/paymentrails/gateways/GatewayHelper.rb
|
93
|
+
- lib/paymentrails/gateways/InvoiceGateway.rb
|
92
94
|
- lib/paymentrails/gateways/OfflinePaymentGateway.rb
|
93
95
|
- lib/paymentrails/gateways/PaymentGateway.rb
|
94
96
|
- lib/paymentrails/gateways/RecipientAccountGateway.rb
|
95
97
|
- lib/paymentrails/gateways/RecipientGateway.rb
|
96
98
|
- paymentrails.gemspec
|
97
99
|
- spec/integration/BatchTest.rb
|
100
|
+
- spec/integration/InvoiceTest.rb
|
98
101
|
- spec/integration/RecipientTest.rb
|
99
102
|
- spec/integration/helper.rb
|
100
103
|
- spec/unit/ConfigurationTest.rb
|