synapsis 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/synapsis/api_operations/edit.rb +6 -1
- data/lib/synapsis/api_resource.rb +1 -1
- data/lib/synapsis/bank_status.rb +9 -0
- data/lib/synapsis/card.rb +5 -0
- data/lib/synapsis/mass_pay.rb +20 -0
- data/lib/synapsis/order.rb +25 -0
- data/lib/synapsis/user.rb +1 -1
- data/lib/synapsis/version.rb +1 -1
- data/lib/synapsis.rb +1 -0
- data/spec/synapsis/bank_link_spec.rb +1 -1
- data/spec/synapsis/bank_spec.rb +1 -1
- data/spec/synapsis/bank_status_spec.rb +19 -0
- data/spec/synapsis/card_spec.rb +48 -1
- data/spec/synapsis/mass_pay_spec.rb +9 -1
- data/spec/synapsis/order_spec.rb +36 -10
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d5b2bf26eef6d006fecce9cb62a93ea6eefd89a
|
4
|
+
data.tar.gz: 6b7f9dcfbc6811b14e3f0e0c4250bac5286fb136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56699c37e591ed8a71d3f12bfb8214ee5e1d5d3310590463085aa914ceb492d4533743ea8eb3f9dafb69824c805c23b089ae31734eb3b94fcce8b5504e1a80a0
|
7
|
+
data.tar.gz: 9829b32bdfa1e7f552730844e7967770bcc3ef9cccaa9452e9449192f573e561ca317a5fcfe02dc11b9abfd1974607d89eac7211fcabb693ebb97f72fb6d85ae
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module Synapsis::APIOperations::Edit
|
2
|
+
def edit(params)
|
3
|
+
response = edit_request(params)
|
4
|
+
return_response(response)
|
5
|
+
end
|
6
|
+
|
2
7
|
def edit_request(params)
|
3
8
|
request(:post, edit_url, params)
|
4
9
|
end
|
5
10
|
|
6
11
|
def edit_url
|
7
|
-
"#{API_V2_PATH}#{class_name}/edit
|
12
|
+
"#{API_V2_PATH}#{class_name}/edit"
|
8
13
|
end
|
9
14
|
end
|
10
15
|
|
@@ -21,7 +21,7 @@ class Synapsis::APIResource
|
|
21
21
|
if response.success?
|
22
22
|
return parsed_response
|
23
23
|
else
|
24
|
-
raise Synapsis::Error, parsed_response['reason'] || parsed_response['error_message']
|
24
|
+
raise Synapsis::Error, parsed_response[class_name] || parsed_response['reason'] || parsed_response['error_message']
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/synapsis/card.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
class Synapsis::Card < Synapsis::APIResource
|
2
2
|
extend Synapsis::APIOperations::Create
|
3
|
+
extend Synapsis::APIOperations::Edit
|
3
4
|
extend Synapsis::APIOperations::View
|
4
5
|
|
5
6
|
def self.add(params)
|
6
7
|
response = create_request(params)
|
7
8
|
return_response(response)
|
8
9
|
end
|
10
|
+
|
11
|
+
def self.show(params)
|
12
|
+
view(params)
|
13
|
+
end
|
9
14
|
end
|
10
15
|
|
data/lib/synapsis/mass_pay.rb
CHANGED
@@ -2,6 +2,15 @@ class Synapsis::MassPay < Synapsis::APIResource
|
|
2
2
|
extend Synapsis::APIOperations::Create
|
3
3
|
extend Synapsis::APIOperations::View
|
4
4
|
|
5
|
+
module Status
|
6
|
+
WITHDRAWAL_HAPPENING = 0
|
7
|
+
CREATED = 1
|
8
|
+
IN_PROGRESS = 2
|
9
|
+
SETTLED = 3
|
10
|
+
CANCELLED = 4
|
11
|
+
RETURNED = 5
|
12
|
+
end
|
13
|
+
|
5
14
|
COST_PER_MASS_PAY = 0.1
|
6
15
|
|
7
16
|
def self.cost_per_mass_pay
|
@@ -27,5 +36,16 @@ class Synapsis::MassPay < Synapsis::APIResource
|
|
27
36
|
response = view_request(params)
|
28
37
|
return_response(response)
|
29
38
|
end
|
39
|
+
|
40
|
+
def self.cancel(params)
|
41
|
+
response = request(:post, cancel_url, params)
|
42
|
+
return_response(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def self.cancel_url
|
48
|
+
"#{API_V2_PATH}masspay/cancel"
|
49
|
+
end
|
30
50
|
end
|
31
51
|
|
data/lib/synapsis/order.rb
CHANGED
@@ -2,6 +2,16 @@ class Synapsis::Order < Synapsis::APIResource
|
|
2
2
|
include Synapsis::Utilities
|
3
3
|
extend Synapsis::APIOperations::Create
|
4
4
|
|
5
|
+
module Status
|
6
|
+
QUEUED_INVESTIGATING = -1
|
7
|
+
QUEUED = 0
|
8
|
+
CREATED = 1
|
9
|
+
IN_PROGRESS = 2
|
10
|
+
SETTLED = 3
|
11
|
+
CANCELLED = 4
|
12
|
+
RETURNED = 5
|
13
|
+
end
|
14
|
+
|
5
15
|
def self.add(params)
|
6
16
|
response = create_request(params)
|
7
17
|
return_response(response)
|
@@ -12,6 +22,17 @@ class Synapsis::Order < Synapsis::APIResource
|
|
12
22
|
return_response(response)
|
13
23
|
end
|
14
24
|
|
25
|
+
# Consumer key of the seller
|
26
|
+
def self.void(order_id:, oauth_consumer_key:)
|
27
|
+
params = {
|
28
|
+
order_id: order_id,
|
29
|
+
oauth_consumer_key: oauth_consumer_key
|
30
|
+
}
|
31
|
+
|
32
|
+
response = request(:post, void_url, params)
|
33
|
+
return_response(response)
|
34
|
+
end
|
35
|
+
|
15
36
|
def self.synapse_fee(transaction_amount)
|
16
37
|
if transaction_amount > 10
|
17
38
|
0.25
|
@@ -25,5 +46,9 @@ class Synapsis::Order < Synapsis::APIResource
|
|
25
46
|
def self.poll_url
|
26
47
|
"#{API_V2_PATH}order/poll"
|
27
48
|
end
|
49
|
+
|
50
|
+
def self.void_url
|
51
|
+
"#{API_V2_PATH}order/void"
|
52
|
+
end
|
28
53
|
end
|
29
54
|
|
data/lib/synapsis/user.rb
CHANGED
data/lib/synapsis/version.rb
CHANGED
data/lib/synapsis.rb
CHANGED
@@ -25,7 +25,7 @@ RSpec.describe Synapsis::Bank do
|
|
25
25
|
|
26
26
|
new_bank = Synapsis::Bank.link(bank_params)
|
27
27
|
|
28
|
-
expect(new_bank.banks.first.name_on_account).to eq user_params[:fullname]
|
28
|
+
expect(new_bank.banks.first.name_on_account.downcase).to eq user_params[:fullname].downcase
|
29
29
|
expect(new_bank.banks.first.bank_name).to eq bank_params[:bank]
|
30
30
|
end
|
31
31
|
end
|
data/spec/synapsis/bank_spec.rb
CHANGED
@@ -29,7 +29,7 @@ RSpec.describe Synapsis::Bank do
|
|
29
29
|
|
30
30
|
new_bank = Synapsis::Bank.add(bank_params)
|
31
31
|
expect(new_bank.bank.name_on_account).to eq viewed_user.user.fullname
|
32
|
-
expect(new_bank.bank.nickname).to eq bank_params[:nickname]
|
32
|
+
expect(new_bank.bank.nickname.downcase).to eq bank_params[:nickname].downcase
|
33
33
|
|
34
34
|
removed_bank = Synapsis::Bank.remove(new_bank.bank.id, random_persons_access_token)
|
35
35
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Synapsis::BankStatus do
|
4
|
+
describe '.show' do
|
5
|
+
before(:each) do
|
6
|
+
Synapsis.environment = 'production'
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
Synapsis.environment = 'development'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'shows' do
|
14
|
+
bank_status_response = Synapsis::BankStatus.show
|
15
|
+
|
16
|
+
expect(bank_status_response).to respond_to(:banks)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/synapsis/card_spec.rb
CHANGED
@@ -25,7 +25,7 @@ RSpec.describe Synapsis::Card do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
describe '.show' do
|
29
29
|
context 'without id parameter' do
|
30
30
|
context 'happy path' do
|
31
31
|
it 'shows all of the user\'s cards' do
|
@@ -41,4 +41,51 @@ RSpec.describe Synapsis::Card do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe '.edit' do
|
46
|
+
let!(:edit_card_params) {{
|
47
|
+
oauth_consumer_key: users_consumer_key,
|
48
|
+
id: 483,
|
49
|
+
legal_name: Faker::Name.name,
|
50
|
+
account_number: "11111111#{rand(1..9)}#{rand(1..9)}",
|
51
|
+
routing_number: "1210003#{rand(1..9)}#{rand(1..9)}",
|
52
|
+
account_class: rand(1..2),
|
53
|
+
account_type: rand(1..2)
|
54
|
+
}}
|
55
|
+
|
56
|
+
context 'happy path' do
|
57
|
+
it 'edits the card' do
|
58
|
+
edited_card_response = Synapsis::Card.edit(edit_card_params)
|
59
|
+
|
60
|
+
[:account_class, :account_type].each do |param|
|
61
|
+
expect(edited_card_response.card.send(param)).to eq edit_card_params[param]
|
62
|
+
end
|
63
|
+
|
64
|
+
expect(edited_card_response.card.account_number_string).to include edit_card_params[:account_number][-1, 2] # Since only last 2 digits are saved we ensure that the account numbers and routing numbers are actually changed
|
65
|
+
expect(edited_card_response.card.routing_number_string).to include edit_card_params[:routing_number][-1, 2] # Since only last 2 digits are saved we ensure that the account numbers and routing numbers are actually changed
|
66
|
+
expect(edited_card_response.card.name_on_account).to eq edit_card_params[:legal_name]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'wrong parameters' do
|
71
|
+
it 'raises errors' do
|
72
|
+
# Wrong OAuth consumer key
|
73
|
+
expect { Synapsis::Card.edit(edit_card_params.merge(oauth_consumer_key: 'WRONG')) }.to raise_error(Synapsis::Error).with_message('Error in OAuth Authentication.')
|
74
|
+
|
75
|
+
# User does not own the card
|
76
|
+
expect { Synapsis::Card.edit(edit_card_params.merge(id: 5)) }.to raise_error(Synapsis::Error).with_message('Card not found')
|
77
|
+
|
78
|
+
# Wrong account class
|
79
|
+
expect { Synapsis::Card.edit(edit_card_params.merge(account_class: 'WRONG')) }.to raise_error(Synapsis::Error).with_message('Sorry, this request could not be processed. Please try again later.')
|
80
|
+
end
|
81
|
+
|
82
|
+
xit 'doesn\'t raise errors on invalid account numbers and routing numbers' do
|
83
|
+
# Invalid account number DOES NOT RAISE AN ERROR
|
84
|
+
expect { Synapsis::Card.edit(edit_card_params.merge(account_number: 'THIS IS NOT REAL')) }.to raise_error(Synapsis::Error).with_message('Error in OAuth Authentication.')
|
85
|
+
|
86
|
+
# Invalid account number DOES NOT RAISE AN ERROR
|
87
|
+
expect { Synapsis::Card.edit(edit_card_params.merge(routing_number: 'THIS IS NOT REAL')) }.to raise_error(Synapsis::Error).with_message('Error in OAuth Authentication.')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
44
91
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Synapsis::MassPay do
|
4
4
|
let!(:users_consumer_key) { 'dcd234d9d9fb55ad9711c4c41e254868ef3768d4' }
|
5
|
-
describe '.add' do
|
5
|
+
describe '.add and .cancel' do
|
6
6
|
# These tests might fail if the guy runs out of money
|
7
7
|
context 'happy path' do
|
8
8
|
let!(:delta) { 0.001 }
|
@@ -32,7 +32,15 @@ RSpec.describe Synapsis::MassPay do
|
|
32
32
|
|
33
33
|
expect(mass_pay_response).to respond_to(:mass_pays)
|
34
34
|
expect(mass_pay_response.mass_pays.count).to eq 2
|
35
|
+
expect(mass_pay_response.mass_pays.first.status).to eq Synapsis::MassPay::Status::CREATED
|
35
36
|
expect(mass_pay_response).to respond_to(:success)
|
37
|
+
|
38
|
+
deleted_mass_pay_response = Synapsis::MassPay.cancel(
|
39
|
+
id: mass_pay_response.mass_pays.first.id,
|
40
|
+
oauth_consumer_key: users_consumer_key
|
41
|
+
)
|
42
|
+
|
43
|
+
expect(deleted_mass_pay_response.mass_pays.first.status).to eq Synapsis::MassPay::Status::CANCELLED
|
36
44
|
end
|
37
45
|
|
38
46
|
it 'deducts the user\'s account by the total amount plus 0.1 per mass pay' do
|
data/spec/synapsis/order_spec.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Synapsis::Order do
|
4
|
+
let!(:buyer_consumer_key) { '3bdb5790692d06983d8cb0feb40365886631e52d' }
|
5
|
+
let!(:seller_consumer_key) { '325ea5c0c3a7927280c54ed3ad310c02b45129d8' }
|
6
|
+
let!(:order_params) {{
|
7
|
+
amount: 1,
|
8
|
+
oauth_consumer_key: buyer_consumer_key,
|
9
|
+
seller_id: 3437
|
10
|
+
}}
|
11
|
+
|
4
12
|
context '.add' do
|
5
13
|
let!(:delta) { 0.001 }
|
6
|
-
let!(:buyer_consumer_key) { '3bdb5790692d06983d8cb0feb40365886631e52d' }
|
7
|
-
let!(:seller_consumer_key) { '325ea5c0c3a7927280c54ed3ad310c02b45129d8' }
|
8
|
-
let!(:order_params) {{
|
9
|
-
amount: 1,
|
10
|
-
oauth_consumer_key: buyer_consumer_key,
|
11
|
-
seller_id: 3437
|
12
|
-
}}
|
13
14
|
|
14
15
|
context 'happy path' do
|
15
16
|
it 'constructs the correct Order object' do
|
@@ -19,7 +20,6 @@ RSpec.describe Synapsis::Order do
|
|
19
20
|
|
20
21
|
ORDER_PARAMS = ['account_type', 'amount', 'date', 'date_settled', 'discount', 'facilitator_fee', 'fee', 'id', 'is_buyer', 'note', 'resource_uri', 'seller', 'status', 'status_url', 'ticket_number', 'tip', 'total']
|
21
22
|
|
22
|
-
|
23
23
|
FIRST_LEVEL_PARAMS.each do |param|
|
24
24
|
expect(order_response).to respond_to(param)
|
25
25
|
end
|
@@ -29,7 +29,7 @@ RSpec.describe Synapsis::Order do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
xit 'pending due to a bug wherein the buyer\'s balance does not get decremented--subtracts the money from the consumer\'s account and adds to the seller\'s account' do
|
33
33
|
buyer_account_balance = Synapsis::User.view(buyer_consumer_key).user.balance
|
34
34
|
seller_account_balance = Synapsis::User.view(seller_consumer_key).user.balance
|
35
35
|
|
@@ -42,7 +42,7 @@ RSpec.describe Synapsis::Order do
|
|
42
42
|
expect(new_seller_account_balance).to be_within(delta).of(seller_account_balance + order_params[:amount] - Synapsis::Order.synapse_fee(order_params[:amount]))
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
xit 'pending due to a bug wherein the buyer\'s balance does not get decremented--subtracts the money from the consumer\'s account and adds to the seller\'s account, with a charge of 0.25 if amount is greater than $10' do
|
46
46
|
buyer_account_balance = Synapsis::User.view(buyer_consumer_key).user.balance
|
47
47
|
seller_account_balance = Synapsis::User.view(seller_consumer_key).user.balance
|
48
48
|
|
@@ -81,4 +81,30 @@ RSpec.describe Synapsis::Order do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
context '.void' do
|
86
|
+
context 'happy path' do
|
87
|
+
it 'voids an order' do
|
88
|
+
existing_order_id = Synapsis::Order.add(order_params).order.id
|
89
|
+
|
90
|
+
voided_order_response = Synapsis::Order.void(
|
91
|
+
order_id: existing_order_id,
|
92
|
+
oauth_consumer_key: seller_consumer_key
|
93
|
+
)
|
94
|
+
|
95
|
+
expect(voided_order_response.order.status).to eq Synapsis::Order::Status::CANCELLED
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'errors' do
|
100
|
+
it 'raises an error' do
|
101
|
+
existing_order_id = Synapsis::Order.add(order_params).order.id
|
102
|
+
|
103
|
+
expect{ Synapsis::Order.void(
|
104
|
+
order_id: existing_order_id,
|
105
|
+
oauth_consumer_key: buyer_consumer_key
|
106
|
+
) }.to raise_error(Synapsis::Error).with_message('cannot void this order')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
84
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synapsis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daryll Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/synapsis/api_resource.rb
|
116
116
|
- lib/synapsis/authentication.rb
|
117
117
|
- lib/synapsis/bank.rb
|
118
|
+
- lib/synapsis/bank_status.rb
|
118
119
|
- lib/synapsis/card.rb
|
119
120
|
- lib/synapsis/deposit.rb
|
120
121
|
- lib/synapsis/error.rb
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- spec/synapsis/authentication_spec.rb
|
132
133
|
- spec/synapsis/bank_link_spec.rb
|
133
134
|
- spec/synapsis/bank_spec.rb
|
135
|
+
- spec/synapsis/bank_status_spec.rb
|
134
136
|
- spec/synapsis/card_spec.rb
|
135
137
|
- spec/synapsis/deposit_spec.rb
|
136
138
|
- spec/synapsis/mass_pay_spec.rb
|
@@ -170,6 +172,7 @@ test_files:
|
|
170
172
|
- spec/synapsis/authentication_spec.rb
|
171
173
|
- spec/synapsis/bank_link_spec.rb
|
172
174
|
- spec/synapsis/bank_spec.rb
|
175
|
+
- spec/synapsis/bank_status_spec.rb
|
173
176
|
- spec/synapsis/card_spec.rb
|
174
177
|
- spec/synapsis/deposit_spec.rb
|
175
178
|
- spec/synapsis/mass_pay_spec.rb
|