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/plan_spec.rb
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Plan', :vcr, class: Pin::Plan do
|
4
|
+
let(:time) { Time.now.iso8601(4) }
|
5
|
+
let(:plan) {
|
6
|
+
{ name: "Plan#{time}",
|
7
|
+
amount: '1000',
|
8
|
+
currency: 'AUD',
|
9
|
+
interval: 30,
|
10
|
+
interval_unit: 'day',
|
11
|
+
setup_amount: 0,
|
12
|
+
trial_amount: 0,
|
13
|
+
trial_interval: 7,
|
14
|
+
trial_interval_unit: 'day' }
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:plan_2) {
|
18
|
+
{ name: "Subscription#{time}",
|
19
|
+
amount: '1000',
|
20
|
+
currency: 'AUD',
|
21
|
+
interval: 1,
|
22
|
+
interval_unit: 'day',
|
23
|
+
setup_amount: 27900,
|
24
|
+
trial_amount: 0,
|
25
|
+
trial_interval: '',
|
26
|
+
trial_interval_unit: '' }
|
27
|
+
}
|
28
|
+
|
29
|
+
let(:plan_2_token) {
|
30
|
+
Pin::Plan.create(plan_2)['token']
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:plan_token) {
|
34
|
+
Pin::Plan.create(plan)['token']
|
35
|
+
}
|
36
|
+
|
37
|
+
let(:card_1) {
|
38
|
+
{ number: '5520000000000000',
|
39
|
+
expiry_month: '12',
|
40
|
+
expiry_year: '2025',
|
41
|
+
cvc: '123',
|
42
|
+
name: 'Roland Robot',
|
43
|
+
address_line1: '123 Fake Street',
|
44
|
+
address_city: 'Melbourne',
|
45
|
+
address_postcode: '1234',
|
46
|
+
address_state: 'Vic',
|
47
|
+
address_country: 'Australia' }
|
48
|
+
}
|
49
|
+
|
50
|
+
let(:card_2) {
|
51
|
+
{ number: '4200000000000000',
|
52
|
+
expiry_month: '12',
|
53
|
+
expiry_year: '2020',
|
54
|
+
cvc: '111',
|
55
|
+
name: 'Roland TestRobot',
|
56
|
+
address_line1: '123 Fake Road',
|
57
|
+
address_line2: '',
|
58
|
+
address_city: 'Melbourne',
|
59
|
+
address_postcode: '1223',
|
60
|
+
address_state: 'Vic',
|
61
|
+
address_country: 'AU' }
|
62
|
+
}
|
63
|
+
|
64
|
+
let(:customer) {
|
65
|
+
Pin::Customer.create('email@example.com', card_1)
|
66
|
+
}
|
67
|
+
|
68
|
+
let(:customer_token) {
|
69
|
+
customer['token']
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:card_2_token) {
|
73
|
+
Pin::Card.create(card_2)['token']
|
74
|
+
}
|
75
|
+
|
76
|
+
let(:link_card_2_to_customer) {
|
77
|
+
Pin::Customer.create_card(customer_token, card_2_token)
|
78
|
+
}
|
79
|
+
|
80
|
+
let(:subscription) {
|
81
|
+
{ plan_token: plan_token,
|
82
|
+
customer_token: customer_token,
|
83
|
+
include_setup_fee: false }
|
84
|
+
}
|
85
|
+
|
86
|
+
let(:subscription_token) {
|
87
|
+
Pin::Subscription.create(subscription)['token']
|
88
|
+
}
|
89
|
+
|
90
|
+
let(:subscription_2) {
|
91
|
+
{ plan_token: plan_2_token,
|
92
|
+
customer_token: customer_token,
|
93
|
+
include_setup_fee: false }
|
94
|
+
}
|
95
|
+
|
96
|
+
let(:subscription_2_token) {
|
97
|
+
Pin::Subscription.create(subscription_2)['token']
|
98
|
+
}
|
99
|
+
|
100
|
+
before(:each) do
|
101
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should create a new plan and return its details' do
|
105
|
+
expect(Pin::Plan.create(plan))
|
106
|
+
.to match a_hash_including("name"=>match(/(Plan)/),
|
107
|
+
"token"=>match(/(plan)[_]([\w-]{22})/),
|
108
|
+
"amount"=>1000,
|
109
|
+
"currency"=>"AUD",
|
110
|
+
"setup_amount"=>0,
|
111
|
+
"trial_amount"=>0,
|
112
|
+
"interval"=>30,
|
113
|
+
"interval_unit"=>"day",
|
114
|
+
"trial_interval"=>7,
|
115
|
+
"trial_interval_unit"=>"day",
|
116
|
+
"expiration_interval"=>0,
|
117
|
+
"expiration_interval_unit"=>"",
|
118
|
+
"active_subscriptions"=>0,
|
119
|
+
"trial_subscriptions"=>0)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should return a paginated list of all plans' do
|
123
|
+
expect(Pin::Plan.all).to_not eq []
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should go to a specific page when page paramater is passed' do
|
127
|
+
request = Pin::Plan.all(2, true)
|
128
|
+
expect(request[:pagination]['current']).to eq 2
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should list customers on a page given a page' do
|
132
|
+
request = Pin::Plan.all(1, true)
|
133
|
+
expect(request[:response]).to_not eq []
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should return pagination if true is passed for pagination' do
|
137
|
+
request = Pin::Plan.all(1, true)
|
138
|
+
request[:pagination].key?(%W('current previous next per_page pages count))
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should return the details of a specified plan given a token' do
|
142
|
+
expect(Pin::Plan.find(plan_token)['token']).to eq(plan_token)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should update the name of a specified plan given a token' do
|
146
|
+
expect(Pin::Plan.update(plan_token, { name: "Updated" })['name'])
|
147
|
+
.to eq("Updated")
|
148
|
+
Pin::Plan.delete(plan_token) # Cleanup as Plan names must be unique
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should delete a plan with zero subscriptions given a token' do
|
152
|
+
expect(Pin::Plan.delete(plan_token).code).to eq 204
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should delete a plan and all de-activated subscriptions' do
|
156
|
+
subscription_2_token # attach a subscription to the plan
|
157
|
+
Pin::Subscription.delete(subscription_2_token) # deactivate subscription
|
158
|
+
expect(Pin::Plan.delete(plan_token).code).to eq 204
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should create a new subscription to the specified plan' do
|
162
|
+
plan = { object: Pin::Plan.create_subscription(plan_token, customer_token),
|
163
|
+
created_at: Time.now }
|
164
|
+
expect(plan[:object])
|
165
|
+
.to match a_hash_including("state"=>"trial",
|
166
|
+
"token"=>match(/(sub)[_]([\w-]{22})/),
|
167
|
+
"plan_token"=>"#{plan_token}",
|
168
|
+
"customer_token"=>"#{customer_token}",
|
169
|
+
"card_token"=> nil)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should create new plan & linked subscription using a new credit card (billing card_2)' do
|
173
|
+
link_card_2_to_customer
|
174
|
+
expect(Pin::Plan.create_subscription(plan_2_token, customer_token, card_2_token))
|
175
|
+
.to match a_hash_including("state"=>"active",
|
176
|
+
"token"=>match(/(sub)[_]([\w-]{22})/),
|
177
|
+
"plan_token"=>"#{plan_2_token}",
|
178
|
+
"customer_token"=>"#{customer_token}",
|
179
|
+
"card_token"=>"#{card_2_token}")
|
180
|
+
charges = Pin::Customer.charges(customer_token)
|
181
|
+
expect(charges[0]['card']['token']).to eq(card_2_token)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should return a paginated list of subscriptions for a plan' do
|
185
|
+
subscription_token # attach a subscription to the plan
|
186
|
+
subscription_list = Pin::Plan.subscriptions(plan_token)
|
187
|
+
expect(subscription_list[0]['token']).to eq(subscription_token)
|
188
|
+
end
|
189
|
+
end
|
data/spec/recipients_spec.rb
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Pin::Recipient, :vcr do
|
4
|
+
let(:recipient_details) {
|
5
|
+
{ email: 'hello@example.com',
|
6
|
+
name: 'Roland Robot',
|
7
|
+
bank_account: {
|
8
|
+
name: 'Roland Robot',
|
9
|
+
bsb: '123456',
|
10
|
+
number: 987654321
|
11
|
+
} }
|
12
|
+
}
|
13
|
+
|
4
14
|
before(:each) do
|
5
15
|
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
6
16
|
end
|
7
17
|
|
8
18
|
it 'should create a new recipient' do
|
9
|
-
|
10
|
-
expect(Pin::Recipient.create(options)['token']).to match(/^[a-z]{2}[_]/)
|
19
|
+
expect(Pin::Recipient.create(recipient_details)['token']).to match(/^[a-z]{2}[_]/)
|
11
20
|
end
|
12
21
|
|
13
22
|
it 'lists out recipients' do
|
@@ -15,22 +24,18 @@ describe Pin::Recipient, :vcr do
|
|
15
24
|
end
|
16
25
|
|
17
26
|
it 'gets a recipient given a token' do
|
18
|
-
|
19
|
-
recipient = Pin::Recipient.create(options)
|
27
|
+
recipient = Pin::Recipient.create(recipient_details)
|
20
28
|
expect(Pin::Recipient.find(recipient['token'])['token']).to eq recipient['token']
|
21
29
|
end
|
22
30
|
|
23
31
|
it 'updates the given details of a recipient and returns its details' do
|
24
|
-
|
25
|
-
recipient = Pin::Recipient.create(options)
|
32
|
+
recipient = Pin::Recipient.create(recipient_details)
|
26
33
|
updated_options = { email: 'new_email@example.com' }
|
27
34
|
expect(Pin::Recipient.update(recipient['token'], updated_options)['email']).to eq 'new_email@example.com'
|
28
35
|
end
|
29
36
|
|
30
37
|
it 'returns a list of recipients transfers' do
|
31
|
-
|
32
|
-
recipient = Pin::Recipient.create(options)
|
33
|
-
|
38
|
+
recipient = Pin::Recipient.create(recipient_details)
|
34
39
|
transfer = { amount: 400, currency: 'AUD', description: 'Pay day', recipient: recipient['token'] }
|
35
40
|
Pin::Transfer.create(transfer)
|
36
41
|
|
data/spec/refund_spec.rb
CHANGED
@@ -1,27 +1,61 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Refund', :vcr, class: Pin::Refund 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(:customer_token) {
|
18
|
+
Pin::Customer.create('email@example.com', card_1)['token']
|
19
|
+
}
|
20
|
+
|
21
|
+
let(:charge) {
|
22
|
+
Pin::Charges.create(email: 'email@example.com',
|
23
|
+
description: 'Charge description',
|
24
|
+
amount: '500',
|
25
|
+
currency: 'AUD',
|
26
|
+
number: '5520000000000000',
|
27
|
+
ip_address: '203.192.1.172',
|
28
|
+
customer_token: customer_token)
|
29
|
+
}
|
30
|
+
|
31
|
+
let(:no_refund_charge) {
|
32
|
+
Pin::Charges.create(email: 'email@example.com',
|
33
|
+
description: 'Charge description',
|
34
|
+
amount: '500',
|
35
|
+
currency: 'AUD',
|
36
|
+
number: '5520000000000000',
|
37
|
+
ip_address: '203.192.1.172',
|
38
|
+
customer_token: customer_token)
|
39
|
+
}
|
40
|
+
|
4
41
|
before(:each) do
|
5
42
|
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
43
|
+
Pin::Refund.create(charge['token'], '400')
|
6
44
|
end
|
7
45
|
|
8
46
|
it 'should list all refunds made to a charge given a token' do
|
9
|
-
expect(Pin::Refund.find('
|
47
|
+
expect(Pin::Refund.find(charge['token'])[0]['token']).to match(/^[a-z]{2}[_]/)
|
10
48
|
end
|
11
49
|
|
12
50
|
it 'should return nothing if looking for a charge without a refund' do
|
13
|
-
expect(Pin::Refund.find('
|
51
|
+
expect(Pin::Refund.find(no_refund_charge['token'])).to eq []
|
14
52
|
end
|
15
53
|
|
16
54
|
it 'should return a page of refunds given a page and token' do
|
17
|
-
expect(Pin::Refund.find('
|
55
|
+
expect(Pin::Refund.find(charge['token'], 1, true)[:response]).to_not eq []
|
18
56
|
end
|
19
57
|
|
20
58
|
it 'should create a refund for a given amount and charge' do
|
21
|
-
|
22
|
-
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']}
|
23
|
-
@charge = Pin::Charges.create(options)
|
24
|
-
expect(Pin::Refund.create(@charge['token'], '400')['amount']).to eq 400
|
59
|
+
expect(Pin::Refund.find(charge['token'])[0]['amount']).to eq 400
|
25
60
|
end
|
26
|
-
|
27
61
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
require 'codeclimate-test-reporter'
|
2
1
|
require 'simplecov'
|
3
2
|
|
4
|
-
CodeClimate::TestReporter.start
|
5
3
|
SimpleCov.start
|
6
4
|
|
7
5
|
require 'rubygems'
|
@@ -25,7 +23,9 @@ RSpec.configure do |config|
|
|
25
23
|
.metadata[:full_description]
|
26
24
|
.split(/\s+/, 2).join('/')
|
27
25
|
.gsub(/[^\w\/]+/, '_')
|
28
|
-
|
26
|
+
valid_keys = %w[record match_on_requests_on]
|
27
|
+
options = example.metadata.select { |key,_| valid_keys.include? key }
|
28
|
+
VCR.use_cassette(name, record: :all) { example.call }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,5 +33,4 @@ VCR.configure do |c|
|
|
33
33
|
c.cassette_library_dir = 'spec/vcr'
|
34
34
|
c.hook_into :webmock
|
35
35
|
c.allow_http_connections_when_no_cassette = true
|
36
|
-
c.filter_sensitive_data('<key>') { ENV['PIN_SECRET'] }
|
37
36
|
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Subscription', :vcr, class: Pin::Subscription do
|
4
|
+
let(:time) { Time.now.iso8601(4) }
|
5
|
+
let(:plan_1) {
|
6
|
+
{ name: "Subscription#{time}",
|
7
|
+
amount: '1000',
|
8
|
+
currency: 'AUD',
|
9
|
+
interval: 30,
|
10
|
+
interval_unit: 'day',
|
11
|
+
setup_amount: 0,
|
12
|
+
trial_amount: 0,
|
13
|
+
trial_interval: 7,
|
14
|
+
trial_interval_unit: 'day' }
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:plan_2) {
|
18
|
+
{ name: "Subscription#{time}",
|
19
|
+
amount: '1000',
|
20
|
+
currency: 'AUD',
|
21
|
+
interval: 30,
|
22
|
+
interval_unit: 'day',
|
23
|
+
setup_amount: 27900,
|
24
|
+
trial_amount: 0,
|
25
|
+
trial_interval: '',
|
26
|
+
trial_interval_unit: '' }
|
27
|
+
}
|
28
|
+
|
29
|
+
let(:plan_1_token) {
|
30
|
+
Pin::Plan.create(plan_1)['token']
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:plan_2_token) {
|
34
|
+
Pin::Plan.create(plan_2)['token']
|
35
|
+
}
|
36
|
+
|
37
|
+
let(:card_1) {
|
38
|
+
{ number: '5520000000000000',
|
39
|
+
expiry_month: '12',
|
40
|
+
expiry_year: '2025',
|
41
|
+
cvc: '123',
|
42
|
+
name: 'Roland Robot',
|
43
|
+
address_line1: '123 Fake Street',
|
44
|
+
address_city: 'Melbourne',
|
45
|
+
address_postcode: '1234',
|
46
|
+
address_state: 'Vic',
|
47
|
+
address_country: 'Australia' }
|
48
|
+
}
|
49
|
+
|
50
|
+
let(:card_2) {
|
51
|
+
{ number: '4200000000000000',
|
52
|
+
expiry_month: '12',
|
53
|
+
expiry_year: '2020',
|
54
|
+
cvc: '111',
|
55
|
+
name: 'Roland TestRobot',
|
56
|
+
address_line1: '123 Fake Road',
|
57
|
+
address_line2: '',
|
58
|
+
address_city: 'Melbourne',
|
59
|
+
address_postcode: '1223',
|
60
|
+
address_state: 'Vic',
|
61
|
+
address_country: 'AU' }
|
62
|
+
}
|
63
|
+
|
64
|
+
let(:customer) {
|
65
|
+
Pin::Customer.create('email@example.com', card_1)
|
66
|
+
}
|
67
|
+
|
68
|
+
let(:customer_token) {
|
69
|
+
customer['token']
|
70
|
+
}
|
71
|
+
|
72
|
+
let(:card_2_token) {
|
73
|
+
Pin::Card.create(card_2)['token']
|
74
|
+
}
|
75
|
+
|
76
|
+
let(:link_card_2_to_customer) {
|
77
|
+
Pin::Customer.create_card(customer_token, card_2_token)
|
78
|
+
}
|
79
|
+
|
80
|
+
let(:subscription_1) {
|
81
|
+
{ plan_token: plan_1_token,
|
82
|
+
customer_token: customer_token,
|
83
|
+
include_setup_fee: false }
|
84
|
+
}
|
85
|
+
|
86
|
+
let(:subscription_2) {
|
87
|
+
link_card_2_to_customer
|
88
|
+
{ plan_token: plan_2_token,
|
89
|
+
customer_token: customer_token,
|
90
|
+
card_token: card_2_token,
|
91
|
+
include_setup_fee: true }
|
92
|
+
}
|
93
|
+
|
94
|
+
let(:subscription_1_token) {
|
95
|
+
Pin::Subscription.create(subscription_1)['token']
|
96
|
+
}
|
97
|
+
|
98
|
+
let(:subscription_2_token) {
|
99
|
+
Pin::Subscription.create(subscription_2)['token']
|
100
|
+
}
|
101
|
+
|
102
|
+
before(:each) do
|
103
|
+
Pin::Base.new(ENV['PIN_SECRET'], :test)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should create a new subscription billing default card and return its details' do
|
107
|
+
expect(Pin::Subscription.create(subscription_1))
|
108
|
+
.to match a_hash_including("state"=>"trial",
|
109
|
+
"cancelled_at"=>nil,
|
110
|
+
"token"=>match(/(sub)[_]([\w-]{22})/),
|
111
|
+
"plan_token"=>"#{plan_1_token}",
|
112
|
+
"customer_token"=>"#{customer_token}",
|
113
|
+
"card_token"=> nil)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should create a new subscription billing card_2' do
|
117
|
+
expect(Pin::Subscription.create(subscription_2))
|
118
|
+
.to match a_hash_including("state"=>"active",
|
119
|
+
"token"=>match(/(sub)[_]([\w-]{22})/),
|
120
|
+
"plan_token"=>"#{plan_2_token}",
|
121
|
+
"customer_token"=>"#{customer_token}",
|
122
|
+
"card_token"=>"#{card_2_token}")
|
123
|
+
charges = Pin::Customer.charges(customer_token)
|
124
|
+
expect(charges[0]['card']['token']).to eq(card_2_token)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should create a new subscription with setup fee, charge equals amount + setup fee' do
|
128
|
+
Pin::Subscription.create(subscription_2)
|
129
|
+
charges = Pin::Customer.charges(customer_token)
|
130
|
+
expect(charges[0]['amount'].to_i).to eq (plan_2[:setup_amount].to_i + plan_2[:amount].to_i)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should list all subscriptions' do
|
134
|
+
expect(Pin::Subscription.all).to_not eq []
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should go to a specific page when page paramater is passed' do
|
138
|
+
request = Pin::Subscription.all(20, true)
|
139
|
+
expect(request[:pagination]['current']).to eq 20
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should list subscriptions on a page given a page' do
|
143
|
+
request = Pin::Subscription.all(1, true)
|
144
|
+
expect(request[:response]).to_not eq []
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should return pagination if true is passed for pagination' do
|
148
|
+
request = Pin::Subscription.all(1, true)
|
149
|
+
request[:pagination].keys.include?(%W('current previous next per_page pages count))
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should not list subscriptions for a given page if there are no subscriptions' do
|
153
|
+
request = Pin::Subscription.all(25, true)
|
154
|
+
expect(request[:response]).to eq []
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should show a subscription given a token' do
|
158
|
+
expect(Pin::Subscription.find(subscription_2_token)['token']).to eq(subscription_2_token)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should update the subscription charged card given a subscription & card token' do
|
162
|
+
Pin::Customer.create_card(customer_token, card_2_token) # register card to customer
|
163
|
+
sub = Pin::Subscription.update(subscription_1_token, card_2_token)
|
164
|
+
expect(sub['card_token']).to eq card_2_token
|
165
|
+
primary_customer_card_token = customer['card']['token']
|
166
|
+
expect(primary_customer_card_token).to_not eq card_2_token
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should delete(deactivate) a subscription given a token' do
|
170
|
+
expect(Pin::Subscription.delete(subscription_2_token)['state']).to eq('cancelling')
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should reactivate the subscription given a token' do
|
174
|
+
deactivated = Pin::Subscription.delete(subscription_2_token)
|
175
|
+
expect(Pin::Subscription.reactivate(deactivated['token'])['state']).to eq('active')
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should fetch history for a subscription given a token' do
|
179
|
+
expect(Pin::Subscription.history(subscription_2_token)).to_not eq []
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should go to a specific page when page parameter is passed' do
|
183
|
+
request = Pin::Subscription.history(subscription_2_token, 20, true)
|
184
|
+
expect(request[:pagination]['current']).to eq 20
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should list subscriptions on a page given a page' do
|
188
|
+
request = Pin::Subscription.history(subscription_2_token, 1, true)
|
189
|
+
expect(request[:response]).to_not eq []
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should return pagination if true is passed for pagination' do
|
193
|
+
request = Pin::Subscription.history(subscription_2_token, 1, true)
|
194
|
+
request[:pagination].key?(%W('current previous next per_page pages count))
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should not list subscriptions for a given page if there are no subscriptions' do
|
198
|
+
request = Pin::Subscription.history(subscription_2_token, 25, true)
|
199
|
+
expect(request[:response]).to eq []
|
200
|
+
end
|
201
|
+
end
|