paymentrails 0.2.9 → 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: 57b1a2026b6e8965b49501ac1742aece5914a1ed4b28c2dc10a1919df9f77523
4
- data.tar.gz: '04910c8e5f5555c43e3af1866e6ca9365eed0dc5ba9184dd0ac6209466a8a6a2'
3
+ metadata.gz: de20eb1c3acb982d1306b963f86928eb8ea02f3ecb761867f429604356f09230
4
+ data.tar.gz: 5979525e925822b4e4021b26deee565e1ed1c22871697ae8d9cfc109d4c431e2
5
5
  SHA512:
6
- metadata.gz: c36e9ea9b5a1ecb4e8e2aeeaa0795267349a310b502c63cb5fd3acd7eb62ac67fa776520244fe15a6f3327c600126f7e22becd15b03e7267aae24a58057cc87c
7
- data.tar.gz: 41b91895e01d72f475f503b62ae834d7c979749dd1ccc53825fab01bd2d186324e0090a096673faaf488bc8a17b2c221ec8a745bba3d9e40d663b722b084f457
6
+ metadata.gz: a2cb8e7a7fa9607dc308f89d164d135a281ccd5a528c9b368db1bc01aab28f366ab1a63a0e6ea23886d47950fc9fa7f635981beafc2b9a667eec426aa81c5959
7
+ data.tar.gz: a7d20fa103dd5dc444c4725b07289cad0e5b7ba81a5ae18c4b70ce1b70c413b4fe0b1e9316abb7c63c594f0ffc0aaecfccd59760b82ab745bc9f0a5c610269cc
@@ -25,6 +25,7 @@ module PaymentRails
25
25
  attr_writer :offline_payment
26
26
 
27
27
  attr_accessor :invoice
28
+ attr_accessor :invoice_payment
28
29
 
29
30
  def initialize(config)
30
31
  @config = config
@@ -36,6 +37,7 @@ module PaymentRails
36
37
  @balance = BalanceGateway.new(client)
37
38
  @offline_payment = OfflinePaymentGateway.new(client)
38
39
  @invoice = InvoiceGateway.new(client)
40
+ @invoice_payment = InvoicePaymentGateway.new(client)
39
41
  end
40
42
  end
41
43
  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
@@ -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
data/lib/paymentrails.rb CHANGED
@@ -8,6 +8,7 @@ require 'paymentrails/gateways/RecipientGateway'
8
8
  require 'paymentrails/gateways/RecipientAccountGateway'
9
9
  require 'paymentrails/gateways/OfflinePaymentGateway'
10
10
  require 'paymentrails/gateways/InvoiceGateway'
11
+ require 'paymentrails/gateways/InvoicePaymentGateway'
11
12
 
12
13
  require 'paymentrails/Balance'
13
14
  require 'paymentrails/Batch'
@@ -18,6 +19,7 @@ require 'paymentrails/Recipient'
18
19
  require 'paymentrails/RecipientAccount'
19
20
  require 'paymentrails/OfflinePayment'
20
21
  require 'paymentrails/Invoice'
22
+ require 'paymentrails/InvoicePayment'
21
23
 
22
24
  module PaymentRails
23
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.9'
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
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.9
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: 2022-02-03 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
@@ -83,6 +83,7 @@ files:
83
83
  - lib/paymentrails/Exceptions.rb
84
84
  - lib/paymentrails/Gateway.rb
85
85
  - lib/paymentrails/Invoice.rb
86
+ - lib/paymentrails/InvoicePayment.rb
86
87
  - lib/paymentrails/OfflinePayment.rb
87
88
  - lib/paymentrails/Payment.rb
88
89
  - lib/paymentrails/Recipient.rb
@@ -91,12 +92,14 @@ files:
91
92
  - lib/paymentrails/gateways/BatchGateway.rb
92
93
  - lib/paymentrails/gateways/GatewayHelper.rb
93
94
  - lib/paymentrails/gateways/InvoiceGateway.rb
95
+ - lib/paymentrails/gateways/InvoicePaymentGateway.rb
94
96
  - lib/paymentrails/gateways/OfflinePaymentGateway.rb
95
97
  - lib/paymentrails/gateways/PaymentGateway.rb
96
98
  - lib/paymentrails/gateways/RecipientAccountGateway.rb
97
99
  - lib/paymentrails/gateways/RecipientGateway.rb
98
100
  - paymentrails.gemspec
99
101
  - spec/integration/BatchTest.rb
102
+ - spec/integration/InvoicePaymentTest.rb
100
103
  - spec/integration/InvoiceTest.rb
101
104
  - spec/integration/RecipientTest.rb
102
105
  - spec/integration/helper.rb