pin_up 1.3.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -9
- data/Gemfile.lock +74 -99
- data/README.md +155 -11
- data/VERSION +1 -1
- data/lib/pin_up.rb +3 -0
- data/lib/pin_up/pin_errors.rb +6 -0
- data/lib/pin_up/plan.rb +79 -0
- data/lib/pin_up/subscription.rb +80 -0
- data/lib/pin_up/webhook_endpoints.rb +45 -0
- data/pin_up.gemspec +48 -44
- data/spec/cards_spec.rb +14 -2
- data/spec/charges_spec.rb +57 -13
- data/spec/customers_spec.rb +52 -23
- data/spec/errors_spec.rb +294 -61
- data/spec/plan_spec.rb +189 -0
- data/spec/recipients_spec.rb +14 -9
- data/spec/refund_spec.rb +42 -8
- data/spec/spec_helper.rb +3 -4
- data/spec/subscription_spec.rb +201 -0
- data/spec/transfers_spec.rb +23 -17
- data/spec/webhook_endpoints_spec.rb +36 -0
- metadata +20 -27
data/spec/customers_spec.rb
CHANGED
@@ -1,8 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Customer', :vcr, class: Pin::Customer do
|
4
|
+
let(:card_1) {
|
5
|
+
{ number: '5520000000000000',
|
6
|
+
expiry_month: '12',
|
7
|
+
expiry_year: '2025',
|
8
|
+
cvc: '123',
|
9
|
+
name: 'Roland Robot',
|
10
|
+
address_line1: '123 Fake Street',
|
11
|
+
address_city: 'Melbourne',
|
12
|
+
address_postcode: '1234',
|
13
|
+
address_state: 'Vic',
|
14
|
+
address_country: 'Australia' }
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:card_2) {
|
18
|
+
{ number: '4200000000000000',
|
19
|
+
expiry_month: '12',
|
20
|
+
expiry_year: '2020',
|
21
|
+
cvc: '111',
|
22
|
+
name: 'Roland TestRobot',
|
23
|
+
address_line1: '123 Fake Road',
|
24
|
+
address_line2: '',
|
25
|
+
address_city: 'Melbourne',
|
26
|
+
address_postcode: '1223',
|
27
|
+
address_state: 'Vic',
|
28
|
+
address_country: 'AU' }
|
29
|
+
}
|
30
|
+
|
31
|
+
let(:customer_token) {
|
32
|
+
Pin::Customer.create('email@example.com', card_1)['token']
|
33
|
+
}
|
34
|
+
|
4
35
|
before(:each) do
|
5
36
|
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
37
|
+
Pin::Charges.create(email: 'email@example.com',
|
38
|
+
description: 'Charge description',
|
39
|
+
amount: '500',
|
40
|
+
currency: 'AUD',
|
41
|
+
number: '5520000000000000',
|
42
|
+
ip_address: '203.192.1.172',
|
43
|
+
customer_token: customer_token)
|
6
44
|
end
|
7
45
|
|
8
46
|
it 'should list customers' do
|
@@ -25,65 +63,56 @@ describe 'Customer', :vcr, class: Pin::Customer do
|
|
25
63
|
end
|
26
64
|
|
27
65
|
it 'should not list customers on a page given a page if there are no customers' do
|
28
|
-
request = Pin::Customer.all(
|
66
|
+
request = Pin::Customer.all(900, true)
|
29
67
|
expect(request[:response]).to eq []
|
30
68
|
end
|
31
69
|
|
32
70
|
it 'should show a customer given a token' do
|
33
|
-
expect(Pin::Customer.find(
|
71
|
+
expect(Pin::Customer.find(customer_token)['token']).to eq(customer_token)
|
34
72
|
end
|
35
73
|
|
36
74
|
it 'should list charges to a customer given a token' do
|
37
|
-
|
75
|
+
Pin::Customer.charges(customer_token)
|
76
|
+
expect(Pin::Customer.charges(customer_token)[0]['token']).to match(/^[a-z]{2}[_]/)
|
38
77
|
end
|
39
78
|
|
40
79
|
it 'should show pagination on a page given a token and a page' do
|
41
|
-
expect(Pin::Customer.charges(
|
80
|
+
expect(Pin::Customer.charges(customer_token, 5, true)[:pagination]['current']).to eq 5
|
42
81
|
end
|
43
82
|
|
44
83
|
it 'should list charges to a customer on a page given a token and a page' do
|
45
|
-
expect(Pin::Customer.charges(
|
84
|
+
expect(Pin::Customer.charges(customer_token, 1, true)[:response][0]['token']).to match(/^[a-z]{2}[_]/)
|
46
85
|
end
|
47
86
|
|
48
87
|
it 'should create a customer given an email and card details' do
|
49
|
-
expect(Pin::Customer.create('email@example.com',
|
88
|
+
expect(Pin::Customer.create('email@example.com', card_1)['token']).to match(/^[a-z]{3}[_]/)
|
50
89
|
end
|
51
90
|
|
52
91
|
it 'should update a customer given a token and details to update' do
|
53
|
-
|
54
|
-
expect(Pin::Customer.update('cus_6XnfOD5bvQ1qkaf3LqmhfQ', options)['card']['address_line1']).to eq '12345 Fake Street'
|
92
|
+
expect(Pin::Customer.update(customer_token, card_1)['card']['address_line1']).to eq '123 Fake Street'
|
55
93
|
end
|
56
94
|
|
57
95
|
it 'should create a customer given a card token customer email' do
|
58
|
-
|
59
|
-
@card = Pin::Card.create(options)
|
96
|
+
@card = Pin::Card.create(card_1)
|
60
97
|
expect(Pin::Customer.create('nitza98@hotmail.com', @card['token'])['token']).to match(/^[a-z]{3}[_]/)
|
61
98
|
end
|
62
99
|
|
63
100
|
it 'should list all cards belonging to this customer' do
|
64
|
-
token
|
65
|
-
expect(Pin::Customer.cards(token).first['token']).to match(/(card)[_]([\w-]{22})/)
|
101
|
+
expect(Pin::Customer.cards(customer_token).first['token']).to match(/(card)[_]([\w-]{22})/)
|
66
102
|
end
|
67
103
|
|
68
104
|
it 'should create a card given customer token and card hash' do
|
69
|
-
customer_token
|
70
|
-
card = { publishable_api_key: ENV['PUBLISHABLE_SECRET'], number: '5520000000000000', expiry_month: '12', expiry_year: '2018', cvc: '123', name: 'Roland TestRobot', address_line1: '123 Fake Road', address_line2: '', address_city: 'Melbourne', address_postcode: '1223', address_state: 'Vic', address_country: 'AU' }
|
71
|
-
expect(Pin::Customer.create_card(customer_token, card)['token']).to match(/(card)[_]([\w-]{22})/)
|
105
|
+
expect(Pin::Customer.create_card(customer_token, card_1)['token']).to match(/(card)[_]([\w-]{22})/)
|
72
106
|
end
|
73
107
|
|
74
108
|
it 'should create a card then add it to a customer' do
|
75
|
-
|
76
|
-
|
77
|
-
customer_token = 'cus_6XnfOD5bvQ1qkaf3LqmhfQ'
|
78
|
-
expect(Pin::Customer.create_card(customer_token, card_token)['token']).to match(/(card)[_]([\w-]{22})/)
|
109
|
+
added_card = Pin::Customer.create_card(customer_token, card_2)
|
110
|
+
expect(added_card['token']).to match(/(card)[_]([\w-]{22})/)
|
79
111
|
end
|
80
112
|
|
81
113
|
it 'should delete a card given a token' do
|
82
|
-
|
83
|
-
card_token = Pin::Card.create(options)['token']
|
84
|
-
customer_token = 'cus_6XnfOD5bvQ1qkaf3LqmhfQ'
|
114
|
+
card_token = Pin::Card.create(card_2)['token']
|
85
115
|
Pin::Customer.create_card(customer_token, card_token)
|
86
116
|
expect(Pin::Customer.delete_card(customer_token, card_token).code).to eq 204
|
87
117
|
end
|
88
|
-
|
89
118
|
end
|
data/spec/errors_spec.rb
CHANGED
@@ -1,29 +1,48 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Errors', :vcr, class: Pin::PinError do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
let(:card_1) {
|
5
|
+
{ number: '5520000000000000',
|
6
|
+
expiry_month: '12',
|
7
|
+
expiry_year: '2025',
|
8
|
+
cvc: '123',
|
9
|
+
name: 'Roland Robot',
|
10
|
+
address_line1: '123 Fake Street',
|
11
|
+
address_city: 'Melbourne',
|
12
|
+
address_postcode: '1234',
|
13
|
+
address_state: 'Vic',
|
14
|
+
address_country: 'Australia' }
|
15
|
+
}
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
let(:card_2) {
|
18
|
+
{ number: '4200000000000000',
|
19
|
+
expiry_month: '12',
|
20
|
+
expiry_year: '2020',
|
21
|
+
cvc: '111',
|
22
|
+
name: 'Roland TestRobot',
|
23
|
+
address_line1: '123 Fake Road',
|
24
|
+
address_line2: '',
|
25
|
+
address_city: 'Melbourne',
|
26
|
+
address_postcode: '1223',
|
27
|
+
address_state: 'Vic',
|
28
|
+
address_country: 'AU' }
|
29
|
+
}
|
15
30
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
expect(error).to be_a Pin::InvalidResource
|
20
|
-
expect(error.message).to eq "card_number_invalid: Card number can't be blank card_name_invalid: Card name can't be blank "
|
21
|
-
expect(error.response).to be_a Hash
|
22
|
-
end
|
23
|
-
end
|
31
|
+
let(:card_2_token) {
|
32
|
+
Pin::Card.create(card_2)['token']
|
33
|
+
}
|
24
34
|
|
25
|
-
|
26
|
-
|
35
|
+
let(:customer_token) {
|
36
|
+
Pin::Customer.create('email@example.com', card_1)['token']
|
37
|
+
}
|
38
|
+
|
39
|
+
let(:charge_hash) {
|
40
|
+
{ email: 'email@example.com',
|
41
|
+
description: 'A new charge from testing Pin gem',
|
42
|
+
amount: '400',
|
43
|
+
currency: 'AUD',
|
44
|
+
ip_address: '127.0.0.1',
|
45
|
+
card: {
|
27
46
|
number: '5520000000000000',
|
28
47
|
expiry_month: '05',
|
29
48
|
expiry_year: '2012',
|
@@ -35,18 +54,18 @@ describe 'Errors', :vcr, class: Pin::PinError do
|
|
35
54
|
address_state: 'WA',
|
36
55
|
address_country: 'Australia'
|
37
56
|
} }
|
38
|
-
|
39
|
-
expect(error).to be_a Pin::InvalidResource
|
40
|
-
expect(error.message).to eq 'card_expiry_month_invalid: Card expiry month is expired card_expiry_year_invalid: Card expiry year is expired '
|
41
|
-
expect(error.response).to be_a Hash
|
42
|
-
end
|
43
|
-
end
|
57
|
+
}
|
44
58
|
|
45
|
-
|
46
|
-
|
59
|
+
let(:hash_of_details) {
|
60
|
+
{ email: 'email@example.com',
|
61
|
+
description: 'A new charge from testing Pin gem',
|
62
|
+
amount: '400',
|
63
|
+
currency: 'AUD',
|
64
|
+
ip_address: '127.0.0.1',
|
65
|
+
card: {
|
47
66
|
number: '5560000000000001',
|
48
|
-
expiry_month: '
|
49
|
-
expiry_year: '
|
67
|
+
expiry_month: '12',
|
68
|
+
expiry_year: '2025',
|
50
69
|
cvc: '123',
|
51
70
|
name: 'Roland Robot',
|
52
71
|
address_line1: '42 Sevenoaks St',
|
@@ -55,25 +74,76 @@ describe 'Errors', :vcr, class: Pin::PinError do
|
|
55
74
|
address_state: 'WA',
|
56
75
|
address_country: 'Australia'
|
57
76
|
} }
|
58
|
-
|
77
|
+
}
|
78
|
+
|
79
|
+
let(:charge) {
|
80
|
+
Pin::Charges.create(email: 'email@example.com',
|
81
|
+
description: 'Charge description',
|
82
|
+
amount: '500',
|
83
|
+
currency: 'AUD',
|
84
|
+
number: '5520000000000000',
|
85
|
+
ip_address: '203.192.1.172',
|
86
|
+
customer_token: customer_token)
|
87
|
+
}
|
88
|
+
|
89
|
+
let(:time) { Time.now.iso8601(4) }
|
90
|
+
|
91
|
+
let(:plan) {
|
92
|
+
{ name: "Plan#{time}",
|
93
|
+
amount: '1000',
|
94
|
+
currency: 'AUD',
|
95
|
+
interval: 30,
|
96
|
+
interval_unit: 'day',
|
97
|
+
setup_amount: 0,
|
98
|
+
trial_amount: 0,
|
99
|
+
trial_interval: 7,
|
100
|
+
trial_interval_unit: 'day' }
|
101
|
+
}
|
102
|
+
|
103
|
+
let(:plan_token) {
|
104
|
+
Pin::Plan.create(plan)['token']
|
105
|
+
}
|
106
|
+
|
107
|
+
let(:subscription_1) {
|
108
|
+
{ plan_token: plan_token,
|
109
|
+
customer_token: customer_token,
|
110
|
+
include_setup_fee: false }
|
111
|
+
}
|
112
|
+
|
113
|
+
let(:subscription_1_token) {
|
114
|
+
Pin::Subscription.create(subscription_1)['token']
|
115
|
+
}
|
116
|
+
|
117
|
+
before(:each) do
|
118
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
59
119
|
end
|
60
120
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
address_line1: '42 Sevenoaks St',
|
69
|
-
address_city: 'Lathlain',
|
70
|
-
address_postcode: '6454',
|
71
|
-
address_state: 'WA',
|
72
|
-
address_country: 'Australia'
|
73
|
-
} }
|
74
|
-
expect { Pin::Charges.create(options) }.to raise_error do |error|
|
121
|
+
###
|
122
|
+
# Customer Errors
|
123
|
+
###
|
124
|
+
it 'should raise a 400 error when attempting to delete customer\'s primary card' do
|
125
|
+
cards = Pin::Customer.cards(customer_token)
|
126
|
+
primary_card_token = cards.select{|card| card['primary'] }.first['token']
|
127
|
+
expect { Pin::Customer.delete_card(customer_token, primary_card_token) }.to raise_error do |error|
|
75
128
|
expect(error).to be_a Pin::InvalidResource
|
76
|
-
expect(error.message).to eq '
|
129
|
+
expect(error.message).to eq 'You cannot delete a customer\'s primary card token'
|
130
|
+
expect(error.response).to be_a Hash
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should raise a 404 error when looking for a customer that doesn\'t exist' do
|
135
|
+
expect { Pin::Customer.find('foo') }.to raise_error do |error|
|
136
|
+
expect(error).to be_a Pin::ResourceNotFound
|
137
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
138
|
+
expect(error.response).to be_a Hash
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should raise an Unauthorized error when token is invalid' do
|
143
|
+
Pin::Base.new('arbitrary_token', :test)
|
144
|
+
expect { Pin::Customer.charges('foo') }.to raise_error do |error|
|
145
|
+
expect(error).to be_a Pin::Unauthorized
|
146
|
+
expect(error.message).to eq 'Not authorised. (Check API Key)'
|
77
147
|
expect(error.response).to be_a Hash
|
78
148
|
end
|
79
149
|
end
|
@@ -86,35 +156,198 @@ describe 'Errors', :vcr, class: Pin::PinError do
|
|
86
156
|
end
|
87
157
|
end
|
88
158
|
|
159
|
+
it 'should raise a 422 error when trying to update missing a param' do
|
160
|
+
hash_w_no_credit_card_or_name = hash_of_details.tap do |h|
|
161
|
+
h[:card][:number] = ''
|
162
|
+
h[:card][:name] = ''
|
163
|
+
end
|
164
|
+
expect { Pin::Customer.update(customer_token, hash_w_no_credit_card_or_name) }.to raise_error do |error|
|
165
|
+
expect(error).to be_a Pin::InvalidResource
|
166
|
+
expect(error.response['messages']).to be_a Array
|
167
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Card number can't be blank")
|
168
|
+
expect(error.response['messages'][1]).to match a_hash_including("message"=>"Card name can't be blank")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
###
|
173
|
+
# Charge Errors
|
174
|
+
###
|
175
|
+
it 'should raise a 422 error when trying to make a payment with an expired card' do
|
176
|
+
hash_w_expired_credit_card = hash_of_details.tap do |h|
|
177
|
+
h[:card][:expiry_year] = '2001'
|
178
|
+
end
|
179
|
+
expect { Pin::Charges.create(hash_w_expired_credit_card) }.to raise_error do |error|
|
180
|
+
expect(error).to be_a Pin::InvalidResource
|
181
|
+
expect(error.response['messages']).to be_a Array
|
182
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Card expiry month is expired")
|
183
|
+
expect(error.response['messages'][1]).to match a_hash_including("message"=>"Card expiry year is expired")
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should raise a 400 error when trying to make a payment and a valid card gets declined' do
|
188
|
+
hash_w_card_declined = hash_of_details.tap do |h|
|
189
|
+
h[:card][:number] = '5560000000000001'
|
190
|
+
end
|
191
|
+
expect { Pin::Charges.create(hash_w_card_declined) }.to raise_error(Pin::ChargeError)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should raise a 422 error when trying to make a payment with an invalid card' do
|
195
|
+
hash_w_invalid_card = hash_of_details.tap do |h|
|
196
|
+
h[:card][:number] = '5520000000000099'
|
197
|
+
end
|
198
|
+
expect { Pin::Charges.create(hash_w_invalid_card) }.to raise_error do |error|
|
199
|
+
expect(error).to be_a Pin::InvalidResource
|
200
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Card number is not valid")
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
###
|
205
|
+
# Refund Errors
|
206
|
+
###
|
89
207
|
it 'should raise a 422 error if no 2nd argument is given' do
|
90
|
-
|
91
|
-
options = { email: 'email@example.com', description: 'A new charge from testing Pin gem', amount: '400', currency: 'AUD', ip_address: '127.0.0.1', customer_token: customer['token'] }
|
92
|
-
@charge = Pin::Charges.create(options)
|
93
|
-
expect { Pin::Refund.create(@charge['token']) }.to raise_error do |error|
|
208
|
+
expect { Pin::Refund.create(charge['token']) }.to raise_error do |error|
|
94
209
|
expect(error).to be_a Pin::InvalidResource
|
95
210
|
expect(error.message).to eq "amount_invalid: Amount can't be blank amount_invalid: Amount is not a number "
|
96
211
|
expect(error.response).to be_a Hash
|
97
212
|
end
|
98
213
|
end
|
99
214
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
215
|
+
###
|
216
|
+
# Plan Errors
|
217
|
+
###
|
218
|
+
it 'should raise a 422 when creating a plan token and any field validation fails' do
|
219
|
+
plan_w_no_name = plan.tap { |h| h[:name] = '' }
|
220
|
+
expect { Pin::Plan.create(plan_w_no_name) }.to raise_error do |error|
|
105
221
|
expect(error).to be_a Pin::InvalidResource
|
106
|
-
expect(error.
|
222
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Name can't be blank")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should raise a 404 error when trying to find a plan token that does not exist' do
|
227
|
+
expect { Pin::Plan.find('invalid_plan_token') }.to raise_error do |error|
|
228
|
+
expect(error).to be_a Pin::ResourceNotFound
|
229
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
107
230
|
expect(error.response).to be_a Hash
|
108
231
|
end
|
109
232
|
end
|
110
233
|
|
111
|
-
it 'should raise
|
112
|
-
Pin::
|
113
|
-
|
114
|
-
expect(error).to
|
115
|
-
expect(error.
|
234
|
+
it 'should raise a 404 error when updating a plan token that does not exist' do
|
235
|
+
expect { Pin::Plan.update('invalid_plan_token', { name: 'new_plan_name' }) }.to raise_error do |error|
|
236
|
+
expect(error).to be_a Pin::ResourceNotFound
|
237
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
238
|
+
expect(error.response).to be_a Hash
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should raise a 422 when updating a plan token and any field validation fails' do
|
243
|
+
expect { Pin::Plan.update(plan_token, { currency: 'USD' }) }.to raise_error do |error|
|
244
|
+
expect(error).to be_a Pin::InvalidResource
|
245
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Name can't be blank")
|
246
|
+
expect(error.response).to be_a Hash
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should raise a 400 cannot delete plan which has active subscriptions' do
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should raise a 404 not found when deleting a plan token that does not exist' do
|
254
|
+
expect { Pin::Plan.delete('invalid_plan_token') }.to raise_error do |error|
|
255
|
+
expect(error).to be_a Pin::ResourceNotFound
|
256
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
257
|
+
expect(error.response).to be_a Hash
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should raise a 404 not found when creating a new subscription on an invalid plan token' do
|
262
|
+
expect { Pin::Plan.create_subscription('invalid_plan_token', customer_token) }.to raise_error do |error|
|
263
|
+
expect(error).to be_a Pin::ResourceNotFound
|
264
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
265
|
+
expect(error.response).to be_a Hash
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'should raise a 404 not found when returning a list of subscriptions for a plan token that does not exist' do
|
270
|
+
expect { Pin::Plan.subscriptions('invalid_plan_token') }.to raise_error do |error|
|
271
|
+
expect(error).to be_a Pin::ResourceNotFound
|
272
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
273
|
+
expect(error.response).to be_a Hash
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
###
|
278
|
+
# Subscription Errors
|
279
|
+
###
|
280
|
+
it 'should raise a 400 when creating a subscription token & any field validation fails' do
|
281
|
+
subscription_w_no_plan_token = subscription_1.tap { |h| h[:plan_token] = '' }
|
282
|
+
expect { Pin::Subscription.create(subscription_w_no_plan_token) }.to raise_error do |error|
|
283
|
+
expect(error).to be_a Pin::InvalidResource
|
284
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Plan must exist")
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'should raise a 404 error when trying to create a subscription with an invalid plan token' do
|
289
|
+
subscription_w_invalid_plan_token = subscription_1.tap { |h| h[:plan_token] = 'invalid_token' }
|
290
|
+
expect { Pin::Subscription.create(subscription_w_invalid_plan_token) }.to raise_error do |error|
|
291
|
+
expect(error).to be_a Pin::ResourceNotFound
|
292
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
293
|
+
expect(error.response).to be_a Hash
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should raise a 404 error when searching for an invalid subscription token' do
|
298
|
+
expect { Pin::Subscription.find('invalid_plan_token') }.to raise_error do |error|
|
299
|
+
expect(error).to be_a Pin::ResourceNotFound
|
300
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
301
|
+
expect(error.response).to be_a Hash
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'should raise a 400 when updating a subscription & no card token is supplied' do
|
306
|
+
expect { Pin::Subscription.update(subscription_1_token, '') }.to raise_error do |error|
|
307
|
+
expect(error).to be_a Pin::InvalidResource
|
308
|
+
expect(error.response['messages'][0]).to match a_hash_including("message"=>"Card token must be present")
|
309
|
+
expect(error.response).to be_a Hash
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'should raise a 400 error when update a subscription with an invalid card token' do
|
314
|
+
expect { Pin::Subscription.update(subscription_1_token, 'invalid_card_token') }.to raise_error do |error|
|
315
|
+
expect(error).to be_a Pin::InvalidResource
|
316
|
+
expect(error.message).to eq("Invalid card token")
|
116
317
|
expect(error.response).to be_a Hash
|
117
318
|
end
|
118
319
|
end
|
119
320
|
|
321
|
+
it 'should raise a 404 when updating a subscription with invalid token' do
|
322
|
+
expect { Pin::Subscription.update('invalid_subscription_token', card_2_token) }.to raise_error do |error|
|
323
|
+
expect(error).to be_a Pin::ResourceNotFound
|
324
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
325
|
+
expect(error.response).to be_a Hash
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'should raise a 404 not found when deleting an invalid subscription token' do
|
330
|
+
expect { Pin::Subscription.delete('invalid_subscription_token') }.to raise_error do |error|
|
331
|
+
expect(error).to be_a Pin::ResourceNotFound
|
332
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
333
|
+
expect(error.response).to be_a Hash
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should raise a 400 invalid state when deleting a cancelled subscription' do
|
338
|
+
deleted_subscription_token = Pin::Subscription.delete(subscription_1_token)['token']
|
339
|
+
expect { Pin::Subscription.delete(deleted_subscription_token) }.to raise_error do |error|
|
340
|
+
expect(error).to be_a Pin::InvalidResource
|
341
|
+
expect(error.message).to eq 'Cannot cancel subscription when state is trial_cancelling'
|
342
|
+
expect(error.response).to be_a Hash
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'should raise a 404 when reactivating a subscription with invalid token' do
|
347
|
+
expect { Pin::Subscription.reactivate('invalid_subscription_token') }.to raise_error do |error|
|
348
|
+
expect(error).to be_a Pin::ResourceNotFound
|
349
|
+
expect(error.message).to eq 'The requested resource could not be found.'
|
350
|
+
expect(error.response).to be_a Hash
|
351
|
+
end
|
352
|
+
end
|
120
353
|
end
|