paymill_ruby 1.0.2
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 +7 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +223 -0
- data/Rakefile +6 -0
- data/lib/paymill.rb +54 -0
- data/lib/paymill/errors.rb +10 -0
- data/lib/paymill/models/address.rb +13 -0
- data/lib/paymill/models/base.rb +50 -0
- data/lib/paymill/models/checksum.rb +40 -0
- data/lib/paymill/models/client.rb +24 -0
- data/lib/paymill/models/fee.rb +14 -0
- data/lib/paymill/models/invoice.rb +18 -0
- data/lib/paymill/models/merchant.rb +21 -0
- data/lib/paymill/models/offer.rb +27 -0
- data/lib/paymill/models/payment.rb +20 -0
- data/lib/paymill/models/payment_method.rb +18 -0
- data/lib/paymill/models/preauthorization.rb +25 -0
- data/lib/paymill/models/refund.rb +22 -0
- data/lib/paymill/models/shopping_cart_item.rb +13 -0
- data/lib/paymill/models/subscription.rb +143 -0
- data/lib/paymill/models/subscription_count.rb +18 -0
- data/lib/paymill/models/transaction.rb +27 -0
- data/lib/paymill/models/webhook.rb +37 -0
- data/lib/paymill/restful/methods.rb +134 -0
- data/lib/paymill/version.rb +3 -0
- data/paymill.gemspec +28 -0
- data/samples/authentication/authentication.rb +1 -0
- data/samples/clients/create_new_client.rb +4 -0
- data/samples/clients/export_clients_list.rb +1 -0
- data/samples/clients/get_client_details.rb +1 -0
- data/samples/clients/list_clients.rb +1 -0
- data/samples/clients/remove_client.rb +2 -0
- data/samples/clients/update_client.rb +4 -0
- data/samples/offers/create_new_offer.rb +7 -0
- data/samples/offers/export_offers_list.rb +1 -0
- data/samples/offers/get_offer_details.rb +1 -0
- data/samples/offers/list_offers.rb +1 -0
- data/samples/offers/remove_offer.rb +7 -0
- data/samples/offers/update_offer.rb +8 -0
- data/samples/payments/create_new_credit_card_payment_with_token.rb +1 -0
- data/samples/payments/create_new_credit_card_payment_with_token_and_client.rb +4 -0
- data/samples/payments/create_new_debit_payment_with_token.rb +1 -0
- data/samples/payments/create_new_debit_payment_with_token_and_client.rb +4 -0
- data/samples/payments/export_payments_list.rb +1 -0
- data/samples/payments/get_payment_details.rb +1 -0
- data/samples/payments/list_payments.rb +1 -0
- data/samples/payments/remove_payment.rb +2 -0
- data/samples/preauthorizations/create_new_preauthorization_with_payment.rb +8 -0
- data/samples/preauthorizations/create_new_preauthorization_with_token.rb +6 -0
- data/samples/preauthorizations/export_preauthorizations_list.rb +1 -0
- data/samples/preauthorizations/get_preauthorization_details.rb +1 -0
- data/samples/preauthorizations/list_preauthozizations.rb +1 -0
- data/samples/preauthorizations/remove_preauthorization.rb +2 -0
- data/samples/refunds/create_new_refund.rb +11 -0
- data/samples/refunds/export_refunds_list.rb +1 -0
- data/samples/refunds/get_refund_details.rb +1 -0
- data/samples/refunds/list_refunds.rb +1 -0
- data/samples/subscriptions/cancel_subscription.rb +2 -0
- data/samples/subscriptions/create_new_subscription_with_an_offer.rb +15 -0
- data/samples/subscriptions/create_new_subscription_with_an_offer_and_different_values.rb +19 -0
- data/samples/subscriptions/create_new_subscription_without_an_offer.rb +13 -0
- data/samples/subscriptions/delete_subscription.rb +2 -0
- data/samples/subscriptions/export_subscriptions_list.rb +1 -0
- data/samples/subscriptions/get_subscription_details.rb +1 -0
- data/samples/subscriptions/list_subscriptions.rb +1 -0
- data/samples/subscriptions/pause_subscription.rb +7 -0
- data/samples/subscriptions/update_subscription.rb +12 -0
- data/samples/subscriptions/update_subscription_amount.rb +7 -0
- data/samples/subscriptions/update_subscription_offer.rb +14 -0
- data/samples/transactions/create_new_transaction_with_app_fee.rb +8 -0
- data/samples/transactions/create_new_transaction_with_client_and_payment.rb +12 -0
- data/samples/transactions/create_new_transaction_with_payment.rb +7 -0
- data/samples/transactions/create_new_transaction_with_preauthorization.rb +10 -0
- data/samples/transactions/create_new_transaction_with_token.rb +6 -0
- data/samples/transactions/export_transactions_list.rb +1 -0
- data/samples/transactions/get_transaction_details_by_id.rb +1 -0
- data/samples/transactions/get_transaction_details_by_slv.rb +1 -0
- data/samples/transactions/list_transactions.rb +1 -0
- data/samples/transactions/upate_transaction.rb +3 -0
- data/samples/webhooks/create_new_email_webhook.rb +5 -0
- data/samples/webhooks/create_new_url_webhook.rb +4 -0
- data/samples/webhooks/export_webhooks_list.rb +1 -0
- data/samples/webhooks/get_webhook_details.rb +1 -0
- data/samples/webhooks/remove_webhook.rb +2 -0
- data/samples/webhooks/update_webhook.rb +3 -0
- data/spec/paymill/models/address_spec.rb +42 -0
- data/spec/paymill/models/checksum_spec.rb +77 -0
- data/spec/paymill/models/client_spec.rb +311 -0
- data/spec/paymill/models/offer_spec.rb +151 -0
- data/spec/paymill/models/payment_spec.rb +188 -0
- data/spec/paymill/models/preauthorization_spec.rb +180 -0
- data/spec/paymill/models/refund_spec.rb +90 -0
- data/spec/paymill/models/subscription_spec.rb +607 -0
- data/spec/paymill/models/transaction_spec.rb +226 -0
- data/spec/paymill/models/webhook_spec.rb +195 -0
- data/spec/spec_helper.rb +28 -0
- metadata +265 -0
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Paymill
|
4
|
+
describe Transaction do
|
5
|
+
|
6
|
+
let( :amount ) { 2990 }
|
7
|
+
let( :currency ) { 'USD' }
|
8
|
+
let( :client ) { Client.create( email: 'rocky.balboa@qaiware.com' ) }
|
9
|
+
|
10
|
+
transaction_id = nil
|
11
|
+
|
12
|
+
context '::create' do
|
13
|
+
before( :each ) do
|
14
|
+
uri = URI.parse("https://test-token.paymill.com?transaction.mode=CONNECTOR_TEST&channel.id=941569045353c8ac2a5689deb88871bb&jsonPFunction=paymilljstests&account.number=4111111111111111&account.expiry.month=12&account.expiry.year=2015&account.verification=123&account.holder=John%20Rambo&presentation.amount3D=3201&presentation.currency3D=EUR")
|
15
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
https.use_ssl = true
|
17
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
18
|
+
request.basic_auth( ENV['PAYMILL_API_TEST_KEY'], "" )
|
19
|
+
response = https.request(request)
|
20
|
+
@token = response.body.match('tok_[a-z|0-9]+')[0]
|
21
|
+
@payment = Payment.create( token: @token, client: client.id )
|
22
|
+
@preauth = Preauthorization.create( payment: @payment, amount: amount, currency: currency, description: 'The Italian Stallion' )
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should create transaction with token', :vcr do
|
26
|
+
transaction = Transaction.create( token: @token, amount: amount, currency: currency, mandate_reference: 'Terminator' )
|
27
|
+
transaction_id = transaction.id
|
28
|
+
|
29
|
+
expect( transaction ).to be_a Transaction
|
30
|
+
|
31
|
+
expect( transaction.id ).to be_a String
|
32
|
+
expect( transaction.amount ).to be amount
|
33
|
+
expect( transaction.origin_amount ).to be amount
|
34
|
+
expect( transaction.status ).to eq 'closed'
|
35
|
+
expect( transaction.mandate_reference ).to eq 'Terminator'
|
36
|
+
expect( transaction.description ).to be_empty
|
37
|
+
expect( transaction.livemode ).to be false
|
38
|
+
expect( transaction.refunds ).to be_nil
|
39
|
+
expect( transaction.currency ).to eq currency
|
40
|
+
expect( transaction.created_at ).to be_a Time
|
41
|
+
expect( transaction.updated_at ).to be_a Time
|
42
|
+
expect( transaction.response_code ).to be 20000
|
43
|
+
expect( transaction.is_fraud ).to be false
|
44
|
+
expect( transaction.short_id ).to eq '0000.9999.0000'
|
45
|
+
expect( transaction.fees ).to be_empty
|
46
|
+
expect( transaction.invoices ).to be_empty
|
47
|
+
expect( transaction.payment ).to be_a Payment
|
48
|
+
expect( transaction.client ).to be_a Client
|
49
|
+
expect( transaction.preauthorization ).to be_nil
|
50
|
+
expect( transaction.app_id ).to be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should create transaction with token and description', :vcr do
|
54
|
+
transaction = Transaction.create( token: @token, amount: amount, currency: currency, description: 'The Italian Stallion' )
|
55
|
+
|
56
|
+
expect( transaction ).to be_a Transaction
|
57
|
+
|
58
|
+
expect( transaction.id ).to be_a String
|
59
|
+
expect( transaction.amount ).to be amount
|
60
|
+
expect( transaction.origin_amount ).to be amount
|
61
|
+
expect( transaction.status ).to eq 'closed'
|
62
|
+
expect( transaction.description ).to eq 'The Italian Stallion'
|
63
|
+
expect( transaction.mandate_reference ).to be nil
|
64
|
+
expect( transaction.livemode ).to be false
|
65
|
+
expect( transaction.refunds ).to be_nil
|
66
|
+
expect( transaction.currency ).to eq currency
|
67
|
+
expect( transaction.created_at ).to be_a Time
|
68
|
+
expect( transaction.updated_at ).to be_a Time
|
69
|
+
expect( transaction.response_code ).to be 20000
|
70
|
+
expect( transaction.is_fraud ).to be false
|
71
|
+
expect( transaction.short_id ).to eq '0000.9999.0000'
|
72
|
+
expect( transaction.fees ).to be_empty
|
73
|
+
expect( transaction.invoices ).to be_empty
|
74
|
+
expect( transaction.payment ).to be_a Payment
|
75
|
+
expect( transaction.client ).to be_a Client
|
76
|
+
expect( transaction.preauthorization ).to be_nil
|
77
|
+
expect( transaction.app_id ).to be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should create transaction with payment', :vcr do
|
81
|
+
transaction = Transaction.create( payment: @payment, amount: amount, currency: currency )
|
82
|
+
|
83
|
+
expect( transaction ).to be_a Transaction
|
84
|
+
|
85
|
+
expect( transaction.id ).to be_a String
|
86
|
+
expect( transaction.amount ).to be amount
|
87
|
+
expect( transaction.origin_amount ).to be amount
|
88
|
+
expect( transaction.status ).to eq 'closed'
|
89
|
+
expect( transaction.description ).to be_empty
|
90
|
+
expect( transaction.livemode ).to be false
|
91
|
+
expect( transaction.refunds ).to be_nil
|
92
|
+
expect( transaction.currency ).to eq currency
|
93
|
+
expect( transaction.created_at ).to be_a Time
|
94
|
+
expect( transaction.updated_at ).to be_a Time
|
95
|
+
expect( transaction.response_code ).to be 20000
|
96
|
+
expect( transaction.is_fraud ).to be false
|
97
|
+
expect( transaction.short_id ).to eq '0000.9999.0000'
|
98
|
+
expect( transaction.fees ).to be_empty
|
99
|
+
expect( transaction.invoices ).to be_empty
|
100
|
+
expect( transaction.payment.id ).to eq @payment.id
|
101
|
+
expect( transaction.client.id ).to eq client.id
|
102
|
+
expect( transaction.client.email ).to eq 'rocky.balboa@qaiware.com'
|
103
|
+
expect( transaction.app_id ).to be_nil
|
104
|
+
|
105
|
+
expect( transaction.preauthorization ).to be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should create transaction with preauthorization', :vcr do
|
109
|
+
transaction = Transaction.create( preauthorization: @preauth, amount: amount, currency: currency )
|
110
|
+
|
111
|
+
expect( transaction ).to be_a Transaction
|
112
|
+
|
113
|
+
expect( transaction.id ).to be_a String
|
114
|
+
expect( transaction.amount ).to be amount
|
115
|
+
expect( transaction.origin_amount ).to be amount
|
116
|
+
expect( transaction.status ).to eq 'closed'
|
117
|
+
expect( transaction.description ).to be_empty
|
118
|
+
expect( transaction.livemode ).to be false
|
119
|
+
expect( transaction.refunds ).to be_nil
|
120
|
+
expect( transaction.currency ).to eq currency
|
121
|
+
expect( transaction.created_at ).to be_a Time
|
122
|
+
expect( transaction.updated_at ).to be_a Time
|
123
|
+
expect( transaction.response_code ).to be 20000
|
124
|
+
expect( transaction.is_fraud ).to be false
|
125
|
+
expect( transaction.short_id ).to eq '0000.9999.0000'
|
126
|
+
expect( transaction.fees ).to be_empty
|
127
|
+
expect( transaction.invoices ).to be_empty
|
128
|
+
expect( transaction.payment.id ).to eq @payment.id
|
129
|
+
expect( transaction.client.id ).to eq client.id
|
130
|
+
expect( transaction.client.email ).to eq 'rocky.balboa@qaiware.com'
|
131
|
+
expect( transaction.app_id ).to be_nil
|
132
|
+
|
133
|
+
expect( transaction.preauthorization.id ).to eq @preauth.id
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should create transaction with client and payment', :vcr do
|
137
|
+
transaction = Transaction.create( payment: @payment, amount: amount, currency: currency, client: client )
|
138
|
+
|
139
|
+
expect( transaction ).to be_a Transaction
|
140
|
+
|
141
|
+
expect( transaction.id ).to be_a String
|
142
|
+
expect( transaction.amount ).to be amount
|
143
|
+
expect( transaction.origin_amount ).to be amount
|
144
|
+
expect( transaction.status ).to eq 'closed'
|
145
|
+
expect( transaction.description ).to be_empty
|
146
|
+
expect( transaction.livemode ).to be false
|
147
|
+
expect( transaction.refunds ).to be_nil
|
148
|
+
expect( transaction.currency ).to eq currency
|
149
|
+
expect( transaction.created_at ).to be_a Time
|
150
|
+
expect( transaction.updated_at ).to be_a Time
|
151
|
+
expect( transaction.response_code ).to be 20000
|
152
|
+
expect( transaction.is_fraud ).to be false
|
153
|
+
expect( transaction.short_id ).to eq '0000.9999.0000'
|
154
|
+
expect( transaction.fees ).to be_empty
|
155
|
+
expect( transaction.invoices ).to be_empty
|
156
|
+
expect( transaction.payment.id ).to eq @payment.id
|
157
|
+
expect( transaction.client.id ).to eq client.id
|
158
|
+
expect( transaction.client.email ).to eq 'rocky.balboa@qaiware.com'
|
159
|
+
expect( transaction.app_id ).to be_nil
|
160
|
+
|
161
|
+
expect( transaction.preauthorization ).to be_nil
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should throw PaymillError with payment and different client', :vcr do
|
165
|
+
expect{ Transaction.create( payment: @payment, amount: amount, currency: currency, client: Client.create() ) }.to raise_error PaymillError
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should throw ArgumentError when creating with token and payment', :vcr do
|
169
|
+
expect{ Transaction.create( token: @token, payment: @payment, currency: currency, amount: amount ) }.to raise_error ArgumentError
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should throw ArgumentError when creating with token and payment and preauthorization', :vcr do
|
173
|
+
expect{ Transaction.create( token: @token, payment: @payment, preauthorization: @preauth, currency: currency, amount: amount ) }.to raise_error ArgumentError
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context '::find' do
|
178
|
+
it 'should find transaction by valid id', :vcr do
|
179
|
+
expect( Transaction.find( transaction_id ).id ).to eq transaction_id
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should throw PaymillError when unvalid id given', :vcr do
|
183
|
+
expect{ Transaction.find( 'fake_id' ) }.to raise_error PaymillError
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context '::update' do
|
188
|
+
it 'should update existing transaction description', :vcr do
|
189
|
+
transaction = Transaction.find( transaction_id )
|
190
|
+
|
191
|
+
transaction.description = 'The Italian Stallion'
|
192
|
+
transaction.update
|
193
|
+
|
194
|
+
expect( transaction ).to be_a Transaction
|
195
|
+
|
196
|
+
expect( transaction.id ).to be_a String
|
197
|
+
expect( transaction.amount ).to be amount
|
198
|
+
expect( transaction.origin_amount ).to be amount
|
199
|
+
expect( transaction.status ).to eq 'closed'
|
200
|
+
expect( transaction.description ).to eq 'The Italian Stallion'
|
201
|
+
expect( transaction.livemode ).to be false
|
202
|
+
expect( transaction.refunds ).to be_nil
|
203
|
+
expect( transaction.currency ).to eq currency
|
204
|
+
expect( transaction.created_at ).to be_a Time
|
205
|
+
expect( transaction.updated_at ).to be_a Time
|
206
|
+
expect( transaction.response_code ).to be 20000
|
207
|
+
expect( transaction.is_fraud ).to be false
|
208
|
+
expect( transaction.short_id ).to eq '0000.9999.0000'
|
209
|
+
expect( transaction.fees ).to be_empty
|
210
|
+
expect( transaction.invoices ).to be_empty
|
211
|
+
expect( transaction.payment ).to be_a Payment
|
212
|
+
expect( transaction.client ).to be_a Client
|
213
|
+
expect( transaction.preauthorization ).to be_nil
|
214
|
+
expect( transaction.app_id ).to be_nil
|
215
|
+
expect( transaction.created_at ).to be < transaction.updated_at
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should throw NoMethodError when by updating transaction's amount", :vcr do
|
219
|
+
transaction = Transaction.find( transaction_id )
|
220
|
+
|
221
|
+
expect{ transaction.amount = 999 }.to raise_error NoMethodError
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Paymill
|
4
|
+
describe Webhook do
|
5
|
+
|
6
|
+
active_webhook_id = nil
|
7
|
+
inactive_webhook_id = nil
|
8
|
+
|
9
|
+
context '::create' do
|
10
|
+
it 'should create url hook', :vcr do
|
11
|
+
webhook = Webhook.create( url: 'http://example.com', event_types: ['transaction.succeeded', 'transaction.failed'] )
|
12
|
+
active_webhook_id = webhook.id
|
13
|
+
|
14
|
+
expect( webhook.id ).to be_a String
|
15
|
+
expect( webhook.url ).to eq 'http://example.com'
|
16
|
+
expect( webhook.livemode ).to be false
|
17
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed']
|
18
|
+
expect( webhook.created_at ).to be_a Time
|
19
|
+
expect( webhook.updated_at ).to be_a Time
|
20
|
+
expect( webhook.active ).to be true
|
21
|
+
expect( webhook.app_id ).to be nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should create inactivated email hook', :vcr do
|
25
|
+
webhook = Webhook.create( email: 'rambo@qaiware.com', event_types: ['refund.failed'], active: false )
|
26
|
+
inactive_webhook_id = webhook.id
|
27
|
+
|
28
|
+
expect( webhook.id ).to be_a String
|
29
|
+
expect( webhook.email ).to eq 'rambo@qaiware.com'
|
30
|
+
expect( webhook.livemode ).to be false
|
31
|
+
expect( webhook.event_types ).to eq ['refund.failed']
|
32
|
+
expect( webhook.created_at ).to be_a Time
|
33
|
+
expect( webhook.updated_at ).to be_a Time
|
34
|
+
expect( webhook.active ).to be false
|
35
|
+
expect( webhook.app_id ).to be nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should throw ArgumentError when creating without event types', :vcr do
|
39
|
+
expect{ Webhook.create( email: 'rambo@qaiware.com' ) }.to raise_error ArgumentError
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should throw ArgumentError when creating wit invalid argument', :vcr do
|
43
|
+
expect{ Webhook.create( email: 'rambo@qaiware.com', event_types: ['transaction.succeeded'], fake: true ) }.to raise_error ArgumentError
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should throw ArgumentError when creating wit email and url', :vcr do
|
47
|
+
expect{ Webhook.create( email: 'rambo@qaiware.com', event_types: ['transaction.succeeded'], url: 'http://example.com' ) }.to raise_error ArgumentError
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should throw ArgumentError when creating without email or url', :vcr do
|
51
|
+
expect{ Webhook.create( event_types: ['transaction.succeeded', 'transaction.failed'] ) }.to raise_error ArgumentError
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '::find' do
|
56
|
+
it 'should find webhook by valid id', :vcr do
|
57
|
+
webhook = Webhook.find( active_webhook_id )
|
58
|
+
|
59
|
+
expect( webhook.id ).to eq active_webhook_id
|
60
|
+
expect( webhook.url ).to eq 'http://example.com'
|
61
|
+
expect( webhook.livemode ).to be false
|
62
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed']
|
63
|
+
expect( webhook.created_at ).to be_a Time
|
64
|
+
expect( webhook.updated_at ).to be_a Time
|
65
|
+
expect( webhook.active ).to be true
|
66
|
+
expect( webhook.app_id ).to be nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should throw PaymillError when unvalid id given', :vcr do
|
70
|
+
expect{ Webhook.find( 'fake_id' ) }.to raise_error PaymillError
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '::update' do
|
75
|
+
it 'should update type from url to email', :vcr do
|
76
|
+
webhook = Webhook.find( active_webhook_id )
|
77
|
+
id = webhook.to_s
|
78
|
+
|
79
|
+
webhook.email = 'rocky@qaiware.com'
|
80
|
+
webhook.update
|
81
|
+
|
82
|
+
expect( webhook.to_s ).to eq id
|
83
|
+
expect( webhook.id ).to eq active_webhook_id
|
84
|
+
expect( webhook.email ).to eq 'rocky@qaiware.com'
|
85
|
+
expect( webhook.url ).to be_nil
|
86
|
+
expect( webhook.livemode ).to be false
|
87
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed']
|
88
|
+
expect( webhook.created_at ).to be_a Time
|
89
|
+
expect( webhook.updated_at ).to be_a Time
|
90
|
+
expect( webhook.active ).to be true
|
91
|
+
expect( webhook.app_id ).to be nil
|
92
|
+
expect( webhook.created_at ).to be < webhook.updated_at
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should update type from email to url', :vcr do
|
96
|
+
webhook = Webhook.find( active_webhook_id )
|
97
|
+
webhook.url = 'https://qaiware.com'
|
98
|
+
|
99
|
+
webhook.update
|
100
|
+
|
101
|
+
expect( webhook.id ).to eq active_webhook_id
|
102
|
+
expect( webhook.email ).to be_nil
|
103
|
+
expect( webhook.url ).to eq 'https://qaiware.com'
|
104
|
+
expect( webhook.livemode ).to be false
|
105
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed']
|
106
|
+
expect( webhook.created_at ).to be_a Time
|
107
|
+
expect( webhook.updated_at ).to be_a Time
|
108
|
+
expect( webhook.active ).to be true
|
109
|
+
expect( webhook.app_id ).to be nil
|
110
|
+
expect( webhook.created_at ).to be < webhook.updated_at
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should add one event type', :vcr do
|
114
|
+
webhook = Webhook.find( active_webhook_id )
|
115
|
+
webhook.event_types << 'transaction.created'
|
116
|
+
|
117
|
+
webhook.update()
|
118
|
+
|
119
|
+
expect( webhook.id ).to eq active_webhook_id
|
120
|
+
expect( webhook.email ).to be_nil
|
121
|
+
expect( webhook.url ).to eq 'https://qaiware.com'
|
122
|
+
expect( webhook.livemode ).to be false
|
123
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed', 'transaction.created']
|
124
|
+
expect( webhook.created_at ).to be_a Time
|
125
|
+
expect( webhook.updated_at ).to be_a Time
|
126
|
+
expect( webhook.active ).to be true
|
127
|
+
expect( webhook.app_id ).to be nil
|
128
|
+
expect( webhook.created_at ).to be < webhook.updated_at
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should delete one event type', :vcr do
|
132
|
+
webhook = Webhook.find( active_webhook_id )
|
133
|
+
webhook.event_types.delete 'transaction.created'
|
134
|
+
|
135
|
+
webhook.update
|
136
|
+
|
137
|
+
expect( webhook.id ).to eq active_webhook_id
|
138
|
+
expect( webhook.email ).to be_nil
|
139
|
+
expect( webhook.url ).to eq 'https://qaiware.com'
|
140
|
+
expect( webhook.livemode ).to be false
|
141
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed']
|
142
|
+
expect( webhook.created_at ).to be_a Time
|
143
|
+
expect( webhook.updated_at ).to be_a Time
|
144
|
+
expect( webhook.active ).to be true
|
145
|
+
expect( webhook.app_id ).to be nil
|
146
|
+
expect( webhook.created_at ).to be < webhook.updated_at
|
147
|
+
end
|
148
|
+
|
149
|
+
xit 'should deactivate the webhook', :vcr do
|
150
|
+
#TODO[VNi]: API can not deactivate a hook
|
151
|
+
webhook = Webhook.find( active_webhook_id )
|
152
|
+
webhook.active = false
|
153
|
+
|
154
|
+
webhook.update
|
155
|
+
|
156
|
+
expect( webhook.id ).to eq active_webhook_id
|
157
|
+
expect( webhook.email ).to be_nil
|
158
|
+
expect( webhook.url ).to eq 'https://qaiware.com'
|
159
|
+
expect( webhook.livemode ).to be false
|
160
|
+
expect( webhook.event_types ).to eq ['transaction.succeeded', 'transaction.failed']
|
161
|
+
expect( webhook.created_at ).to be_a Time
|
162
|
+
expect( webhook.updated_at ).to be_a Time
|
163
|
+
expect( webhook.active ).to be false
|
164
|
+
expect( webhook.app_id ).to be nil
|
165
|
+
expect( webhook.created_at ).to be < webhook.updated_at
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should activate the webhook', :vcr do
|
169
|
+
webhook = Webhook.find( inactive_webhook_id )
|
170
|
+
webhook.active = true
|
171
|
+
|
172
|
+
webhook.update()
|
173
|
+
|
174
|
+
expect( webhook.id ).to eq inactive_webhook_id
|
175
|
+
expect( webhook.email ).to eq 'rambo@qaiware.com'
|
176
|
+
expect( webhook.url ).to be_nil
|
177
|
+
expect( webhook.livemode ).to be false
|
178
|
+
expect( webhook.event_types ).to eq ['refund.failed']
|
179
|
+
expect( webhook.created_at ).to be_a Time
|
180
|
+
expect( webhook.updated_at ).to be_a Time
|
181
|
+
expect( webhook.active ).to be true
|
182
|
+
expect( webhook.app_id ).to be nil
|
183
|
+
expect( webhook.created_at ).to be < webhook.updated_at
|
184
|
+
end
|
185
|
+
|
186
|
+
context '::deltele' do
|
187
|
+
it 'showd delete existing webhook', :vcr do
|
188
|
+
expect( Webhook.find( active_webhook_id ).delete ).to be_nil
|
189
|
+
expect( Webhook.find( inactive_webhook_id ).delete ).to be_nil
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'paymill'
|
2
|
+
require 'vcr'
|
3
|
+
require 'pry'
|
4
|
+
require 'active_support/all'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
# initialize the library by getting paymill's api key from the envirounent variables
|
8
|
+
Paymill.api_key = ENV['PAYMILL_API_TEST_KEY']
|
9
|
+
|
10
|
+
# VCR basic configuration
|
11
|
+
VCR.configure do |config|
|
12
|
+
config.allow_http_connections_when_no_cassette = true
|
13
|
+
config.cassette_library_dir = 'spec/cassettes'
|
14
|
+
config.hook_into :webmock
|
15
|
+
config.default_cassette_options = { record: :new_episodes, re_record_interval: 1.week.to_i }
|
16
|
+
config.configure_rspec_metadata!
|
17
|
+
config.filter_sensitive_data( '<PAYMILL_API_TEST_KEY>' ) { ENV['PAYMILL_API_TEST_KEY'] }
|
18
|
+
end
|
19
|
+
|
20
|
+
# RSpec configuration
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# configure rspec to create VCR cassette names, based on rspec examples
|
23
|
+
config.around( :each, :vcr ) do |example|
|
24
|
+
name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
|
25
|
+
options = example.metadata.slice( :record, :match_requests_on ).except( :example_group )
|
26
|
+
VCR.use_cassette( name, options ) { example.call }
|
27
|
+
end
|
28
|
+
end
|