paymentrails 0.2.6 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f075f2b06d9c9ce0d11833e11268288a727e10fb79f1ce44a070fbb5d9a55e2b
4
- data.tar.gz: 82eed4cf841783902a59c32edc955b6ec7a0541ab679cb5193e7493c0d00d662
3
+ metadata.gz: de20eb1c3acb982d1306b963f86928eb8ea02f3ecb761867f429604356f09230
4
+ data.tar.gz: 5979525e925822b4e4021b26deee565e1ed1c22871697ae8d9cfc109d4c431e2
5
5
  SHA512:
6
- metadata.gz: 7e6ee052161182aff7763683512b8bb66dc90b79394f19923fb3b53f544e0c6134cf66ab885b7905768d659918a8b812555cc2b7deef2878090434d7ff5c928c
7
- data.tar.gz: 2fc33f250b401fb53d9a3d729798886db4a60a419750fbab5e47f57664aa2a8aa1a496a0aa77e252339abf9475cdb619ab5f961f5b9cdd8045abee49200e9c6c
6
+ metadata.gz: a2cb8e7a7fa9607dc308f89d164d135a281ccd5a528c9b368db1bc01aab28f366ab1a63a0e6ea23886d47950fc9fa7f635981beafc2b9a667eec426aa81c5959
7
+ data.tar.gz: a7d20fa103dd5dc444c4725b07289cad0e5b7ba81a5ae18c4b70ce1b70c413b4fe0b1e9316abb7c63c594f0ffc0aaecfccd59760b82ab745bc9f0a5c610269cc
@@ -14,7 +14,8 @@ module PaymentRails
14
14
  :methods,
15
15
  :detail,
16
16
  :total,
17
- :balances
17
+ :balances,
18
+ :accounts
18
19
  )
19
20
  end
20
21
  end
@@ -24,6 +24,9 @@ module PaymentRails
24
24
  attr_reader :offline_payment
25
25
  attr_writer :offline_payment
26
26
 
27
+ attr_accessor :invoice
28
+ attr_accessor :invoice_payment
29
+
27
30
  def initialize(config)
28
31
  @config = config
29
32
  @client = Client.new(config)
@@ -33,6 +36,8 @@ module PaymentRails
33
36
  @payment = PaymentGateway.new(client)
34
37
  @balance = BalanceGateway.new(client)
35
38
  @offline_payment = OfflinePaymentGateway.new(client)
39
+ @invoice = InvoiceGateway.new(client)
40
+ @invoice_payment = InvoicePaymentGateway.new(client)
36
41
  end
37
42
  end
38
43
  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,13 @@
1
+ module PaymentRails
2
+ class InvoicePayment
3
+ attr_accessor(
4
+ :id,
5
+ :batchId,
6
+ :paymentId,
7
+ :invoiceId,
8
+ :invoiceLineId,
9
+ :amount,
10
+ :invoicePayments
11
+ )
12
+ end
13
+ end
@@ -45,7 +45,8 @@ module PaymentRails
45
45
  :returnedReason,
46
46
  :failureMessage,
47
47
  :merchantId,
48
- :checkNumber
48
+ :checkNumber,
49
+ :forceUsTaxActivity
49
50
  )
50
51
  end
51
52
  end
@@ -35,7 +35,8 @@ module PaymentRails
35
35
  :placeOfBirth,
36
36
  :tags,
37
37
  :taxDeliveryType,
38
- :riskScore
38
+ :riskScore,
39
+ :isPortalUser
39
40
  )
40
41
  end
41
42
  end
