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.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +3 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +223 -0
  7. data/Rakefile +6 -0
  8. data/lib/paymill.rb +54 -0
  9. data/lib/paymill/errors.rb +10 -0
  10. data/lib/paymill/models/address.rb +13 -0
  11. data/lib/paymill/models/base.rb +50 -0
  12. data/lib/paymill/models/checksum.rb +40 -0
  13. data/lib/paymill/models/client.rb +24 -0
  14. data/lib/paymill/models/fee.rb +14 -0
  15. data/lib/paymill/models/invoice.rb +18 -0
  16. data/lib/paymill/models/merchant.rb +21 -0
  17. data/lib/paymill/models/offer.rb +27 -0
  18. data/lib/paymill/models/payment.rb +20 -0
  19. data/lib/paymill/models/payment_method.rb +18 -0
  20. data/lib/paymill/models/preauthorization.rb +25 -0
  21. data/lib/paymill/models/refund.rb +22 -0
  22. data/lib/paymill/models/shopping_cart_item.rb +13 -0
  23. data/lib/paymill/models/subscription.rb +143 -0
  24. data/lib/paymill/models/subscription_count.rb +18 -0
  25. data/lib/paymill/models/transaction.rb +27 -0
  26. data/lib/paymill/models/webhook.rb +37 -0
  27. data/lib/paymill/restful/methods.rb +134 -0
  28. data/lib/paymill/version.rb +3 -0
  29. data/paymill.gemspec +28 -0
  30. data/samples/authentication/authentication.rb +1 -0
  31. data/samples/clients/create_new_client.rb +4 -0
  32. data/samples/clients/export_clients_list.rb +1 -0
  33. data/samples/clients/get_client_details.rb +1 -0
  34. data/samples/clients/list_clients.rb +1 -0
  35. data/samples/clients/remove_client.rb +2 -0
  36. data/samples/clients/update_client.rb +4 -0
  37. data/samples/offers/create_new_offer.rb +7 -0
  38. data/samples/offers/export_offers_list.rb +1 -0
  39. data/samples/offers/get_offer_details.rb +1 -0
  40. data/samples/offers/list_offers.rb +1 -0
  41. data/samples/offers/remove_offer.rb +7 -0
  42. data/samples/offers/update_offer.rb +8 -0
  43. data/samples/payments/create_new_credit_card_payment_with_token.rb +1 -0
  44. data/samples/payments/create_new_credit_card_payment_with_token_and_client.rb +4 -0
  45. data/samples/payments/create_new_debit_payment_with_token.rb +1 -0
  46. data/samples/payments/create_new_debit_payment_with_token_and_client.rb +4 -0
  47. data/samples/payments/export_payments_list.rb +1 -0
  48. data/samples/payments/get_payment_details.rb +1 -0
  49. data/samples/payments/list_payments.rb +1 -0
  50. data/samples/payments/remove_payment.rb +2 -0
  51. data/samples/preauthorizations/create_new_preauthorization_with_payment.rb +8 -0
  52. data/samples/preauthorizations/create_new_preauthorization_with_token.rb +6 -0
  53. data/samples/preauthorizations/export_preauthorizations_list.rb +1 -0
  54. data/samples/preauthorizations/get_preauthorization_details.rb +1 -0
  55. data/samples/preauthorizations/list_preauthozizations.rb +1 -0
  56. data/samples/preauthorizations/remove_preauthorization.rb +2 -0
  57. data/samples/refunds/create_new_refund.rb +11 -0
  58. data/samples/refunds/export_refunds_list.rb +1 -0
  59. data/samples/refunds/get_refund_details.rb +1 -0
  60. data/samples/refunds/list_refunds.rb +1 -0
  61. data/samples/subscriptions/cancel_subscription.rb +2 -0
  62. data/samples/subscriptions/create_new_subscription_with_an_offer.rb +15 -0
  63. data/samples/subscriptions/create_new_subscription_with_an_offer_and_different_values.rb +19 -0
  64. data/samples/subscriptions/create_new_subscription_without_an_offer.rb +13 -0
  65. data/samples/subscriptions/delete_subscription.rb +2 -0
  66. data/samples/subscriptions/export_subscriptions_list.rb +1 -0
  67. data/samples/subscriptions/get_subscription_details.rb +1 -0
  68. data/samples/subscriptions/list_subscriptions.rb +1 -0
  69. data/samples/subscriptions/pause_subscription.rb +7 -0
  70. data/samples/subscriptions/update_subscription.rb +12 -0
  71. data/samples/subscriptions/update_subscription_amount.rb +7 -0
  72. data/samples/subscriptions/update_subscription_offer.rb +14 -0
  73. data/samples/transactions/create_new_transaction_with_app_fee.rb +8 -0
  74. data/samples/transactions/create_new_transaction_with_client_and_payment.rb +12 -0
  75. data/samples/transactions/create_new_transaction_with_payment.rb +7 -0
  76. data/samples/transactions/create_new_transaction_with_preauthorization.rb +10 -0
  77. data/samples/transactions/create_new_transaction_with_token.rb +6 -0
  78. data/samples/transactions/export_transactions_list.rb +1 -0
  79. data/samples/transactions/get_transaction_details_by_id.rb +1 -0
  80. data/samples/transactions/get_transaction_details_by_slv.rb +1 -0
  81. data/samples/transactions/list_transactions.rb +1 -0
  82. data/samples/transactions/upate_transaction.rb +3 -0
  83. data/samples/webhooks/create_new_email_webhook.rb +5 -0
  84. data/samples/webhooks/create_new_url_webhook.rb +4 -0
  85. data/samples/webhooks/export_webhooks_list.rb +1 -0
  86. data/samples/webhooks/get_webhook_details.rb +1 -0
  87. data/samples/webhooks/remove_webhook.rb +2 -0
  88. data/samples/webhooks/update_webhook.rb +3 -0
  89. data/spec/paymill/models/address_spec.rb +42 -0
  90. data/spec/paymill/models/checksum_spec.rb +77 -0
  91. data/spec/paymill/models/client_spec.rb +311 -0
  92. data/spec/paymill/models/offer_spec.rb +151 -0
  93. data/spec/paymill/models/payment_spec.rb +188 -0
  94. data/spec/paymill/models/preauthorization_spec.rb +180 -0
  95. data/spec/paymill/models/refund_spec.rb +90 -0
  96. data/spec/paymill/models/subscription_spec.rb +607 -0
  97. data/spec/paymill/models/transaction_spec.rb +226 -0
  98. data/spec/paymill/models/webhook_spec.rb +195 -0
  99. data/spec/spec_helper.rb +28 -0
  100. metadata +265 -0
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ module Paymill
4
+ describe Offer do
5
+
6
+ offer_id = nil
7
+
8
+ context '::find' do
9
+ it 'should find a Offer object when valid offer id is given', :vcr do
10
+ offer = Offer.find( 'offer_9bba76a5e8bca1407230' )
11
+
12
+ expect( offer.id ).to eq 'offer_9bba76a5e8bca1407230'
13
+ expect( offer.name ).to eq 'Chuck Testa'
14
+ expect( offer.amount ).to be 10000
15
+ expect( offer.currency ).to eq 'EUR'
16
+ expect( offer.interval ).to eq '1 MONTH'
17
+ expect( offer.trial_period_days ).to be 0
18
+ expect( offer.created_at ).to be_a Time
19
+ expect( offer.updated_at ).to be_a Time
20
+ expect( offer.subscription_count.active ).to be 0
21
+ expect( offer.subscription_count.inactive ).to be 0
22
+ expect( offer.app_id ).to be_nil
23
+ end
24
+
25
+ it 'should throw NotFoundError when unexisting offer id given', :vcr do
26
+ expect{ Offer.find( 'fake_id' ) }.to raise_error PaymillError
27
+ end
28
+ end
29
+
30
+ context '::create' do
31
+ it 'should create new offer without trial period in days', :vcr do
32
+ offer = Offer.create( amount: 4200, currency: 'EUR', interval: '1 MONTH', name: 'Superabo' )
33
+
34
+ expect( offer.id ).to be_a String
35
+ expect( offer.name ).to eq 'Superabo'
36
+ expect( offer.amount ).to be 4200
37
+ expect( offer.currency ).to eq 'EUR'
38
+ expect( offer.interval ).to eq '1 MONTH'
39
+ expect( offer.trial_period_days ).to be 0
40
+ expect( offer.created_at ).to be_a Time
41
+ expect( offer.updated_at ).to be_a Time
42
+ expect( offer.subscription_count.active ).to be 0
43
+ expect( offer.subscription_count.inactive ).to eq 0
44
+ expect( offer.app_id ).to be_nil
45
+ end
46
+
47
+ it 'should create new offer with trial period in days', :vcr do
48
+ offer = Offer.create( amount: 4200, currency: 'EUR', interval: '1 MONTH', name: 'sabo', trial_period_days: 30 )
49
+ offer_id = offer.id
50
+
51
+ expect( offer.id ).to be_a String
52
+ expect( offer.name ).to eq 'sabo'
53
+ expect( offer.amount ).to eq 4200
54
+ expect( offer.currency ).to eq 'EUR'
55
+ expect( offer.interval ).to eq '1 MONTH'
56
+ expect( offer.trial_period_days ).to be 30
57
+ expect( offer.created_at ).to be_a Time
58
+ expect( offer.updated_at ).to be_a Time
59
+ expect( offer.subscription_count.active ).to be 0
60
+ expect( offer.subscription_count.inactive ).to eq 0
61
+ expect( offer.app_id ).to be_nil
62
+ end
63
+
64
+ it 'should throw ArgumentError when creating with invalid argument name', :vcr do
65
+ expect{ Offer.create( foo: '4200', amount: 333, currency: 'EUR', interval: '1 MONTH', name: 'Superabo' ) }.to raise_error ArgumentError
66
+ end
67
+
68
+ it 'should throw ArgumentError when creating without amount argument', :vcr do
69
+ expect{ Offer.create( currency: 'EUR', interval: '1 MONTH', name: 'Superabo' ) }.to raise_error ArgumentError
70
+ end
71
+
72
+ it 'should throw PaymillError when creating with wrong currency argument value', :vcr do
73
+ expect{ Offer.create( amount: 333, currency: 'ER', interval: '1 MONTH', name: 'Superabo' ) }.to raise_error PaymillError
74
+ end
75
+ end
76
+
77
+ context '::update' do
78
+ it "should update offer's name", :vcr do
79
+ offer = Offer.find( offer_id )
80
+ created_at = offer.created_at
81
+ updated_at = offer.updated_at
82
+
83
+ offer.name = 'Superabo'
84
+ offer.update
85
+
86
+ expect( offer.id ).to eq offer_id
87
+ expect( offer.name ).to eq 'Superabo'
88
+ expect( offer.amount ).to eq 4200
89
+ expect( offer.currency ).to eq 'EUR'
90
+ expect( offer.interval ).to eq '1 MONTH'
91
+ expect( offer.trial_period_days ).to be 30
92
+ expect( offer.created_at ).to eq created_at
93
+ expect( offer.created_at ).to be < offer.updated_at
94
+ end
95
+
96
+ it "should update offer's amount and currency", :vcr do
97
+ offer = Offer.find( offer_id )
98
+ created_at = offer.created_at
99
+ updated_at = offer.updated_at
100
+
101
+ offer.currency = 'USD'
102
+ offer.amount = '900'
103
+ offer.update
104
+
105
+ expect( offer.id ).to eq offer_id
106
+ expect( offer.name ).to eq 'Superabo'
107
+ expect( offer.amount ).to eq 900
108
+ expect( offer.currency ).to eq 'USD'
109
+ expect( offer.interval ).to eq '1 MONTH'
110
+ expect( offer.trial_period_days ).to be 30
111
+ expect( offer.created_at ).to eq created_at
112
+ expect( offer.created_at ).to be < offer.updated_at
113
+ end
114
+
115
+ it 'should update offer and its subscriptions', :vcr do
116
+ offer = Offer.find( offer_id )
117
+ created_at = offer.created_at
118
+ updated_at = offer.updated_at
119
+
120
+ offer.amount = '1000'
121
+ offer.update( update_subscriptions: true )
122
+
123
+ expect( offer.id ).to eq offer_id
124
+ expect( offer.name ).to eq 'Superabo'
125
+ expect( offer.amount ).to eq 1000
126
+ expect( offer.currency ).to eq 'USD'
127
+ expect( offer.interval ).to eq '1 MONTH'
128
+ expect( offer.trial_period_days ).to be 30
129
+ expect( offer.created_at ).to eq created_at
130
+ expect( offer.created_at ).to be < offer.updated_at
131
+ end
132
+
133
+ it "should throw NoMethodError when updating unupdateable field", :vcr do
134
+ offer = Offer.find( offer_id )
135
+ expect{ offer.app_id = 'fake_app_id' }.to raise_error NoMethodError
136
+ end
137
+ end
138
+
139
+ context '::delete' do
140
+ it 'should delete existing offer', :vcr do
141
+ offer = Offer.find( offer_id )
142
+ expect( offer.delete_without_subscriptions() ).to be_nil
143
+ end
144
+
145
+ it 'should delete existing offer with its correlated subscriptions', :vcr do
146
+ offer = Offer.create( amount: 4200, currency: 'EUR', interval: '1 MONTH', name: 'Superabo' )
147
+ expect( offer.delete_with_subscriptions ).to be_nil
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ module Paymill
4
+ describe Payment do
5
+
6
+ payment_id = nil
7
+
8
+ let( :client ) { Client.create( email: 'john.rambo@qaiware.com') }
9
+
10
+ context '::find' do
11
+ it 'should find a payment by given valid id', :vcr do
12
+ payment = Payment.find( 'pay_cc87bc3445daf8da2329b108' )
13
+
14
+ expect( payment ).to be_a Payment
15
+
16
+ expect( payment.type ).to eq 'creditcard'
17
+ expect( payment.client ).to be_nil
18
+ expect( payment.card_type ). to eq 'visa'
19
+
20
+ expect( payment.country ).to eq 'DE'
21
+ expect( payment.expire_month ).to eq 12
22
+ expect( payment.expire_year ).to eq 2020
23
+ expect( payment.card_holder ).to eq 'joe johnson'
24
+ expect( payment.last4 ).to eq 1111
25
+ expect( payment.is_recurring ).to be true
26
+ expect( payment.is_usable_for_preauthorization ).to be true
27
+
28
+ expect( payment.id ).to eq 'pay_cc87bc3445daf8da2329b108'
29
+ expect( payment.created_at ).to be_a Time
30
+ expect( payment.updated_at ).to be_a Time
31
+ expect( payment.app_id ).to be_nil
32
+ end
33
+
34
+ it 'should throw NotFoundError when unexisting payment id given', :vcr do
35
+ expect{ Payment.find( 'fake_id' ) }.to raise_error PaymillError
36
+ end
37
+ end
38
+
39
+ context '::create' do
40
+ context 'creditcard' do
41
+ before( :each ) do
42
+ 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=Max%20Mustermann&presentation.amount3D=3201&presentation.currency3D=EUR")
43
+ https = Net::HTTP.new(uri.host, uri.port)
44
+ https.use_ssl = true
45
+ request = Net::HTTP::Get.new(uri.request_uri)
46
+ request.basic_auth( ENV['PAYMILL_API_TEST_KEY'], "" )
47
+ response = https.request(request)
48
+ @token = response.body.match('tok_[a-z|0-9]+')[0]
49
+ end
50
+
51
+ it 'should create client with token', :vcr do
52
+ payment = Payment.create( token: @token )
53
+ payment_id = payment.id
54
+
55
+ expect( payment ).to be_a Payment
56
+
57
+ expect( payment.type ).to eq 'creditcard'
58
+ expect( payment.client ).to be_nil
59
+ expect( payment.card_type ). to eq 'visa'
60
+
61
+ expect( payment.country ).to be_nil
62
+ expect( payment.expire_month ).to be 12
63
+ expect( payment.expire_year ).to be 2015
64
+ expect( payment.card_holder ).to eq 'Max Mustermann'
65
+ expect( payment.last4 ).to eq 1111
66
+ expect( payment.is_recurring ).to be true
67
+ expect( payment.is_usable_for_preauthorization ).to be true
68
+
69
+ expect( payment.id ).to be_a String
70
+ expect( payment.created_at ).to be_a Time
71
+ expect( payment.updated_at ).to be_a Time
72
+ expect( payment.app_id ).to be_nil
73
+ end
74
+
75
+ it 'should create client with token and client', :vcr do
76
+ payment = Payment.create( token: @token, client: client.id )
77
+
78
+ expect( payment ).to be_a Payment
79
+
80
+ expect( payment.type ).to eq 'creditcard'
81
+ expect( payment.client ).to be_a Client
82
+ expect( payment.client.id ).to eq client.id
83
+ expect( payment.card_type ).to eq 'visa'
84
+
85
+ expect( payment.country ).to be_nil
86
+ expect( payment.expire_month ).to eq 12
87
+ expect( payment.expire_year ).to eq 2015
88
+ expect( payment.card_holder ).to eq 'Max Mustermann'
89
+ expect( payment.last4 ).to eq 1111
90
+ expect( payment.is_recurring ).to be true
91
+ expect( payment.is_usable_for_preauthorization ).to be true
92
+
93
+ expect( payment.id ).to be_a String
94
+ expect( payment.created_at ).to be_a Time
95
+ expect( payment.updated_at ).to be_a Time
96
+ expect( payment.app_id ).to be_nil
97
+ end
98
+
99
+ xit 'should throw exception when creating a clinent with invalid token', :vcr do
100
+ #TODO[VNi]: We can create payment with custom string
101
+ expect{ Payment.create( token: 'fake' ) }.to raise_error PaymillError
102
+ end
103
+
104
+ xit 'should throw exception when creating a clinent with invalid client id', :vcr do
105
+ #TODO[VNi]: We can create payment with custom string
106
+ expect{ Payment.create( token: @token, client: 'fake' ) }.to raise_error PaymillError
107
+ end
108
+
109
+ it 'should throw exception when creating with wrong argument name', :vcr do
110
+ expect{ Payment.create( foo: 'fake' ) }.to raise_error ArgumentError
111
+ end
112
+
113
+ it 'should throw exception when creating with more arguments', :vcr do
114
+ expect{ Payment.create( token: @token, client: client.id, foo: 'fake' ) }.to raise_error ArgumentError
115
+ end
116
+
117
+ it 'should throw exception when creating without arguments', :vcr do
118
+ expect{ Payment.create() }.to raise_error ArgumentError
119
+ end
120
+ end
121
+
122
+ context 'debit' do
123
+ before( :each ) do
124
+ uri = URI.parse("https://test-token.paymill.de/?transaction.mode=CONNECTOR_TEST&channel.id=14704210606b41cbb45f66819085cb8d&response.url=https://test-tds.paymill.de/end.php?parentUrl=http%253A%252F%252Fhtmlpreview.github.io%252F%253Fhttps%253A%252F%252Fgithub.com%252Fpaymill%252Fpaymill-payment-form%252Fblob%252Fmaster%252Fpaymill_payment_sepa.html&&jsonPFunction=window.paymill.transport.paymillCallback298646523&account.iban=DE12500105170648489890&account.bic=BENEDEPPYYY&account.country=DE&account.holder=John+Rambo")
125
+ https = Net::HTTP.new(uri.host, uri.port)
126
+ https.use_ssl = true
127
+ request = Net::HTTP::Get.new(uri.request_uri)
128
+ request.basic_auth( ENV['PAYMILL_API_TEST_KEY'], "" )
129
+ response = https.request(request)
130
+ @token = response.body.match('uniqueId":"\w*')[0].split('":"').last
131
+ end
132
+
133
+ it 'should create client with token', :vcr do
134
+ payment = Payment.create( token: @token )
135
+
136
+ expect( payment ).to be_a Payment
137
+
138
+ expect( payment.type ).to eq 'debit'
139
+ expect( payment.client ).to be_nil
140
+
141
+ expect( payment.code ).to be_empty
142
+ expect( payment.holder ).to eq 'John Rambo'
143
+ expect( payment.account ).to be_empty
144
+ expect( payment.is_recurring ).to be true
145
+ expect( payment.is_usable_for_preauthorization ).to be true
146
+
147
+ expect( payment.iban ).to eq 'DE1250010517******9890'
148
+ expect( payment.bic ).to eq 'BENEDEPPYYY'
149
+
150
+ expect( payment.id ).to be_a String
151
+ expect( payment.created_at ).to be_a Time
152
+ expect( payment.updated_at ).to be_a Time
153
+ expect( payment.app_id ).to be_nil
154
+ end
155
+
156
+ it 'should create client with token and client', :vcr do
157
+ payment = Payment.create( token: @token, client: client.id )
158
+
159
+ expect( payment ).to be_a Payment
160
+
161
+ expect( payment.type ).to eq 'debit'
162
+ expect( payment.client ).to be_a Client
163
+ expect( payment.client.id ).to eq client.id
164
+
165
+ expect( payment.code ).to be_empty
166
+ expect( payment.holder ).to eq 'John Rambo'
167
+ expect( payment.account ).to be_empty
168
+ expect( payment.is_recurring ).to be true
169
+ expect( payment.is_usable_for_preauthorization ).to be true
170
+
171
+ expect( payment.iban ).to eq 'DE1250010517******9890'
172
+ expect( payment.bic ).to eq 'BENEDEPPYYY'
173
+
174
+ expect( payment.id ).to be_a String
175
+ expect( payment.created_at ).to be_a Time
176
+ expect( payment.updated_at ).to be_a Time
177
+ expect( payment.app_id ).to be_nil
178
+ end
179
+ end
180
+ end
181
+
182
+ context '::delete' do
183
+ it 'showd delete existing payment', :vcr do
184
+ expect( Payment.find( payment_id ).delete ).to be_nil
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+
3
+ module Paymill
4
+ describe Preauthorization do
5
+
6
+ let( :amount ) { 1990 }
7
+ let( :client ) { Client.create( email: 'rocky.balboa@qaiware.com' ) }
8
+ let( :currency ) { 'USD' }
9
+
10
+ preauthorization_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
+ end
23
+
24
+ it 'should create preauthorization with token', :vcr do
25
+ preauthorization = Preauthorization.create( token: @token, amount: amount, currency: currency )
26
+ preauthorization_id = preauthorization.id
27
+
28
+ expect( preauthorization ).to be_a Preauthorization
29
+
30
+ expect( preauthorization.id ).to be_a String
31
+ expect( preauthorization.amount ).to be amount
32
+ expect( preauthorization.currency ).to eq currency
33
+ expect( preauthorization.description ).to be_nil
34
+ expect( preauthorization.status ).to eq 'closed'
35
+ expect( preauthorization.livemode ).to be false
36
+ expect( preauthorization.created_at ).to be_a Time
37
+ expect( preauthorization.updated_at ).to be_a Time
38
+ expect( preauthorization.app_id ).to be_nil
39
+
40
+ expect( preauthorization.payment ).to be_a Payment
41
+ expect( preauthorization.payment.type ).to eq 'creditcard'
42
+ expect( preauthorization.payment.client ).to be_a String
43
+ expect( preauthorization.payment.card_type ). to eq 'visa'
44
+
45
+ expect( preauthorization.payment.country ).to be_nil
46
+ expect( preauthorization.payment.expire_month ).to eq 12
47
+ expect( preauthorization.payment.expire_year ).to eq 2015
48
+ expect( preauthorization.payment.card_holder ).to eq 'John Rambo'
49
+ expect( preauthorization.payment.last4 ).to eq 1111
50
+ expect( preauthorization.payment.is_recurring ).to be true
51
+ expect( preauthorization.payment.is_usable_for_preauthorization ).to be true
52
+
53
+ expect( preauthorization.payment.id ).to be_a String
54
+ expect( preauthorization.payment.created_at ).to be_a Time
55
+ expect( preauthorization.payment.updated_at ).to be_a Time
56
+ expect( preauthorization.payment.app_id ).to be_nil
57
+
58
+ expect( preauthorization.client ).to be_a Client
59
+
60
+ # expect( preauthorization.transaction ).to <Obejct>"
61
+ end
62
+
63
+ it 'should create preauthorization with payment', :vcr do
64
+ preauthorization = Preauthorization.create( payment: @payment.id, amount: amount, currency: currency )
65
+ preauthorization_id = preauthorization.id
66
+
67
+ expect( preauthorization ).to be_a Preauthorization
68
+
69
+ expect( preauthorization.id ).to be_a String
70
+ expect( preauthorization.amount ).to be amount
71
+ expect( preauthorization.currency ).to eq currency
72
+ expect( preauthorization.description ).to be_nil
73
+ expect( preauthorization.status ).to eq 'closed'
74
+ expect( preauthorization.livemode ).to be false
75
+ expect( preauthorization.created_at ).to be_a Time
76
+ expect( preauthorization.updated_at ).to be_a Time
77
+ expect( preauthorization.app_id ).to be_nil
78
+
79
+ expect( preauthorization.payment ).to be_a Payment
80
+ expect( preauthorization.payment.id ).to eq @payment.id
81
+ expect( preauthorization.payment.type ).to eq 'creditcard'
82
+ expect( preauthorization.payment.client ).to eq client.id
83
+ expect( preauthorization.payment.card_type ). to eq 'visa'
84
+
85
+ expect( preauthorization.payment.country ).to be_nil
86
+ expect( preauthorization.payment.expire_month ).to eq 12
87
+ expect( preauthorization.payment.expire_year ).to eq 2015
88
+ expect( preauthorization.payment.card_holder ).to eq 'John Rambo'
89
+ expect( preauthorization.payment.last4 ).to eq 1111
90
+ expect( preauthorization.payment.is_recurring ).to be true
91
+ expect( preauthorization.payment.is_usable_for_preauthorization ).to be true
92
+
93
+ expect( preauthorization.payment.id ).to be_a String
94
+ expect( preauthorization.payment.created_at ).to be_a Time
95
+ expect( preauthorization.payment.updated_at ).to be_a Time
96
+ expect( preauthorization.payment.app_id ).to be_nil
97
+
98
+ expect( preauthorization.client ).to be_a Client
99
+ expect( preauthorization.client.id ).to eq client.id
100
+ expect( preauthorization.client.email ).to eq 'rocky.balboa@qaiware.com'
101
+
102
+ # expect( preauthorization.transaction ).to <Obejct>"
103
+ end
104
+
105
+ it 'should create preauthorization with payment and description', :vcr do
106
+ preauthorization = Preauthorization.create( payment: @payment, amount: amount, currency: currency, description: 'The Italian Stallion' )
107
+ preauthorization_id = preauthorization.id
108
+
109
+ expect( preauthorization ).to be_a Preauthorization
110
+
111
+ expect( preauthorization.id ).to be_a String
112
+ expect( preauthorization.amount ).to be amount
113
+ expect( preauthorization.currency ).to eq currency
114
+ expect( preauthorization.description ).to eq 'The Italian Stallion'
115
+ expect( preauthorization.status ).to eq 'closed'
116
+ expect( preauthorization.livemode ).to be false
117
+ expect( preauthorization.created_at ).to be_a Time
118
+ expect( preauthorization.updated_at ).to be_a Time
119
+ expect( preauthorization.app_id ).to be_nil
120
+
121
+ expect( preauthorization.payment ).to be_a Payment
122
+ expect( preauthorization.payment.id ).to eq @payment.id
123
+ expect( preauthorization.payment.type ).to eq 'creditcard'
124
+ expect( preauthorization.payment.client ).to eq client.id
125
+ expect( preauthorization.payment.card_type ). to eq 'visa'
126
+
127
+ expect( preauthorization.payment.country ).to be_nil
128
+ expect( preauthorization.payment.expire_month ).to eq 12
129
+ expect( preauthorization.payment.expire_year ).to eq 2015
130
+ expect( preauthorization.payment.card_holder ).to eq 'John Rambo'
131
+ expect( preauthorization.payment.last4 ).to eq 1111
132
+ expect( preauthorization.payment.is_recurring ).to be true
133
+ expect( preauthorization.payment.is_usable_for_preauthorization ).to be true
134
+
135
+ expect( preauthorization.payment.id ).to be_a String
136
+ expect( preauthorization.payment.created_at ).to be_a Time
137
+ expect( preauthorization.payment.updated_at ).to be_a Time
138
+ expect( preauthorization.payment.app_id ).to be_nil
139
+
140
+ expect( preauthorization.client ).to be_a Client
141
+ expect( preauthorization.client.id ).to eq client.id
142
+ expect( preauthorization.client.email ).to eq 'rocky.balboa@qaiware.com'
143
+
144
+ # expect( preauthorization.transaction ).to <Obejct>"
145
+ end
146
+
147
+ it 'should throw ArgumentError when creating without amount', :vcr do
148
+ expect{ Preauthorization.create( payment: @payment, currency: currency ) }.to raise_error ArgumentError
149
+ end
150
+
151
+ it 'should throw ArgumentError when creating wit invalid argument', :vcr do
152
+ expect{ Preauthorization.create( payment: @payment, currency: currency, amount: amount, fake: true ) }.to raise_error ArgumentError
153
+ end
154
+
155
+ it 'should throw ArgumentError when creating without token or payment', :vcr do
156
+ expect{ Preauthorization.create( currency: currency, amount: amount ) }.to raise_error ArgumentError
157
+ end
158
+
159
+ it 'should throw ArgumentError when creating with token and payment', :vcr do
160
+ expect{ Preauthorization.create( token: @token, payment: @payment, currency: currency, amount: amount ) }.to raise_error ArgumentError
161
+ end
162
+ end
163
+
164
+ context '::find' do
165
+ it 'should find preauthorization by valid id', :vcr do
166
+ expect( Preauthorization.find( preauthorization_id ).id ).to eq preauthorization_id
167
+ end
168
+
169
+ it 'should throw PaymillError when unvalid id given', :vcr do
170
+ expect{ Preauthorization.find( 'fake_id' ) }.to raise_error PaymillError
171
+ end
172
+ end
173
+
174
+ context '::deltele' do
175
+ it 'should delete existing preauthorization', :vcr do
176
+ expect( Preauthorization.find( preauthorization_id ).delete ).to be_nil
177
+ end
178
+ end
179
+ end
180
+ end