paymentrails 0.2.4 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paymentrails/Batch.rb +16 -2
- data/lib/paymentrails/BatchSummary.rb +18 -3
- data/lib/paymentrails/Client.rb +2 -2
- data/lib/paymentrails/Configuration.rb +1 -1
- data/lib/paymentrails/Exceptions.rb +1 -1
- data/lib/paymentrails/Gateway.rb +3 -0
- data/lib/paymentrails/Invoice.rb +22 -0
- data/lib/paymentrails/OfflinePayment.rb +19 -2
- data/lib/paymentrails/Payment.rb +3 -1
- data/lib/paymentrails/Recipient.rb +38 -2
- data/lib/paymentrails/RecipientAccount.rb +27 -3
- data/lib/paymentrails/gateways/BalanceGateway.rb +1 -1
- data/lib/paymentrails/gateways/BatchGateway.rb +9 -12
- data/lib/paymentrails/gateways/GatewayHelper.rb +15 -0
- data/lib/paymentrails/gateways/InvoiceGateway.rb +78 -0
- data/lib/paymentrails/gateways/OfflinePaymentGateway.rb +6 -8
- data/lib/paymentrails/gateways/PaymentGateway.rb +6 -8
- data/lib/paymentrails/gateways/RecipientAccountGateway.rb +6 -8
- data/lib/paymentrails/gateways/RecipientGateway.rb +15 -10
- data/lib/paymentrails.rb +3 -1
- data/paymentrails.gemspec +2 -2
- data/spec/integration/InvoiceTest.rb +126 -0
- metadata +9 -5
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/Batch.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class Batch
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:amount,
|
6
|
+
:completedAt,
|
7
|
+
:createdAt,
|
8
|
+
:currency,
|
9
|
+
:description,
|
10
|
+
:sentAt,
|
11
|
+
:status,
|
12
|
+
:totalPayments,
|
13
|
+
:updatedAt,
|
14
|
+
:quoteExpiredAt,
|
15
|
+
:payments,
|
16
|
+
:tags,
|
17
|
+
:coverFees
|
18
|
+
)
|
5
19
|
end
|
6
20
|
end
|
@@ -1,6 +1,21 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class BatchSummary
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:amount,
|
6
|
+
:completedAt,
|
7
|
+
:createdAt,
|
8
|
+
:currency,
|
9
|
+
:description,
|
10
|
+
:sentAt,
|
11
|
+
:status,
|
12
|
+
:totalPayments,
|
13
|
+
:updatedAt,
|
14
|
+
:methods,
|
15
|
+
:detail,
|
16
|
+
:total,
|
17
|
+
:balances,
|
18
|
+
:accounts
|
19
|
+
)
|
5
20
|
end
|
6
|
-
end
|
21
|
+
end
|
data/lib/paymentrails/Client.rb
CHANGED
@@ -79,11 +79,11 @@ module PaymentRails
|
|
79
79
|
when '401'
|
80
80
|
raise AuthenticationError, message
|
81
81
|
when '403'
|
82
|
-
raise
|
82
|
+
raise AuthorizationError, message
|
83
83
|
when '404'
|
84
84
|
raise NotFoundError, message
|
85
85
|
when '429'
|
86
|
-
raise TooManyRequestsError message
|
86
|
+
raise TooManyRequestsError, message
|
87
87
|
when '500'
|
88
88
|
raise ServerError, message
|
89
89
|
when '503'
|
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
|
@@ -1,6 +1,23 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class OfflinePayment
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:recipientId,
|
6
|
+
:externalId,
|
7
|
+
:memo,
|
8
|
+
:tags,
|
9
|
+
:taxReportable,
|
10
|
+
:category,
|
11
|
+
:amount,
|
12
|
+
:currency,
|
13
|
+
:withholdingAmount,
|
14
|
+
:withholdingCurrency,
|
15
|
+
:processedAt,
|
16
|
+
:equivalentWithholdingAmount,
|
17
|
+
:equivalentWithholdingCurrency,
|
18
|
+
:updatedAt,
|
19
|
+
:createdAt,
|
20
|
+
:deletedAt
|
21
|
+
)
|
5
22
|
end
|
6
23
|
end
|
data/lib/paymentrails/Payment.rb
CHANGED
@@ -1,6 +1,42 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class Recipient
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:routeType,
|
6
|
+
:estimatedFees,
|
7
|
+
:referenceId,
|
8
|
+
:email,
|
9
|
+
:name,
|
10
|
+
:lastName,
|
11
|
+
:firstName,
|
12
|
+
:type,
|
13
|
+
:taxType,
|
14
|
+
:status,
|
15
|
+
:language,
|
16
|
+
:complianceStatus,
|
17
|
+
:dob,
|
18
|
+
:passport,
|
19
|
+
:updatedAt,
|
20
|
+
:createdAt,
|
21
|
+
:gravatarUrl,
|
22
|
+
:governmentId,
|
23
|
+
:ssn,
|
24
|
+
:primaryCurrency,
|
25
|
+
:merchantId,
|
26
|
+
:payout,
|
27
|
+
:compliance,
|
28
|
+
:accounts,
|
29
|
+
:address,
|
30
|
+
:taxWithholdingPercentage,
|
31
|
+
:taxForm,
|
32
|
+
:taxFormStatus,
|
33
|
+
:inactiveReasons,
|
34
|
+
:payoutMethod,
|
35
|
+
:placeOfBirth,
|
36
|
+
:tags,
|
37
|
+
:taxDeliveryType,
|
38
|
+
:riskScore,
|
39
|
+
:isPortalUser
|
40
|
+
)
|
5
41
|
end
|
6
42
|
end
|
@@ -1,6 +1,30 @@
|
|
1
1
|
module PaymentRails
|
2
2
|
class RecipientAccount
|
3
|
-
attr_accessor
|
4
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:id,
|
5
|
+
:primary,
|
6
|
+
:currency,
|
7
|
+
:recipientAccountId,
|
8
|
+
:recipientId,
|
9
|
+
:recipientReferenceId,
|
10
|
+
:routeType,
|
11
|
+
:recipientFees,
|
12
|
+
:emailAddress,
|
13
|
+
:country,
|
14
|
+
:type,
|
15
|
+
:iban,
|
16
|
+
:accountNum,
|
17
|
+
:accountHolderName,
|
18
|
+
:swiftBic,
|
19
|
+
:branchId,
|
20
|
+
:bankId,
|
21
|
+
:bankName,
|
22
|
+
:bankAddress,
|
23
|
+
:bankCity,
|
24
|
+
:bankRegionCode,
|
25
|
+
:bankPostalCode,
|
26
|
+
:status,
|
27
|
+
:disabledAt
|
28
|
+
)
|
5
29
|
end
|
6
|
-
end
|
30
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class BatchGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -51,9 +54,7 @@ module PaymentRails
|
|
51
54
|
data = JSON.parse(response)
|
52
55
|
data.each do |key, value|
|
53
56
|
next unless key === 'batch'
|
54
|
-
|
55
|
-
batch.send("#{newKey}=", newValue)
|
56
|
-
end
|
57
|
+
loosely_hydrate_model(batch, value)
|
57
58
|
end
|
58
59
|
batch
|
59
60
|
end
|
@@ -64,9 +65,7 @@ module PaymentRails
|
|
64
65
|
data = JSON.parse(response)
|
65
66
|
data.each do |key, value|
|
66
67
|
next unless key === 'batchSummary'
|
67
|
-
|
68
|
-
summary.send("#{newKey}=", newValue)
|
69
|
-
end
|
68
|
+
loosely_hydrate_model(summary, value)
|
70
69
|
end
|
71
70
|
summary
|
72
71
|
end
|
@@ -78,14 +77,12 @@ module PaymentRails
|
|
78
77
|
data.each do |key, value|
|
79
78
|
next unless key === 'batches'
|
80
79
|
value.each do |newKey, _newValue|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
batches.push(batch)
|
80
|
+
batches.push(
|
81
|
+
loosely_hydrate_model(Batch.new, newKey)
|
82
|
+
)
|
86
83
|
end
|
87
84
|
end
|
88
85
|
batches
|
89
86
|
end
|
90
87
|
end
|
91
|
-
end
|
88
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PaymentRails
|
2
|
+
module GatewayHelper
|
3
|
+
def loosely_hydrate_model(klass_instance, attributes)
|
4
|
+
attributes.each do |k, v|
|
5
|
+
begin
|
6
|
+
klass_instance.send("#{k}=", v)
|
7
|
+
rescue NoMethodError
|
8
|
+
warn "[PaymentRails] Unknown attribute #{k} for class #{klass_instance.class.name}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
klass_instance
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class OfflinePaymentGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -36,9 +39,7 @@ module PaymentRails
|
|
36
39
|
data = JSON.parse(response)
|
37
40
|
data.each do |key, value|
|
38
41
|
next unless key === 'offlinePayment'
|
39
|
-
|
40
|
-
offline_payment.send("#{opKey}=", opValue)
|
41
|
-
end
|
42
|
+
loosely_hydrate_model(offline_payment, value)
|
42
43
|
end
|
43
44
|
offline_payment
|
44
45
|
end
|
@@ -50,14 +51,11 @@ module PaymentRails
|
|
50
51
|
data.each do |key, value|
|
51
52
|
next unless key === 'offlinePayments'
|
52
53
|
value.each do |newKey, _newValue|
|
53
|
-
offline_payment = OfflinePayment.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
offline_payment.send("#{key1}=", value1)
|
56
|
-
end
|
54
|
+
offline_payment = loosely_hydrate_model(OfflinePayment.new, newKey)
|
57
55
|
offline_payments.push(offline_payment)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
offline_payments
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class PaymentGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -36,9 +39,7 @@ module PaymentRails
|
|
36
39
|
data = JSON.parse(response)
|
37
40
|
data.each do |key, value|
|
38
41
|
next unless key === 'payment'
|
39
|
-
|
40
|
-
payment.send("#{recipKey}=", recipValue)
|
41
|
-
end
|
42
|
+
loosely_hydrate_model(payment, value)
|
42
43
|
end
|
43
44
|
payment
|
44
45
|
end
|
@@ -50,14 +51,11 @@ module PaymentRails
|
|
50
51
|
data.each do |key, value|
|
51
52
|
next unless key === 'payments'
|
52
53
|
value.each do |newKey, _newValue|
|
53
|
-
payment = Payment.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
payment.send("#{key1}=", value1)
|
56
|
-
end
|
54
|
+
payment = loosely_hydrate_model(Payment.new, newKey)
|
57
55
|
payments.push(payment)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
payments
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class RecipientAccountGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -36,9 +39,7 @@ module PaymentRails
|
|
36
39
|
data = JSON.parse(response)
|
37
40
|
data.each do |key, value|
|
38
41
|
next unless key === 'account'
|
39
|
-
|
40
|
-
recipient_account.send("#{recipKey}=", recipValue)
|
41
|
-
end
|
42
|
+
loosely_hydrate_model(recipient_account, value)
|
42
43
|
end
|
43
44
|
recipient_account
|
44
45
|
end
|
@@ -50,14 +51,11 @@ module PaymentRails
|
|
50
51
|
data.each do |key, value|
|
51
52
|
next unless key === 'accounts'
|
52
53
|
value.each do |newKey, _newValue|
|
53
|
-
recipient_account = RecipientAccount.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
recipient_account.send("#{key1}=", value1)
|
56
|
-
end
|
54
|
+
recipient_account = loosely_hydrate_model(RecipientAccount.new, newKey)
|
57
55
|
recipient_accounts.push(recipient_account)
|
58
56
|
end
|
59
57
|
end
|
60
58
|
recipient_accounts
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative '../Client.rb'
|
2
|
+
require_relative 'GatewayHelper'
|
2
3
|
|
3
4
|
module PaymentRails
|
4
5
|
class RecipientGateway
|
6
|
+
include GatewayHelper
|
7
|
+
|
5
8
|
def initialize(client)
|
6
9
|
@client = client
|
7
10
|
end
|
@@ -26,8 +29,15 @@ module PaymentRails
|
|
26
29
|
true
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
|
-
|
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}")
|
31
41
|
recipient_list_builder(response)
|
32
42
|
end
|
33
43
|
|
@@ -36,9 +46,7 @@ module PaymentRails
|
|
36
46
|
data = JSON.parse(response)
|
37
47
|
data.each do |key, value|
|
38
48
|
next unless key === 'recipient'
|
39
|
-
|
40
|
-
recipient.send("#{recipKey}=", recipValue)
|
41
|
-
end
|
49
|
+
loosely_hydrate_model(recipient, value)
|
42
50
|
end
|
43
51
|
recipient
|
44
52
|
end
|
@@ -50,14 +58,11 @@ module PaymentRails
|
|
50
58
|
data.each do |key, value|
|
51
59
|
next unless key === 'recipients'
|
52
60
|
value.each do |newKey, _newValue|
|
53
|
-
recipient = Recipient.new
|
54
|
-
newKey.each do |key1, value1|
|
55
|
-
recipient.send("#{key1}=", value1)
|
56
|
-
end
|
61
|
+
recipient = loosely_hydrate_model(Recipient.new, newKey)
|
57
62
|
recipients.push(recipient)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
recipients
|
61
66
|
end
|
62
67
|
end
|
63
|
-
end
|
68
|
+
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,9 +17,10 @@ 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)
|
22
24
|
Gateway.new(Configuration.new(key, secret, environment, optionals))
|
23
25
|
end
|
24
|
-
end
|
26
|
+
end
|
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"
|
@@ -13,6 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.required_ruby_version = '>= 2.4'
|
14
14
|
s.add_development_dependency 'dotenv', '~> 2'
|
15
15
|
s.add_development_dependency 'rake', '~> 12'
|
16
|
-
s.add_development_dependency "rubocop", '~> 0.77'
|
16
|
+
s.add_development_dependency "rubocop", '~> 0.77.0'
|
17
17
|
s.add_development_dependency 'test-unit', '~> 3'
|
18
18
|
end
|
@@ -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
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.77.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.77.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: test-unit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,18 +82,22 @@ 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
|
88
89
|
- lib/paymentrails/RecipientAccount.rb
|
89
90
|
- lib/paymentrails/gateways/BalanceGateway.rb
|
90
91
|
- lib/paymentrails/gateways/BatchGateway.rb
|
92
|
+
- lib/paymentrails/gateways/GatewayHelper.rb
|
93
|
+
- lib/paymentrails/gateways/InvoiceGateway.rb
|
91
94
|
- lib/paymentrails/gateways/OfflinePaymentGateway.rb
|
92
95
|
- lib/paymentrails/gateways/PaymentGateway.rb
|
93
96
|
- lib/paymentrails/gateways/RecipientAccountGateway.rb
|
94
97
|
- lib/paymentrails/gateways/RecipientGateway.rb
|
95
98
|
- paymentrails.gemspec
|
96
99
|
- spec/integration/BatchTest.rb
|
100
|
+
- spec/integration/InvoiceTest.rb
|
97
101
|
- spec/integration/RecipientTest.rb
|
98
102
|
- spec/integration/helper.rb
|
99
103
|
- spec/unit/ConfigurationTest.rb
|
@@ -117,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
121
|
- !ruby/object:Gem::Version
|
118
122
|
version: '0'
|
119
123
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
124
|
+
rubygems_version: 3.1.2
|
121
125
|
signing_key:
|
122
126
|
specification_version: 4
|
123
127
|
summary: PaymentRails Ruby SDK
|