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,8 @@
1
+ Paymill::Transaction.create(
2
+ token: '098f6bcd4621d373cade4e832627b4f6',
3
+ amount: 4200, currency: 'EUR',
4
+ description: 'Test Transaction',
5
+ fee_amount: 4200,
6
+ fee_payment: 'pay_a818b847db6ce5ff636f',
7
+ fee_currency: 'EUR'
8
+ )
@@ -0,0 +1,12 @@
1
+ client = Paymill::Client.create(email: 'mail@example.com')
2
+ payment = Paymill::Payment.create(
3
+ token: '098f6bcd4621d373cade4e832627b4f6',
4
+ client: client
5
+ )
6
+
7
+ Paymill::Transaction.create(
8
+ payment: payment,
9
+ client: client,
10
+ amount: 4200,
11
+ currency: 'EUR'
12
+ )
@@ -0,0 +1,7 @@
1
+ payment = Paymill::Payment.create(token: '098f6bcd4621d373cade4e832627b4f6')
2
+ transaction = Paymill::Transaction.create(
3
+ payment: payment,
4
+ amount: 4200,
5
+ currency: 'EUR',
6
+ description: 'Test Transaction'
7
+ )
@@ -0,0 +1,10 @@
1
+ preauthorization = Paymill::Preauthorization.create(
2
+ token: '098f6bcd4621d373cade4e832627b4f6',
3
+ amount: 4200,
4
+ currency: 'EUR'
5
+ )
6
+ transaction = Transaction.create(
7
+ preauthorization: preauthorization,
8
+ amount: 4200,
9
+ currency: 'EUR'
10
+ )
@@ -0,0 +1,6 @@
1
+ Paymill::Transaction.create(
2
+ token: '098f6bcd4621d373cade4e832627b4f6',
3
+ amount: 4200,
4
+ currency: 'EUR',
5
+ description: 'Test Transaction'
6
+ )
@@ -0,0 +1 @@
1
+ # Not implemented yet
@@ -0,0 +1 @@
1
+ Paymill::Transaction.find('tran_023d3b5769321c649435')
@@ -0,0 +1 @@
1
+ Paymill::Transaction.find('tran_023d3b5769321c649435')
@@ -0,0 +1 @@
1
+ Paymill::Transaction.all()
@@ -0,0 +1,3 @@
1
+ transaction = Paymill::Transaction.find('tran_023d3b5769321c649435')
2
+ transaction.description = 'My updated transaction description'
3
+ transaction.update
@@ -0,0 +1,5 @@
1
+ Paymill::Webhook.create(
2
+ email: 'webhook@example.com',
3
+ event_types: ['transaction.succeeded', 'transaction.failed'],
4
+ active: false
5
+ )
@@ -0,0 +1,4 @@
1
+ Paymill::Webhook.create(
2
+ url: 'http://example.com',
3
+ event_types: ['transaction.succeeded', 'transaction.failed']
4
+ )
@@ -0,0 +1 @@
1
+ # Not implemented yet
@@ -0,0 +1 @@
1
+ Paymill::Webhook.find('hook_40237e20a7d5a231d99b')
@@ -0,0 +1,2 @@
1
+ webhook = Paymill::Webhook.find(active_webhook_id)
2
+ webhook.delete()
@@ -0,0 +1,3 @@
1
+ webhook = Paymill::Webhook.find(active_webhook_id)
2
+ webhook.email = 'mail@example.com'
3
+ webhook.update()
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Paymill
4
+ describe Address do
5
+
6
+ context '::create' do
7
+
8
+ it 'should raise ArgumentError when invalid parameter is given' do
9
+ expect{
10
+ Address.new(
11
+ name: 'Primary',
12
+ street_address: 'Rambo Str.',
13
+ street_address_addition: '',
14
+ city: 'Sofia',
15
+ state: 'Sofia',
16
+ postal_code: 1234,
17
+ country: 'Bulgaria',
18
+ phone: '088 41 555 27',
19
+ invalid: 'this is invalid parameter'
20
+ )
21
+ }.to raise_error ArgumentError
22
+ end
23
+
24
+ it 'should with minimal parameters' do
25
+ address = Address.new(
26
+ name: 'Primary', street_address: 'Rambo Str.', street_address_addition: '', city: 'Sofia',
27
+ state: 'Sofia', postal_code: 1234, country: 'Bulgaria', phone: '088 41 555 27'
28
+ )
29
+
30
+ expect( address.name ).to eq 'Primary'
31
+ expect( address.street_address ).to eq 'Rambo Str.'
32
+ expect( address.street_address_addition ).to be_empty
33
+ expect( address.city ).to eq 'Sofia'
34
+ expect( address.state ).to eq 'Sofia'
35
+ expect( address.postal_code ).to be 1234
36
+ expect( address.country ).to eq 'Bulgaria'
37
+ expect( address.phone ).to eq '088 41 555 27'
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ module Paymill
4
+ describe Checksum do
5
+ let( :billing_address ) {
6
+ Address.new(
7
+ name: 'Primary', street_address: 'Rambo Str.', street_address_addition: '', city: 'Sofia',
8
+ state: 'Sofia', postal_code: 1234, country: 'BG', phone: '088 41 555 27'
9
+ )
10
+ }
11
+ let( :rambo_poster ) {
12
+ ShoppingCartItem.new(
13
+ name: "Rambo Poster", description: "John J. Rambo", amount: 2200, quantity: 3, item_number: "898-24342-343", url: "http://www.store.com/items/posters/12121-rambo"
14
+ )
15
+ }
16
+ let( :comando_poster ) {
17
+ ShoppingCartItem.new(
18
+ name: "Comando Poster", description: "John Matrix", amount: 3100, quantity: 1, item_number: "898-24342-341", url: "http://www.store.com/items/posters/12121-comando"
19
+ )
20
+ }
21
+
22
+ context '::create' do
23
+ it 'should create new checksum with minimum parameters', :vcr do
24
+ checksum = Checksum.create( checksum_type: 'paypal', amount: 4200, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel' )
25
+
26
+ expect( checksum.action ).to eq 'transaction'
27
+ expect( checksum.checksum ).to be_a String
28
+ expect( checksum.data ).to eq 'amount=4200&currency=EUR&description=Chuck+Testa&return_url=https%3A%2F%2Ftesta.com&cancel_url=https%3A%2F%2Ftest.com%2Fcancel'
29
+ expect( checksum.id ).to be_a String
30
+ expect( checksum.type ).to eq 'paypal'
31
+ expect( checksum.app_id ).to be_nil
32
+ expect( checksum.created_at ).to be_a Time
33
+ expect( checksum.updated_at ).to be_a Time
34
+ end
35
+
36
+ it 'should create new checksum with minimum parameters and billing address', :vcr do
37
+ checksum = Checksum.create( checksum_type: 'paypal', amount: 4200, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel', billing_address: billing_address )
38
+
39
+ expect( checksum.action ).to eq 'transaction'
40
+ expect( checksum.checksum ).to be_a String
41
+ expect( checksum.data ).to eq 'amount=4200&currency=EUR&description=Chuck+Testa&return_url=https%3A%2F%2Ftesta.com&cancel_url=https%3A%2F%2Ftest.com%2Fcancel&billing_address%5Bname%5D=Primary&billing_address%5Bstreet_address%5D=Rambo+Str.&billing_address%5Bcity%5D=Sofia&billing_address%5Bstate%5D=Sofia&billing_address%5Bpostal_code%5D=1234&billing_address%5Bcountry%5D=BG&billing_address%5Bphone%5D=088+41+555+27'
42
+ expect( checksum.id ).to be_a String
43
+ expect( checksum.type ).to eq 'paypal'
44
+ expect( checksum.app_id ).to be_nil
45
+ expect( checksum.created_at ).to be_a Time
46
+ expect( checksum.updated_at ).to be_a Time
47
+ end
48
+
49
+ it 'should create new checksum with minimum parameters and items', :vcr do
50
+ checksum = Checksum.create( checksum_type: 'paypal', amount: 9700, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel', items: [rambo_poster, comando_poster] )
51
+
52
+ expect( checksum.action ).to eq 'transaction'
53
+ expect( checksum.checksum ).to be_a String
54
+ expect( checksum.data ).to eq 'amount=9700&currency=EUR&description=Chuck+Testa&return_url=https%3A%2F%2Ftesta.com&cancel_url=https%3A%2F%2Ftest.com%2Fcancel&items%5B0%5D%5Bname%5D=Rambo+Poster&items%5B0%5D%5Bdescription%5D=John+J.+Rambo&items%5B0%5D%5Bamount%5D=2200&items%5B0%5D%5Bquantity%5D=3&items%5B0%5D%5Bitem_number%5D=898-24342-343&items%5B0%5D%5Burl%5D=http%3A%2F%2Fwww.store.com%2Fitems%2Fposters%2F12121-rambo&items%5B1%5D%5Bname%5D=Comando+Poster&items%5B1%5D%5Bdescription%5D=John+Matrix&items%5B1%5D%5Bamount%5D=3100&items%5B1%5D%5Bquantity%5D=1&items%5B1%5D%5Bitem_number%5D=898-24342-341&items%5B1%5D%5Burl%5D=http%3A%2F%2Fwww.store.com%2Fitems%2Fposters%2F12121-comando'
55
+ expect( checksum.id ).to be_a String
56
+ expect( checksum.type ).to eq 'paypal'
57
+ expect( checksum.app_id ).to be_nil
58
+ expect( checksum.created_at ).to be_a Time
59
+ expect( checksum.updated_at ).to be_a Time
60
+ end
61
+
62
+ it 'should create new checksum with minimum parameters and fee', :vcr do
63
+ checksum = Checksum.create( checksum_type: 'paypal', amount: 9700, currency: 'EUR', description: 'Chuck Testa', return_url: 'https://testa.com', cancel_url: 'https://test.com/cancel', fee_amount: 100, fee_payment: 'pay_3af44644dd6d25c820a8', fee_currency: 'EUR', app_id: '8fh98hfd828ej2e09dk0hf9' )
64
+
65
+ expect( checksum.action ).to eq 'transaction'
66
+ expect( checksum.checksum ).to be_a String
67
+ expect( checksum.data ).to eq 'amount=9700&currency=EUR&description=Chuck+Testa&return_url=https%3A%2F%2Ftesta.com&cancel_url=https%3A%2F%2Ftest.com%2Fcancel&fee_amount=100&fee_payment=pay_3af44644dd6d25c820a8&fee_currency=EUR&app_id=8fh98hfd828ej2e09dk0hf9'
68
+ expect( checksum.id ).to be_a String
69
+ expect( checksum.type ).to eq 'paypal'
70
+ expect( checksum.app_id ).to be_nil
71
+ expect( checksum.created_at ).to be_a Time
72
+ expect( checksum.updated_at ).to be_a Time
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,311 @@
1
+ require 'spec_helper'
2
+
3
+ module Paymill
4
+ describe Client do
5
+
6
+ client_id = nil
7
+
8
+ context '::find' do
9
+ it 'should throw AuthenticationError when API_KEY is not set', :vcr do
10
+ Paymill.api_key = nil
11
+ expect{ Client.find( 'fake_id' ) }.to raise_error AuthenticationError
12
+ Paymill.api_key = ENV['PAYMILL_API_TEST_KEY']
13
+ end
14
+
15
+ it 'should throw NotFoundError when unexisting client id given', :vcr do
16
+ expect{ Client.find( 'fake_id' ) }.to raise_error PaymillError
17
+ end
18
+
19
+ it 'should find a Client object when valid client id is given', :vcr do
20
+ client = Client.find( 'client_a6dcf82f63c3a5627454' )
21
+
22
+ expect( client ).to be_a Client
23
+ expect( client.id ).to eq 'client_a6dcf82f63c3a5627454'
24
+ expect( client.email ).to eq 'john.rambo@qaiware.com'
25
+ expect( client.description ).to eq 'Boom, boom, shake the room'
26
+ expect( client.created_at ).to be_a Time
27
+ expect( client.updated_at ).to be_a Time
28
+ expect( client.app_id ).to be_nil
29
+
30
+ expect( client.payments ).not_to be_nil
31
+ expect( client.payments.first ).to be_a Payment
32
+
33
+ expect( client.payments.first.id ).to eq 'pay_e3d67dfaf30a237308d42bf2'
34
+ expect( client.payments.first.type ).to eq 'creditcard'
35
+ expect( client.payments.first.client ).to eq 'client_a6dcf82f63c3a5627454'
36
+ expect( client.payments.first.card_type ).to eq 'visa'
37
+ expect( client.payments.first.country ).to be_nil
38
+ expect( client.payments.first.expire_month ).to eq 12
39
+ expect( client.payments.first.expire_year ).to eq 2015
40
+ expect( client.payments.first.card_holder ).to be_empty
41
+ expect( client.payments.first.last4 ).to eq 1111
42
+ expect( client.payments.first.created_at ).to be_a Time
43
+ expect( client.payments.first.updated_at ).to be_a Time
44
+ expect( client.payments.first.app_id ).to be_nil
45
+ expect( client.payments.first.is_recurring ).to be true
46
+ expect( client.payments.first.is_usable_for_preauthorization ).to be true
47
+
48
+
49
+ expect( client.subscriptions ).not_to be_nil
50
+
51
+ expect( client.subscriptions.first ).to be_a Subscription
52
+ expect( client.subscriptions.first.id ).to eq 'sub_386b863839a6c9f6c584'
53
+ expect( client.subscriptions.first.offer.id ).to eq 'offer_5c74768d4d854c9df2a1'
54
+ expect( client.subscriptions.first.offer.name ).to eq 'test1'
55
+ expect( client.subscriptions.first.offer.amount ).to be 2000
56
+ expect( client.subscriptions.first.offer.currency ).to eq 'EUR'
57
+ expect( client.subscriptions.first.offer.interval ).to eq '1 WEEK'
58
+ expect( client.subscriptions.first.offer.trial_period_days ).to be_nil
59
+ expect( client.subscriptions.first.offer.created_at ).to be_a Time
60
+ expect( client.subscriptions.first.offer.updated_at ).to be_a Time
61
+ expect( client.subscriptions.first.offer.subscription_count.active ).to be 1
62
+ expect( client.subscriptions.first.offer.subscription_count.inactive ).to be 0
63
+ expect( client.subscriptions.first.offer.app_id ).to be_nil
64
+ expect( client.subscriptions.first.livemode ).to be false
65
+ expect( client.subscriptions.first.amount ).to be 2000
66
+ expect( client.subscriptions.first.temp_amount ).to be_nil
67
+ expect( client.subscriptions.first.currency ).to eq 'USD'
68
+ expect( client.subscriptions.first.name ).to eq 'test2'
69
+ expect( client.subscriptions.first.interval ).to eq '2 MONTH'
70
+ expect( client.subscriptions.first.trial_start ).to be_nil
71
+ expect( client.subscriptions.first.trial_end ).to be_nil
72
+ expect( client.subscriptions.first.period_of_validity ).to be_nil
73
+ expect( client.subscriptions.first.end_of_period ).to be_nil
74
+ expect( client.subscriptions.first.next_capture_at ).to be_a Time
75
+ expect( client.subscriptions.first.created_at ).to be_a Time
76
+ expect( client.subscriptions.first.updated_at ).to be_a Time
77
+ expect( client.subscriptions.first.canceled_at ).to be_nil
78
+ expect( client.subscriptions.first.payment ).to eq 'pay_f71c32615742beac11bf7b7c'
79
+ expect( client.subscriptions.first.app_id ).to be_nil
80
+ expect( client.subscriptions.first.is_canceled ).to be false
81
+ expect( client.subscriptions.first.is_deleted ).to be false
82
+ expect( client.subscriptions.first.status ).to eq 'active'
83
+ expect( client.subscriptions.first.client ).to eq 'client_a6dcf82f63c3a5627454'
84
+
85
+
86
+ expect( client.subscriptions.last ).to be_a Subscription
87
+ expect( client.subscriptions.last.id ).to eq 'sub_386b863839a6c9f6c584'
88
+ expect( client.subscriptions.last.offer.id ).to eq 'offer_5c74768d4d854c9df2a1'
89
+ expect( client.subscriptions.last.offer.name ).to eq 'test1'
90
+ expect( client.subscriptions.last.offer.amount ).to be 2000
91
+ expect( client.subscriptions.last.offer.currency ).to eq 'EUR'
92
+ expect( client.subscriptions.last.offer.interval ).to eq '1 WEEK'
93
+ expect( client.subscriptions.last.offer.trial_period_days ).to be_nil
94
+ expect( client.subscriptions.last.offer.created_at ).to be_a Time
95
+ expect( client.subscriptions.last.offer.updated_at ).to be_a Time
96
+ expect( client.subscriptions.last.offer.subscription_count.active ).to be 1
97
+ expect( client.subscriptions.last.offer.subscription_count.inactive ).to be 0
98
+ expect( client.subscriptions.last.offer.app_id ).to be_nil
99
+ expect( client.subscriptions.last.livemode ).to be false
100
+ expect( client.subscriptions.last.amount ).to be 2000
101
+ expect( client.subscriptions.last.temp_amount ).to be_nil
102
+ expect( client.subscriptions.last.currency ).to eq 'USD'
103
+ expect( client.subscriptions.last.name ).to eq 'test2'
104
+ expect( client.subscriptions.last.interval ).to eq '2 MONTH'
105
+ expect( client.subscriptions.last.trial_start ).to be_nil
106
+ expect( client.subscriptions.last.trial_end ).to be_nil
107
+ expect( client.subscriptions.last.period_of_validity ).to be_nil
108
+ expect( client.subscriptions.last.end_of_period ).to be_nil
109
+ expect( client.subscriptions.last.next_capture_at ).to be_a Time
110
+ expect( client.subscriptions.last.created_at ).to be_a Time
111
+ expect( client.subscriptions.last.updated_at ).to be_a Time
112
+ expect( client.subscriptions.last.canceled_at ).to be_nil
113
+ expect( client.subscriptions.last.payment ).to eq 'pay_f71c32615742beac11bf7b7c'
114
+ expect( client.subscriptions.last.app_id ).to be_nil
115
+ expect( client.subscriptions.last.is_canceled ).to be false
116
+ expect( client.subscriptions.last.is_deleted ).to be false
117
+ expect( client.subscriptions.last.status ).to eq 'active'
118
+ expect( client.subscriptions.last.client ).to eq 'client_a6dcf82f63c3a5627454'
119
+ end
120
+ end
121
+
122
+ context '::create' do
123
+ it 'should create new client with given email and description', :vcr do
124
+ client = Client.create( email: 'john.rambo@qaiware.com', description: 'Main caracter in First Blood' )
125
+ client_id = client.id
126
+
127
+ expect( client ).to be_a Client
128
+
129
+ expect( client.email ).to eq 'john.rambo@qaiware.com'
130
+ expect( client.description ).to eq 'Main caracter in First Blood'
131
+
132
+ expect( client.id ).to be_a String
133
+ expect( client.created_at ).to be_a Time
134
+ expect( client.updated_at ).to be_a Time
135
+ expect( client.app_id ).to be_nil
136
+
137
+
138
+ expect( client.payments.size ).to be 0
139
+ expect( client.subscriptions ).to be_nil
140
+ end
141
+
142
+ it 'should create new client with given email', :vcr do
143
+ client = Client.create( email: 'john.rambo@qaiware.com' )
144
+ expect( client ).to be_a Client
145
+
146
+ expect( client.email ).to eq 'john.rambo@qaiware.com'
147
+ expect( client.description ).to be_nil
148
+
149
+ expect( client.id ).to be_a String
150
+ expect( client.created_at ).to be_a Time
151
+ expect( client.updated_at ).to be_a Time
152
+ expect( client.app_id ).to be_nil
153
+
154
+
155
+ expect( client.payments.size ).to be 0
156
+ expect( client.subscriptions ).to be_nil
157
+ end
158
+
159
+ it 'should create new client with given description', :vcr do
160
+ client = Client.create( description: 'Main caracter in First Blood' )
161
+ expect( client ).to be_a Client
162
+
163
+ expect( client.email ).to be_nil
164
+ expect( client.description ).to eq 'Main caracter in First Blood'
165
+
166
+ expect( client.id ).to be_a String
167
+ expect( client.created_at ).to be_a Time
168
+ expect( client.updated_at ).to be_a Time
169
+ expect( client.app_id ).to be_nil
170
+
171
+ expect( client.payments.size ).to be 0
172
+ expect( client.subscriptions ).to be_nil
173
+ end
174
+
175
+ it 'should create new client with no arguments', :vcr do
176
+ client = Client.create()
177
+ expect( client ).to be_a Client
178
+
179
+ expect( client.email ).to be_nil
180
+ expect( client.description ).to be_nil
181
+
182
+ expect( client.id ).to be_a String
183
+ expect( client.created_at ).to be_a Time
184
+ expect( client.updated_at ).to be_a Time
185
+ expect( client.app_id ).to be_nil
186
+
187
+ expect( client.payments.size ).to be 0
188
+ expect( client.subscriptions ).to be_nil
189
+ end
190
+
191
+ it 'should throw ArgumentError when creating with invalid argument', :vcr do
192
+ expect{ Client.create( foo: 'foo' ) }.to raise_error ArgumentError
193
+ end
194
+ end
195
+
196
+ context '::update' do
197
+ it "should update client's email and description", :vcr do
198
+ client = Client.find( client_id )
199
+ created_at = client.created_at
200
+
201
+ client.email = 'john.ruby.rambo@qaiware.com'
202
+ client.description = 'Main Ruby caracter in First Blood'
203
+
204
+ client.update
205
+
206
+ expect( client ).to be_a Client
207
+ expect( client.email ).to eq 'john.ruby.rambo@qaiware.com'
208
+ expect( client.description ).to eq 'Main Ruby caracter in First Blood'
209
+ expect( client.id ).to be_a String
210
+ expect( client.created_at ).to eq created_at
211
+ expect( client.created_at ).to be < client.updated_at
212
+ expect( client.app_id ).to be_nil
213
+ expect( client.payments.size ).to be 0
214
+ expect( client.subscriptions ).to be_nil
215
+ end
216
+
217
+ it "should update client's email", :vcr do
218
+ client = Client.find( client_id )
219
+ created_at = client.created_at
220
+
221
+ client.email = 'john.rambo@qaiware.com'
222
+
223
+ client.update
224
+
225
+ expect( client ).to be_a Client
226
+ expect( client.email ).to eq 'john.rambo@qaiware.com'
227
+ expect( client.description ).to eq 'Main Ruby caracter in First Blood'
228
+ expect( client.id ).to be_a String
229
+ expect( client.created_at ).to eq created_at
230
+ expect( client.created_at ).to be < client.updated_at
231
+ expect( client.app_id ).to be_nil
232
+ expect( client.payments.size ).to be 0
233
+ expect( client.subscriptions ).to be_nil
234
+ end
235
+
236
+ it "should update client's description", :vcr do
237
+ client = Client.find( client_id )
238
+ created_at = client.created_at
239
+
240
+ client.description = 'Main caracter in First Blood'
241
+
242
+ client.update
243
+
244
+ expect( client ).to be_a Client
245
+ expect( client.email ).to eq 'john.rambo@qaiware.com'
246
+ expect( client.description ).to eq 'Main caracter in First Blood'
247
+ expect( client.id ).to be_a String
248
+ expect( client.created_at ).to eq created_at
249
+ expect( client.created_at ).to be < client.updated_at
250
+ expect( client.app_id ).to be_nil
251
+ expect( client.payments.size ).to be 0
252
+ expect( client.subscriptions ).to be_nil
253
+ end
254
+
255
+ it "should throw NoMethodError when updating unupdateable field", :vcr do
256
+ client = Client.find( client_id )
257
+ expect{ client.app_id = 'fake_app_id' }.to raise_error NoMethodError
258
+ end
259
+ end
260
+
261
+ context '::delete' do
262
+ it 'should delete existing client', :vcr do
263
+ client = Client.find( client_id )
264
+ expect( client.delete() ).to be_nil
265
+ end
266
+ end
267
+
268
+ context '::all' do
269
+ it 'should get all clients', :vcr do
270
+ clients = Client.all
271
+
272
+ expect( clients ).to be_a Array
273
+ expect( clients ).to respond_to :data_count
274
+ end
275
+
276
+ it 'should get all clients with sorting and filters', :vcr do
277
+ # 2015-07-08 00:43:14 to 2015-07-14 23:23:14
278
+ clients = Client.all( order: [:email_asc], filters: [created_at: "1436316194-1436916194"] )
279
+
280
+ expect( clients ).to be_a Array
281
+ expect( clients ).to respond_to :data_count
282
+ expect( clients.size ).to be 20
283
+ end
284
+
285
+ it 'should get all clients with filters', :vcr do
286
+ clients = Client.all( filters: [email: 'john.rambo@qaiware.com', description: 'Boom, boom, shake the room'] )
287
+
288
+ expect( clients ).to be_a Array
289
+ expect( clients ).to respond_to :data_count
290
+ expect( clients.size ).to be 20
291
+ end
292
+
293
+ it 'should get all clients with order and count', :vcr do
294
+ clients = Client.all( order: [:email, :created_at_desc], count: 30 )
295
+
296
+ expect( clients ).to be_a Array
297
+ expect( clients ).to respond_to :data_count
298
+ expect( clients.size ).to be 30
299
+ end
300
+
301
+ it 'should get all clients with order, count and offset', :vcr do
302
+ clients = Client.all( order: [:email, :created_at_desc], count: 30, offset: 10 )
303
+
304
+ expect( clients ).to be_a Array
305
+ expect( clients ).to respond_to :data_count
306
+ expect( clients.size ).to be 30
307
+ end
308
+
309
+ end
310
+ end
311
+ end