payload-api 0.4.1 → 0.5.0
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/.github/workflows/test.yml +2 -0
- data/README.md +23 -2
- data/lib/payload/arm/object.rb +8 -0
- data/lib/payload/arm/request.rb +13 -1
- data/lib/payload/arm/session.rb +6 -6
- data/lib/payload/objects.rb +73 -18
- data/lib/payload/version.rb +1 -1
- data/lib/payload.rb +15 -5
- data/spec/objects/v1/access_token_spec.rb +19 -0
- data/spec/objects/v1/account_spec.rb +97 -0
- data/spec/objects/v1/billing_spec.rb +54 -0
- data/spec/objects/v1/invoice_spec.rb +53 -0
- data/spec/objects/v1/payment_link_spec.rb +50 -0
- data/spec/objects/v1/payment_method_spec.rb +106 -0
- data/spec/objects/{payment_spec.rb → v1/payment_spec.rb} +5 -6
- data/spec/objects/v1/session_spec.rb +89 -0
- data/spec/objects/v1/transaction_spec.rb +55 -0
- data/spec/objects/v2/account_spec.rb +211 -0
- data/spec/objects/v2/invoice_spec.rb +53 -0
- data/spec/objects/v2/payment_method_spec.rb +106 -0
- data/spec/objects/v2/transaction_spec.rb +48 -0
- data/spec/payload/arm/request_spec.rb +258 -0
- data/spec/support/helpers/v1_helpers.rb +159 -0
- data/spec/support/helpers/v2_helpers.rb +205 -0
- data/spec/support/helpers.rb +15 -0
- data/spec/support/helpers_spec.rb +21 -0
- metadata +22 -6
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require_relative '../../support/helpers'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'Payment Method Integration Tests - V1' do
|
|
6
|
+
include_context 'test helpers'
|
|
7
|
+
|
|
8
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 1) }
|
|
9
|
+
let(:h) { V1Helpers.new(session) }
|
|
10
|
+
let(:proc_account) { h.create_processing_account }
|
|
11
|
+
|
|
12
|
+
describe 'Payment Methods' do
|
|
13
|
+
it 'creates a payment with card' do
|
|
14
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
15
|
+
expect(card_payment.status).to eq('processed')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'creates a payment with bank account' do
|
|
19
|
+
bank_payment = h.create_bank_payment
|
|
20
|
+
expect(bank_payment.status).to eq('processed')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'filters payments' do
|
|
24
|
+
rand_description = (0...10).map { ('a'..'z').to_a[rand(26)] }.join
|
|
25
|
+
|
|
26
|
+
amounts = [90.0, 100.0, 110.0]
|
|
27
|
+
card_payments = []
|
|
28
|
+
amounts.each do |amount|
|
|
29
|
+
card_payment = h.create_card_payment(proc_account.id, amount: amount, description: rand_description)
|
|
30
|
+
card_payments << card_payment
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
payments = session.Transaction.filter_by(
|
|
34
|
+
type: 'payment',
|
|
35
|
+
amount: '100',
|
|
36
|
+
description: rand_description
|
|
37
|
+
).all
|
|
38
|
+
|
|
39
|
+
expect(payments.length).to be == 1
|
|
40
|
+
expect(payments.map(&:id)).to include(card_payments[1].id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'voids a card payment' do
|
|
44
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
45
|
+
card_payment.update(status: 'voided')
|
|
46
|
+
expect(card_payment.status).to eq('voided')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'voids a bank payment' do
|
|
50
|
+
bank_payment = h.create_bank_payment
|
|
51
|
+
bank_payment.update(status: 'voided')
|
|
52
|
+
expect(bank_payment.status).to eq('voided')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'refunds a card payment' do
|
|
56
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
57
|
+
refund = h.create_refund(card_payment)
|
|
58
|
+
|
|
59
|
+
expect(refund.type).to eq('refund')
|
|
60
|
+
expect(refund.amount).to eq(card_payment.amount)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'partially refunds a card payment' do
|
|
64
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
65
|
+
amount = (card_payment.amount/2).round(2) # rounded to 2 decimal places
|
|
66
|
+
refund = h.create_refund(card_payment, amount: amount)
|
|
67
|
+
|
|
68
|
+
expect(refund.type).to eq('refund')
|
|
69
|
+
expect(refund.amount).to eq(amount)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'creates a blind refund for card payment' do
|
|
73
|
+
refund = h.create_blind_refund(10, proc_account.id)
|
|
74
|
+
|
|
75
|
+
expect(refund.type).to eq('refund')
|
|
76
|
+
expect(refund.amount).to eq(10)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'refunds a bank payment' do
|
|
80
|
+
bank_payment = h.create_bank_payment
|
|
81
|
+
refund = h.create_refund(bank_payment)
|
|
82
|
+
|
|
83
|
+
expect(refund.type).to eq('refund')
|
|
84
|
+
expect(refund.amount).to eq(bank_payment.amount)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'partially refunds a bank payment' do
|
|
88
|
+
bank_payment = h.create_bank_payment
|
|
89
|
+
amount = (bank_payment.amount/2).round(2) # rounded to 2 decimal places
|
|
90
|
+
refund = h.create_refund(bank_payment, amount: amount)
|
|
91
|
+
|
|
92
|
+
expect(refund.type).to eq('refund')
|
|
93
|
+
expect(refund.amount).to eq(amount)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'raises error for invalid payment method type' do
|
|
97
|
+
expect {
|
|
98
|
+
session.Transaction.create(
|
|
99
|
+
type: 'invalid',
|
|
100
|
+
card_number: '4242 4242 4242 4242',
|
|
101
|
+
expiry: '12/29'
|
|
102
|
+
)
|
|
103
|
+
}.to raise_error(Payload::InvalidAttributes)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "payload"
|
|
2
2
|
require "payload/arm/object"
|
|
3
3
|
require 'base64'
|
|
4
|
-
|
|
4
|
+
require_relative '../../support/helpers'
|
|
5
5
|
|
|
6
6
|
RSpec.describe Payload::ARMRequest do
|
|
7
7
|
|
|
@@ -46,11 +46,10 @@ RSpec.describe Payload::ARMRequest do
|
|
|
46
46
|
payment = instance.create(
|
|
47
47
|
amount: 129.0,
|
|
48
48
|
customer_id: 'acct_3bW9JMoGYQul5fCIa9f8q',
|
|
49
|
-
allocations: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
],
|
|
49
|
+
allocations: [{
|
|
50
|
+
entry_type: 'payment',
|
|
51
|
+
invoice_id: 'inv_3eNP6uf94xHTXr0rMyvZJ'
|
|
52
|
+
}],
|
|
54
53
|
)
|
|
55
54
|
|
|
56
55
|
expect(payment.id).to eq($test_id)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require 'payload/arm/session'
|
|
4
|
+
require 'date'
|
|
5
|
+
require_relative '../../support/helpers'
|
|
6
|
+
|
|
7
|
+
RSpec.describe 'Session Integration Tests' do
|
|
8
|
+
include_context 'test helpers'
|
|
9
|
+
|
|
10
|
+
describe 'Session' do
|
|
11
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 1) }
|
|
12
|
+
|
|
13
|
+
it 'creates a customer account with session' do
|
|
14
|
+
customer_account = session.Customer.create(name: 'Test', email: 'test@example.com')
|
|
15
|
+
expect(customer_account.id).to be_truthy
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'deletes with session' do
|
|
19
|
+
customer_account = session.Customer.create(name: 'Test', email: 'test@example.com')
|
|
20
|
+
customer_account.delete
|
|
21
|
+
|
|
22
|
+
expect {
|
|
23
|
+
session.Customer.get(customer_account.id)
|
|
24
|
+
}.to raise_error(Payload::NotFound)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'creates multiple accounts with session' do
|
|
28
|
+
rand_email1 = (0...5).map { ('a'..'z').to_a[rand(26)] }.join + '@example.com'
|
|
29
|
+
rand_email2 = (0...5).map { ('a'..'z').to_a[rand(26)] }.join + '@example.com'
|
|
30
|
+
|
|
31
|
+
session.create([
|
|
32
|
+
session.Customer.new(email: rand_email1, name: 'Matt Perez'),
|
|
33
|
+
session.Customer.new(email: rand_email2, name: 'Andrea Kearney')
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
get_account_1 = session.Customer.filter_by(email: rand_email1).all[0]
|
|
37
|
+
get_account_2 = session.Customer.filter_by(email: rand_email2).all[0]
|
|
38
|
+
|
|
39
|
+
expect(get_account_1).to be_truthy
|
|
40
|
+
expect(get_account_2).to be_truthy
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'pages and orders results with session' do
|
|
44
|
+
session.create([
|
|
45
|
+
session.Customer.new(email: 'account1@example.com', name: 'Randy Robson'),
|
|
46
|
+
session.Customer.new(email: 'account2@example.com', name: 'Brandy Bobson'),
|
|
47
|
+
session.Customer.new(email: 'account3@example.com', name: 'Mandy Johnson')
|
|
48
|
+
])
|
|
49
|
+
|
|
50
|
+
customers = session.Customer.filter_by(order_by: 'created_at', limit: 3, offset: 1).all
|
|
51
|
+
|
|
52
|
+
expect(customers.length).to eq(3)
|
|
53
|
+
require 'time'
|
|
54
|
+
expect(Time.parse(customers[0].created_at)).to be <= Time.parse(customers[1].created_at)
|
|
55
|
+
expect(Time.parse(customers[1].created_at)).to be <= Time.parse(customers[2].created_at)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'updates customer with session' do
|
|
59
|
+
customer_account = session.Customer.create(name: 'Test', email: 'test@example.com')
|
|
60
|
+
customer_account.update(email: 'test2@example.com')
|
|
61
|
+
expect(customer_account.email).to eq('test2@example.com')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'updates multiple accounts with session' do
|
|
65
|
+
customer_account_1 = session.Customer.create(name: 'Brandy', email: 'test1@example.com')
|
|
66
|
+
customer_account_2 = session.Customer.create(name: 'Sandy', email: 'test2@example.com')
|
|
67
|
+
|
|
68
|
+
updated_accounts = session.update([
|
|
69
|
+
[customer_account_1, { email: 'brandy@example.com' }],
|
|
70
|
+
[customer_account_2, { email: 'sandy@example.com' }]
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
expect(updated_accounts[0].email).to eq('brandy@example.com')
|
|
74
|
+
expect(updated_accounts[1].email).to eq('sandy@example.com')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'gets customer with session' do
|
|
78
|
+
customer_account = session.Customer.create(name: 'Test', email: 'test@example.com')
|
|
79
|
+
expect(session.Customer.get(customer_account.id)).to be_truthy
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'selects customer attributes with session' do
|
|
83
|
+
customer_account = session.Customer.create(name: 'Test', email: 'test@example.com')
|
|
84
|
+
selected = session.query(Payload::Customer).select('id').get(customer_account.id)
|
|
85
|
+
expect(selected['id']).to eq(customer_account.id)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require_relative '../../support/helpers'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'Transaction Integration Tests - V1' do
|
|
6
|
+
include_context 'test helpers'
|
|
7
|
+
|
|
8
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 1) }
|
|
9
|
+
let(:h) { V1Helpers.new(session) }
|
|
10
|
+
let(:proc_account) { h.create_processing_account }
|
|
11
|
+
|
|
12
|
+
describe 'Transactions' do
|
|
13
|
+
|
|
14
|
+
it 'has empty transaction ledger' do
|
|
15
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
16
|
+
transaction = session.Transaction.select('*', 'ledger').get(card_payment.id)
|
|
17
|
+
expect(transaction.ledger).to eq([])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'tests unified payout batching' do
|
|
21
|
+
h.create_blind_refund(10, proc_account.id)
|
|
22
|
+
|
|
23
|
+
transactions = session.Transaction.select('*', 'ledger')
|
|
24
|
+
.filter_by(type: 'refund', processing_id: proc_account.id)
|
|
25
|
+
.all
|
|
26
|
+
|
|
27
|
+
expect(transactions.length).to eq(1)
|
|
28
|
+
expect(transactions[0].processing_id).to eq(proc_account.id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'gets transactions' do
|
|
32
|
+
h.create_card_payment(proc_account.id)
|
|
33
|
+
payments = session.Transaction.filter_by(status: 'processed', type: 'payment').all
|
|
34
|
+
expect(payments.length).to be > 0
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'checks risk flag' do
|
|
38
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
39
|
+
expect(card_payment.risk_flag).to eq('allowed')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'updates processed transaction' do
|
|
43
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
44
|
+
card_payment.update(status: 'voided')
|
|
45
|
+
expect(card_payment.status).to eq('voided')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'raises error for transaction not found' do
|
|
49
|
+
expect {
|
|
50
|
+
session.Transaction.get('invalid')
|
|
51
|
+
}.to raise_error(Payload::NotFound)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require_relative '../../support/helpers'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'Account Integration Tests - V2' do
|
|
6
|
+
include_context 'test helpers'
|
|
7
|
+
|
|
8
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 2) }
|
|
9
|
+
|
|
10
|
+
describe 'Customer Account' do
|
|
11
|
+
it 'creates a customer account' do
|
|
12
|
+
customer_account = session.Account.create(
|
|
13
|
+
type: 'customer',
|
|
14
|
+
name: 'Test',
|
|
15
|
+
contact_details: {
|
|
16
|
+
email: 'test@example.com'
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
expect(customer_account.id).to be_truthy
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'deletes a customer account' do
|
|
23
|
+
cust_account = session.Account.create(
|
|
24
|
+
type: 'customer',
|
|
25
|
+
name: 'Test',
|
|
26
|
+
contact_details: {
|
|
27
|
+
email: 'test@example.com'
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
cust_account.delete
|
|
31
|
+
|
|
32
|
+
expect {
|
|
33
|
+
session.Account.get(cust_account.id)
|
|
34
|
+
}.to raise_error(Payload::NotFound)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'creates multiple accounts' do
|
|
38
|
+
rand_email1 = (0...5).map { ('a'..'z').to_a[rand(26)] }.join + '@example.com'
|
|
39
|
+
rand_email2 = (0...5).map { ('a'..'z').to_a[rand(26)] }.join + '@example.com'
|
|
40
|
+
|
|
41
|
+
name1 = 'Matt Perez'
|
|
42
|
+
name2 = 'Andrea Kearney'
|
|
43
|
+
|
|
44
|
+
accounts_to_create = [
|
|
45
|
+
session.Account.new(type: 'customer', contact_details: { email: rand_email1 }, name: name1),
|
|
46
|
+
session.Account.new(type: 'customer', contact_details: { email: rand_email2 }, name: name2)
|
|
47
|
+
]
|
|
48
|
+
session.create(accounts_to_create)
|
|
49
|
+
|
|
50
|
+
get_account_1 = session.Account.filter_by(type: 'customer', 'contact_details[email]': rand_email1).all[0]
|
|
51
|
+
get_account_2 = session.Account.filter_by(type: 'customer', 'contact_details[email]': rand_email2).all[0]
|
|
52
|
+
|
|
53
|
+
expect(get_account_1).to be_truthy
|
|
54
|
+
expect(get_account_2).to be_truthy
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'gets a processing account' do
|
|
58
|
+
orgs = session.Profile.all()
|
|
59
|
+
org = orgs[0]
|
|
60
|
+
proc_account = session.Account.create(
|
|
61
|
+
type: 'processing',
|
|
62
|
+
name: 'Processing Account',
|
|
63
|
+
processing: {
|
|
64
|
+
status: { funding: 'pending' },
|
|
65
|
+
settings_id: org.processing_settings_id,
|
|
66
|
+
},
|
|
67
|
+
payment_methods: [session.PaymentMethod.new(
|
|
68
|
+
type: 'bank_account',
|
|
69
|
+
bank_account: {
|
|
70
|
+
account_number: '123456789',
|
|
71
|
+
routing_number: '036001808',
|
|
72
|
+
account_type: 'checking'
|
|
73
|
+
},
|
|
74
|
+
billing_address: {
|
|
75
|
+
postal_code: '11111',
|
|
76
|
+
},
|
|
77
|
+
account_defaults: {
|
|
78
|
+
funding: 'all',
|
|
79
|
+
}
|
|
80
|
+
)],
|
|
81
|
+
entity: {
|
|
82
|
+
type: 'business',
|
|
83
|
+
legal_name: 'Example',
|
|
84
|
+
country: 'US',
|
|
85
|
+
phone_number: '123 123-1234',
|
|
86
|
+
tax_id: { value: '123 12 1234' },
|
|
87
|
+
address: {
|
|
88
|
+
address_line_1: '123 Example St',
|
|
89
|
+
city: 'New York',
|
|
90
|
+
state_province: 'NY',
|
|
91
|
+
postal_code: '11111',
|
|
92
|
+
},
|
|
93
|
+
business: {
|
|
94
|
+
category: 'real_estate',
|
|
95
|
+
structure: 'llc',
|
|
96
|
+
website: 'https://example.com',
|
|
97
|
+
formation: {
|
|
98
|
+
state_province: 'NY',
|
|
99
|
+
date: '2019-10-01',
|
|
100
|
+
},
|
|
101
|
+
primary_contact: {
|
|
102
|
+
name: 'John Smith',
|
|
103
|
+
email: 'johnsmith@gmail.com',
|
|
104
|
+
},
|
|
105
|
+
stakeholders: [
|
|
106
|
+
{
|
|
107
|
+
country: 'US',
|
|
108
|
+
personal_information: {
|
|
109
|
+
full_name: 'John Smith',
|
|
110
|
+
email: 'johnsmith@gmail.com',
|
|
111
|
+
birth_date: '1990-05-10',
|
|
112
|
+
phone_number: '123 123-1234',
|
|
113
|
+
},
|
|
114
|
+
address: {
|
|
115
|
+
address_line_1: '123 Example St',
|
|
116
|
+
city: 'New York',
|
|
117
|
+
state_province: 'NY',
|
|
118
|
+
postal_code: '11111',
|
|
119
|
+
},
|
|
120
|
+
govt_id: {
|
|
121
|
+
tax_id: { value: '123 12 1234' },
|
|
122
|
+
},
|
|
123
|
+
association: {
|
|
124
|
+
roles: ['principal_officer'],
|
|
125
|
+
title: 'CEO',
|
|
126
|
+
ownership: {
|
|
127
|
+
percentage: 100,
|
|
128
|
+
years_owned: 5,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
retrieved = session.Account.get(proc_account.id)
|
|
137
|
+
expect(retrieved).to be_truthy
|
|
138
|
+
expect(proc_account.processing['status']['funding']).to eq('pending')
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'pages and orders results' do
|
|
142
|
+
accounts_to_create = [
|
|
143
|
+
session.Account.new(type: 'customer', contact_details: { email: 'account1@example.com' }, name: 'Randy Robson'),
|
|
144
|
+
session.Account.new(type: 'customer', contact_details: { email: 'account2@example.com' }, name: 'Brandy Bobson'),
|
|
145
|
+
session.Account.new(type: 'customer', contact_details: { email: 'account3@example.com' }, name: 'Mandy Johnson')
|
|
146
|
+
]
|
|
147
|
+
session.create(accounts_to_create)
|
|
148
|
+
customers = session.Account.filter_by(type: 'customer', order_by: 'created_at', limit: 3, offset: 1).all
|
|
149
|
+
|
|
150
|
+
expect(customers.length).to eq(3)
|
|
151
|
+
require 'time'
|
|
152
|
+
expect(Time.parse(customers[0].created_at)).to be <= Time.parse(customers[1].created_at)
|
|
153
|
+
expect(Time.parse(customers[1].created_at)).to be <= Time.parse(customers[2].created_at)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'updates a customer' do
|
|
157
|
+
cust_account = session.Account.create(
|
|
158
|
+
type: 'customer',
|
|
159
|
+
name: 'Test',
|
|
160
|
+
contact_details: {
|
|
161
|
+
email: 'test@example.com'
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
cust_account.update(contact_details: { email: 'test2@example.com' })
|
|
165
|
+
expect(cust_account.contact_details['email']).to eq('test2@example.com')
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'updates multiple accounts' do
|
|
169
|
+
customer_account_1 = session.Account.create(
|
|
170
|
+
type: 'customer',
|
|
171
|
+
name: 'Brandy',
|
|
172
|
+
contact_details: { email: 'test1@example.com' }
|
|
173
|
+
)
|
|
174
|
+
customer_account_2 = session.Account.create(
|
|
175
|
+
type: 'customer',
|
|
176
|
+
name: 'Sandy',
|
|
177
|
+
contact_details: { email: 'test2@example.com' }
|
|
178
|
+
)
|
|
179
|
+
updated_accounts = session.update([
|
|
180
|
+
[customer_account_1, { contact_details: { email: 'brandy@example.com' } }],
|
|
181
|
+
[customer_account_2, { contact_details: { email: 'sandy@example.com' } }]
|
|
182
|
+
])
|
|
183
|
+
|
|
184
|
+
expect(updated_accounts[0].contact_details['email']).to eq('brandy@example.com')
|
|
185
|
+
expect(updated_accounts[1].contact_details['email']).to eq('sandy@example.com')
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it 'gets a customer' do
|
|
189
|
+
cust_account = session.Account.create(
|
|
190
|
+
type: 'customer',
|
|
191
|
+
name: 'Test',
|
|
192
|
+
contact_details: {
|
|
193
|
+
email: 'test@example.com'
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
expect(session.Account.get(cust_account.id)).to be_truthy
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it 'selects customer attributes' do
|
|
200
|
+
cust_account = session.Account.create(
|
|
201
|
+
type: 'customer',
|
|
202
|
+
name: 'Test',
|
|
203
|
+
contact_details: {
|
|
204
|
+
email: 'test@example.com'
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
selected = session.Account.select('id').get(cust_account.id)
|
|
208
|
+
expect(selected['id']).to eq(cust_account.id)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require 'date'
|
|
4
|
+
require_relative '../../support/helpers'
|
|
5
|
+
|
|
6
|
+
RSpec.describe 'Invoice Integration Tests - V2' do
|
|
7
|
+
include_context 'test helpers'
|
|
8
|
+
|
|
9
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 2) }
|
|
10
|
+
let(:h) { V2Helpers.new(session) }
|
|
11
|
+
|
|
12
|
+
let(:proc_account) { h.create_processing_account }
|
|
13
|
+
let(:customer_account) { h.create_customer_account }
|
|
14
|
+
let(:invoice) { h.create_invoice(proc_account, customer_account) }
|
|
15
|
+
|
|
16
|
+
describe 'Invoice' do
|
|
17
|
+
it 'creates an invoice' do
|
|
18
|
+
inv = invoice
|
|
19
|
+
expect(inv.due_date).to eq(Date.today.strftime('%Y-%m-%d'))
|
|
20
|
+
expect(inv.status).to eq('unpaid')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'pays an invoice' do
|
|
24
|
+
inv = invoice
|
|
25
|
+
expect(inv.due_date).to eq(Date.today.strftime('%Y-%m-%d'))
|
|
26
|
+
expect(inv.status).to eq('unpaid')
|
|
27
|
+
|
|
28
|
+
amount = inv.totals['balance_due']
|
|
29
|
+
|
|
30
|
+
if inv.status != 'paid'
|
|
31
|
+
h.create_card_payment(
|
|
32
|
+
proc_account.id,
|
|
33
|
+
amount: amount,
|
|
34
|
+
description: 'Test Payment',
|
|
35
|
+
customer_id: customer_account.id,
|
|
36
|
+
invoice_id: inv.id
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
get_invoice = session.Invoice.get(inv.id)
|
|
41
|
+
expect(get_invoice.status).to eq('paid')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'deletes an invoice' do
|
|
45
|
+
inv = invoice
|
|
46
|
+
inv.delete
|
|
47
|
+
|
|
48
|
+
expect {
|
|
49
|
+
session.Invoice.get(inv.id)
|
|
50
|
+
}.to raise_error(Payload::NotFound)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require_relative '../../support/helpers'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'Payment Method Integration Tests - V2' do
|
|
6
|
+
include_context 'test helpers'
|
|
7
|
+
|
|
8
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 2) }
|
|
9
|
+
let(:h) { V2Helpers.new(session) }
|
|
10
|
+
let(:proc_account) { h.create_processing_account }
|
|
11
|
+
|
|
12
|
+
describe 'Payment Methods' do
|
|
13
|
+
it 'creates a payment with card' do
|
|
14
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
15
|
+
expect(card_payment.status['value']).to eq('processed')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'creates a payment with bank account' do
|
|
19
|
+
bank_payment = h.create_bank_payment
|
|
20
|
+
expect(bank_payment.status['value']).to eq('processed')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'filters payments' do
|
|
24
|
+
rand_description = (0...10).map { ('a'..'z').to_a[rand(26)] }.join
|
|
25
|
+
|
|
26
|
+
amounts = [90.0, 100.0, 110.0]
|
|
27
|
+
card_payments = []
|
|
28
|
+
amounts.each do |amount|
|
|
29
|
+
card_payment = h.create_card_payment(proc_account.id, amount: amount, description: rand_description)
|
|
30
|
+
card_payments << card_payment
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
payments = session.Transaction.filter_by(
|
|
34
|
+
type: 'payment',
|
|
35
|
+
amount: '100',
|
|
36
|
+
description: rand_description
|
|
37
|
+
).all
|
|
38
|
+
|
|
39
|
+
expect(payments.length).to be == 1
|
|
40
|
+
expect(payments.map(&:id)).to include(card_payments[1].id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'voids a card payment' do
|
|
44
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
45
|
+
card_payment.update(status: { value: 'voided' })
|
|
46
|
+
expect(card_payment.status['value']).to eq('voided')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'voids a bank payment' do
|
|
50
|
+
bank_payment = h.create_bank_payment
|
|
51
|
+
bank_payment.update(status: { value: 'voided' })
|
|
52
|
+
expect(bank_payment.status['value']).to eq('voided')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'refunds a card payment' do
|
|
56
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
57
|
+
refund = h.create_refund(card_payment)
|
|
58
|
+
|
|
59
|
+
expect(refund.type).to eq('refund')
|
|
60
|
+
expect(refund.amount).to eq(card_payment.amount)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'partially refunds a card payment' do
|
|
64
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
65
|
+
amount = (card_payment.amount/2).round(2) # rounded to 2 decimal places
|
|
66
|
+
refund = h.create_refund(card_payment, amount: amount)
|
|
67
|
+
|
|
68
|
+
expect(refund.type).to eq('refund')
|
|
69
|
+
expect(refund.amount).to eq(amount)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'creates a blind refund for card payment' do
|
|
73
|
+
refund = h.create_blind_refund(10, proc_account.id)
|
|
74
|
+
|
|
75
|
+
expect(refund.type).to eq('refund')
|
|
76
|
+
expect(refund.amount).to eq(10)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'refunds a bank payment' do
|
|
80
|
+
bank_payment = h.create_bank_payment
|
|
81
|
+
refund = h.create_refund(bank_payment)
|
|
82
|
+
|
|
83
|
+
expect(refund.type).to eq('refund')
|
|
84
|
+
expect(refund.amount).to eq(bank_payment.amount)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'partially refunds a bank payment' do
|
|
88
|
+
bank_payment = h.create_bank_payment
|
|
89
|
+
amount = (bank_payment.amount/2).round(2) # rounded to 2 decimal places
|
|
90
|
+
refund = h.create_refund(bank_payment, amount: amount)
|
|
91
|
+
|
|
92
|
+
expect(refund.type).to eq('refund')
|
|
93
|
+
expect(refund.amount).to eq(amount)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'raises error for invalid payment method type' do
|
|
97
|
+
expect {
|
|
98
|
+
session.Transaction.create(
|
|
99
|
+
type: 'invalid',
|
|
100
|
+
card_number: '4242 4242 4242 4242',
|
|
101
|
+
expiry: '12/30'
|
|
102
|
+
)
|
|
103
|
+
}.to raise_error(Payload::InvalidAttributes)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'payload'
|
|
2
|
+
require 'payload/arm/object'
|
|
3
|
+
require_relative '../../support/helpers'
|
|
4
|
+
|
|
5
|
+
RSpec.describe 'Transaction Integration Tests - V2' do
|
|
6
|
+
include_context 'test helpers'
|
|
7
|
+
|
|
8
|
+
let(:session) { Payload::Session.new(Payload.api_key, Payload.api_url, 2) }
|
|
9
|
+
let(:h) { V2Helpers.new(session) }
|
|
10
|
+
let(:proc_account) { h.create_processing_account }
|
|
11
|
+
|
|
12
|
+
describe 'Transactions' do
|
|
13
|
+
|
|
14
|
+
it 'has empty transaction ledger' do
|
|
15
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
16
|
+
transaction = session.Transaction.select('*', 'ledger').get(card_payment.id)
|
|
17
|
+
expect(transaction.ledger).to eq([])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'tests unified payout batching' do
|
|
21
|
+
h.create_blind_refund(10, proc_account.id)
|
|
22
|
+
|
|
23
|
+
transactions = session.Transaction.select('*', 'ledger')
|
|
24
|
+
.filter_by(type: 'refund', processing_id: proc_account.id)
|
|
25
|
+
.all
|
|
26
|
+
|
|
27
|
+
expect(transactions.length).to eq(1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'gets transactions' do
|
|
31
|
+
h.create_card_payment(proc_account.id)
|
|
32
|
+
payments = session.Transaction.filter_by('status[value]': 'processed', type: 'payment', 'receiver[account_id]': proc_account.id).all
|
|
33
|
+
expect(payments.length).to be > 0
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'updates processed transaction' do
|
|
37
|
+
card_payment = h.create_card_payment(proc_account.id)
|
|
38
|
+
card_payment.update(status: { value: 'voided' })
|
|
39
|
+
expect(card_payment.status['value']).to eq('voided')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'raises error for transaction not found' do
|
|
43
|
+
expect {
|
|
44
|
+
session.Transaction.get('invalid')
|
|
45
|
+
}.to raise_error(Payload::NotFound)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|