@@ -0,0 +1,77 @@
1
+ require_relative '../Client.rb'
2
+ require_relative 'GatewayHelper'
3
+
4
+ module PaymentRails
5
+ class InvoiceGateway
6
+ include GatewayHelper
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def find(body)
13
+ response = @client.post('/v1/invoices/get', body)
14
+ invoice_builder(response)
15
+ end
16
+
17
+ def create(body)
18
+ response = @client.post('/v1/invoices/create', body)
19
+ invoice_builder(response)
20
+ end
21
+
22
+ def create_line(body)
23
+ response = @client.post('/v1/invoices/create-lines', body)
24
+ invoice_builder(response)
25
+ end
26
+
27
+ def search(body)
28
+ response = @client.post('/v1/invoices/search', body)
29
+ invoice_list_builder(response)
30
+ end
31
+
32
+ def update(body)
33
+ @client.post('/v1/invoices/update', body)
34
+ true
35
+ end
36
+
37
+ def update_line(body)
38
+ @client.post('/v1/invoices/update-lines', body)
39
+ true
40
+ end
41
+
42
+ def delete(body)
43
+ @client.post('/v1/invoices/delete', body)
44
+ true
45
+ end
46
+
47
+ def delete_line(body)
48
+ @client.post('/v1/invoices/delete-lines', body)
49
+ true
50
+ end
51
+
52
+ def invoice_builder(response)
53
+ invoice = Invoice.new
54
+ data = JSON.parse(response)
55
+ data.each do |key, value|
56
+ next unless key === 'invoice'
57
+ loosely_hydrate_model(invoice, value)
58
+ end
59
+ invoice
60
+ end
61
+
62
+ def invoice_list_builder(response)
63
+ invoices = []
64
+ data = JSON.parse(response)
65
+
66
+ data.each do |key, value|
67
+ next unless key === 'invoices'
68
+ value.each do |newKey, _newValue|
69
+ invoices.push(
70
+ loosely_hydrate_model(Invoice.new, newKey)
71
+ )
72
+ end
73
+ end
74
+ invoices
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,56 @@
1
+ require_relative '../Client.rb'
2
+ require_relative 'GatewayHelper'
3
+
4
+ module PaymentRails
5
+ class InvoicePaymentGateway
6
+ include GatewayHelper
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def create(body)
13
+ response = @client.post('/v1/invoices/payment/create', body)
14
+ invoice_payment_builder(response)
15
+ end
16
+
17
+ def update(body)
18
+ @client.post('/v1/invoices/payment/update', body)
19
+ true
20
+ end
21
+
22
+ def delete(body)
23
+ @client.post('/v1/invoices/payment/delete', body)
24
+ true
25
+ end
26
+
27
+ def search(body)
28
+ response = @client.post('/v1/invoices/payment/search', body)
29
+ invoice_payments_list_builder(response)
30
+ end
31
+
32
+ def invoice_payment_builder(response)
33
+ invoice_payment = InvoicePayment.new
34
+ data = JSON.parse(response)
35
+ data.each do |key, value|
36
+ next unless key === 'invoicePayment'
37
+ loosely_hydrate_model(invoice_payment, value)
38
+ end
39
+ invoice_payment
40
+ end
41
+
42
+ def invoice_payments_list_builder(response)
43
+ invoice_payments = []
44
+ data = JSON.parse(response)
45
+
46
+ data.each do |key, value|
47
+ next unless key === 'invoicePayments'
48
+ value.each do |newKey, _newValue|
49
+ invoice_payment = loosely_hydrate_model(InvoicePayment.new, newKey)
50
+ invoice_payments.push(invoice_payment)
51
+ end
52
+ end
53
+ invoice_payments
54
+ end
55
+ end
56
+ end
@@ -29,8 +29,15 @@ module PaymentRails
29
29
  true
30
30
  end
31
31
 
32
- def search(page = 1, page_size = 10, term = '')
33
- response = @client.get('/v1/recipients?page=' + page.to_s + '&pageSize=' + page_size.to_s + '&search=' + term)
32
+ # TODO: if we can afford a breaking change ideally these should be kwargs
33
+ def search(page = 1, page_size = 10, prefix_search = '', filters = {})
34
+ query_string = URI.encode_www_form(
35
+ page: page.to_s,
36
+ pageSize: page_size.to_s,
37
+ search: prefix_search,
38
+ **filters
39
+ )
40
+ response = @client.get("/v1/recipients?#{query_string}")
34
41
  recipient_list_builder(response)
35
42
  end
36
43
 
data/lib/paymentrails.rb CHANGED
@@ -7,6 +7,8 @@ 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'
11
+ require 'paymentrails/gateways/InvoicePaymentGateway'
10
12
 
11
13
  require 'paymentrails/Balance'
12
14
  require 'paymentrails/Batch'
@@ -16,6 +18,8 @@ require 'paymentrails/Payment'
16
18
  require 'paymentrails/Recipient'
17
19
  require 'paymentrails/RecipientAccount'
18
20
  require 'paymentrails/OfflinePayment'
21
+ require 'paymentrails/Invoice'
22
+ require 'paymentrails/InvoicePayment'
19
23
 
20
24
  module PaymentRails
21
25
  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.6'
7
+ s.version = '0.2.10'
8
8
  s.homepage = 'https://www.paymentrails.com/'
9
9
  s.email = ['joshua@paymentrails.com']
10
10
  s.license = "MIT"
@@ -0,0 +1,99 @@
1
+ require_relative 'helper'
2
+
3
+ class InvoicePaymentTest < 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
+ assert_equal('open', invoice.status)
37
+
38
+ invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
39
+ assert_not_nil(invoice_line.lines)
40
+ assert_not_nil(invoice_line.lines.first['id'])
41
+
42
+ @client.invoice_payment.create(ids: [invoiceId: invoice.id])
43
+ invoice_payments = @client.invoice_payment.search(invoiceIds: [invoice.id])
44
+ assert_true(invoice_payments.count > 0)
45
+
46
+ findInvoice = @client.invoice.find(invoiceId: invoice.id)
47
+ assert_equal('paid', findInvoice.status)
48
+ end
49
+
50
+ def test_update
51
+ recipient = create_recipient
52
+
53
+ invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
54
+ assert_not_nil(invoice)
55
+ assert_not_nil(invoice.id)
56
+
57
+ invoices = @client.invoice.search({})
58
+ assert_true(invoices.count > 0)
59
+
60
+ invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
61
+ assert_not_nil(invoice_line.lines)
62
+ assert_not_nil(invoice_line.lines.first['id'])
63
+
64
+ invoice_payment = @client.invoice_payment.create(ids: [invoiceId: invoice.id])
65
+ invoice_payments = @client.invoice_payment.search(invoiceIds: [invoice.id])
66
+ assert_true(invoice_payments.count > 0)
67
+ assert_equal('2000.00', invoice_payments.first.amount['value'])
68
+
69
+ response = @client.invoice_payment.update(paymentId: invoice_payment.paymentId, invoiceLineId: invoice_payment.invoicePayments.first['invoiceLineId'], amount: { value: '5000', currency: 'USD' })
70
+ assert_true(response)
71
+ invoice_payments = @client.invoice_payment.search(invoiceIds: [invoice.id])
72
+ assert_true(invoice_payments.count > 0)
73
+ assert_equal('5000.00', invoice_payments.first.amount['value'])
74
+ end
75
+
76
+ def test_delete
77
+ recipient = create_recipient
78
+
79
+ invoice = @client.invoice.create(recipientId: recipient.id, description: 'Integration Test Invoice Create')
80
+ assert_not_nil(invoice)
81
+ assert_not_nil(invoice.id)
82
+
83
+ invoices = @client.invoice.search({})
84
+ assert_true(invoices.count > 0)
85
+
86
+ invoice_line = @client.invoice.create_line(invoiceId: invoice.id, lines: [{ unitAmount: { value: '2000', currency: 'USD' } }])
87
+ assert_not_nil(invoice_line.lines)
88
+ assert_not_nil(invoice_line.lines.first['id'])
89
+
90
+ invoice_payment = @client.invoice_payment.create(ids: [invoiceId: invoice.id])
91
+ invoice_payments = @client.invoice_payment.search(invoiceIds: [invoice.id])
92
+ assert_true(invoice_payments.count > 0)
93
+
94
+ response = @client.invoice_payment.delete(paymentId: invoice_payment.paymentId, invoiceLineIds: [invoice_payment.invoicePayments.first['invoiceLineId']])
95
+ assert_true(response)
96
+ invoice_payments = @client.invoice_payment.search(invoiceIds: [invoice.id])
97
+ assert_true(invoice_payments.count == 0)
98
+ end
99
+ end
@@ -0,0 +1,124 @@
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
+
121
+ response = @client.invoice.delete_line(invoiceId: invoice.id, invoiceLineIds: [invoice_line.lines.first['id']])
122
+ assert_true(response)
123
+ end
124
+ 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.6
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - PaymentRails
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -82,6 +82,8 @@ files:
82
82
  - lib/paymentrails/Configuration.rb
83
83
  - lib/paymentrails/Exceptions.rb
84
84
  - lib/paymentrails/Gateway.rb
85
+ - lib/paymentrails/Invoice.rb
86
+ - lib/paymentrails/InvoicePayment.rb
85
87
  - lib/paymentrails/OfflinePayment.rb
86
88
  - lib/paymentrails/Payment.rb
87
89
  - lib/paymentrails/Recipient.rb
@@ -89,12 +91,16 @@ files:
89
91
  - lib/paymentrails/gateways/BalanceGateway.rb
90
92
  - lib/paymentrails/gateways/BatchGateway.rb
91
93
  - lib/paymentrails/gateways/GatewayHelper.rb
94
+ - lib/paymentrails/gateways/InvoiceGateway.rb
95
+ - lib/paymentrails/gateways/InvoicePaymentGateway.rb
92
96
  - lib/paymentrails/gateways/OfflinePaymentGateway.rb
93
97
  - lib/paymentrails/gateways/PaymentGateway.rb
94
98
  - lib/paymentrails/gateways/RecipientAccountGateway.rb
95
99
  - lib/paymentrails/gateways/RecipientGateway.rb
96
100
  - paymentrails.gemspec
97
101
  - spec/integration/BatchTest.rb
102
+ - spec/integration/InvoicePaymentTest.rb
103
+ - spec/integration/InvoiceTest.rb
98
104
  - spec/integration/RecipientTest.rb
99
105
  - spec/integration/helper.rb
100
106
  - spec/unit/ConfigurationTest.rb
@@ -118,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
124
  - !ruby/object:Gem::Version
119
125
  version: '0'
120
126
  requirements: []
121
- rubygems_version: 3.0.3
127
+ rubygems_version: 3.1.2
122
128
  signing_key:
123
129
  specification_version: 4
124
130
  summary: PaymentRails Ruby SDK