stripe-ruby-mock 1.8.3.6 → 1.8.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/lib/stripe_mock.rb +8 -0
  2. data/lib/stripe_mock/api/errors.rb +16 -16
  3. data/lib/stripe_mock/api/webhooks.rb +55 -0
  4. data/lib/stripe_mock/errors/unsupported_request_error.rb +4 -0
  5. data/lib/stripe_mock/util.rb +23 -0
  6. data/lib/stripe_mock/version.rb +1 -1
  7. data/lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json +12 -0
  8. data/lib/stripe_mock/webhook_fixtures/account.updated.json +24 -0
  9. data/lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json +21 -0
  10. data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +21 -0
  11. data/lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json +24 -0
  12. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +57 -0
  13. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +57 -0
  14. data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +57 -0
  15. data/lib/stripe_mock/webhook_fixtures/coupon.created.json +22 -0
  16. data/lib/stripe_mock/webhook_fixtures/coupon.deleted.json +22 -0
  17. data/lib/stripe_mock/webhook_fixtures/customer.created.json +40 -0
  18. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +40 -0
  19. data/lib/stripe_mock/webhook_fixtures/customer.discount.created.json +28 -0
  20. data/lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json +28 -0
  21. data/lib/stripe_mock/webhook_fixtures/customer.discount.updated.json +43 -0
  22. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +34 -0
  23. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +34 -0
  24. data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +34 -0
  25. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +47 -0
  26. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +43 -0
  27. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +64 -0
  28. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +64 -0
  29. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +64 -0
  30. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +67 -0
  31. data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +21 -0
  32. data/lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json +21 -0
  33. data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +24 -0
  34. data/lib/stripe_mock/webhook_fixtures/plan.created.json +20 -0
  35. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +20 -0
  36. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +23 -0
  37. data/lib/stripe_mock/webhook_fixtures/transfer.created.json +23 -0
  38. data/lib/stripe_mock/webhook_fixtures/transfer.failed.json +23 -0
  39. data/lib/stripe_mock/webhook_fixtures/transfer.paid.json +23 -0
  40. data/lib/stripe_mock/webhook_fixtures/transfer.updated.json +26 -0
  41. data/spec/spec_helper.rb +2 -0
  42. data/spec/util_spec.rb +45 -0
  43. data/spec/webhook_spec.rb +61 -0
  44. metadata +43 -2
data/lib/stripe_mock.rb CHANGED
@@ -6,8 +6,10 @@ require 'stripe'
6
6
 
7
7
  require 'stripe_mock/version'
8
8
  require 'stripe_mock/data'
9
+ require 'stripe_mock/util'
9
10
 
10
11
  require 'stripe_mock/errors/stripe_mock_error'
12
+ require 'stripe_mock/errors/unsupported_request_error'
11
13
  require 'stripe_mock/errors/uninitialized_instance_error'
12
14
  require 'stripe_mock/errors/unstarted_state_error'
13
15
  require 'stripe_mock/errors/server_timeout_error'
@@ -20,9 +22,15 @@ require 'stripe_mock/api/instance'
20
22
  require 'stripe_mock/api/client'
21
23
  require 'stripe_mock/api/server'
22
24
  require 'stripe_mock/api/errors'
25
+ require 'stripe_mock/api/webhooks'
23
26
 
24
27
  require 'stripe_mock/request_handlers/charges.rb'
25
28
  require 'stripe_mock/request_handlers/customers.rb'
26
29
  require 'stripe_mock/request_handlers/invoice_items.rb'
27
30
  require 'stripe_mock/request_handlers/plans.rb'
28
31
  require 'stripe_mock/instance'
32
+
33
+ module StripeMock
34
+ lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
35
+ @webhook_fixture_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
36
+ end
@@ -11,26 +11,26 @@ module StripeMock
11
11
  end
12
12
 
13
13
  def self.prepare_card_error(code)
14
- args = card_error_args[code]
14
+ args = CardErrors.argument_map[code]
15
15
  raise StripeMockError.new("Unrecognized stripe card error code: #{code}") if args.nil?
16
16
  self.prepare_error Stripe::CardError.new(*args)
17
17
  end
18
18
 
19
- private
20
-
21
- def self.card_error_args
22
- @__map ||= {
23
- incorrect_number: ["The card number is incorrect", 'number', 'incorrect_number', 402],
24
- invalid_number: ["The card number is not a valid credit card number", 'number', 'invalid_number', 402],
25
- invalid_expiry_month: ["The card's expiration month is invalid", 'exp_month', 'invalid_expiry_month', 402],
26
- invalid_expiry_year: ["The card's expiration year is invalid", 'exp_year', 'invalid_expiry_year', 402],
27
- invalid_cvc: ["The card's security code is invalid", 'cvc', 'invalid_cvc', 402],
28
- expired_card: ["The card has expired", 'exp_month', 'expired_card', 402],
29
- incorrect_cvc: ["The card's security code is incorrect", 'cvc', 'incorrect_cvc', 402],
30
- card_declined: ["The card was declined", nil, 'card_declined', 402],
31
- missing: ["There is no card on a customer that is being charged.", nil, 'missing', 402],
32
- processing_error: ["An error occurred while processing the card", nil, 'processing_error', 402],
33
- }
19
+ module CardErrors
20
+ def self.argument_map
21
+ @__map ||= {
22
+ incorrect_number: ["The card number is incorrect", 'number', 'incorrect_number', 402],
23
+ invalid_number: ["The card number is not a valid credit card number", 'number', 'invalid_number', 402],
24
+ invalid_expiry_month: ["The card's expiration month is invalid", 'exp_month', 'invalid_expiry_month', 402],
25
+ invalid_expiry_year: ["The card's expiration year is invalid", 'exp_year', 'invalid_expiry_year', 402],
26
+ invalid_cvc: ["The card's security code is invalid", 'cvc', 'invalid_cvc', 402],
27
+ expired_card: ["The card has expired", 'exp_month', 'expired_card', 402],
28
+ incorrect_cvc: ["The card's security code is incorrect", 'cvc', 'incorrect_cvc', 402],
29
+ card_declined: ["The card was declined", nil, 'card_declined', 402],
30
+ missing: ["There is no card on a customer that is being charged.", nil, 'missing', 402],
31
+ processing_error: ["An error occurred while processing the card", nil, 'processing_error', 402],
32
+ }
33
+ end
34
34
  end
35
35
 
36
36
  end
@@ -0,0 +1,55 @@
1
+ module StripeMock
2
+
3
+ def self.mock_webhook_event(type, params={})
4
+ unless Webhooks.event_list.include?(type)
5
+ raise UnsupportedRequestError.new "Unsupported webhook event `#{type}`"
6
+ end
7
+ json = MultiJson.load File.read File.join(@webhook_fixture_path, "#{type}.json")
8
+
9
+ json = Stripe::Util.symbolize_names(json)
10
+ params = Stripe::Util.symbolize_names(params)
11
+ Stripe::Event.construct_from Util.rmerge(json, params)
12
+ end
13
+
14
+ module Webhooks
15
+ def self.event_list
16
+ @__list = [
17
+ 'account.updated',
18
+ 'account.application.deauthorized',
19
+ 'charge.succeeded',
20
+ 'charge.failed',
21
+ 'charge.refunded',
22
+ 'charge.dispute.created',
23
+ 'charge.dispute.updated',
24
+ 'charge.dispute.closed',
25
+ 'customer.created',
26
+ 'customer.updated',
27
+ 'customer.deleted',
28
+ 'customer.subscription.created',
29
+ 'customer.subscription.updated',
30
+ 'customer.subscription.deleted',
31
+ 'customer.subscription.trial_will_end',
32
+ 'customer.discount.created',
33
+ 'customer.discount.updated',
34
+ 'customer.discount.deleted',
35
+ 'invoice.created',
36
+ 'invoice.updated',
37
+ 'invoice.payment_succeeded',
38
+ 'invoice.payment_failed',
39
+ 'invoiceitem.created',
40
+ 'invoiceitem.updated',
41
+ 'invoiceitem.deleted',
42
+ 'plan.created',
43
+ 'plan.updated',
44
+ 'plan.deleted',
45
+ 'coupon.created',
46
+ 'coupon.deleted',
47
+ 'transfer.created',
48
+ 'transfer.paid',
49
+ 'transfer.updated',
50
+ 'transfer.failed'
51
+ ]
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,4 @@
1
+ module StripeMock
2
+ class UnsupportedRequestError < StripeMockError
3
+ end
4
+ end
@@ -0,0 +1,23 @@
1
+ module StripeMock
2
+ module Util
3
+
4
+ def self.rmerge(hash_one, hash_two)
5
+ return hash_two if hash_one.nil?
6
+ return nil if hash_two.nil?
7
+
8
+ hash_one.merge(hash_two) do |key, oldval, newval|
9
+ if oldval.is_a?(Array) && newval.is_a?(Array)
10
+ oldval.zip(newval).map {|elems|
11
+ elems[1].nil? ? elems[0] : rmerge(elems[0], elems[1])
12
+ }
13
+ elsif oldval.is_a?(Hash) && newval.is_a?(Hash)
14
+ rmerge(oldval, newval)
15
+ else
16
+ newval
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.8.3.6"
3
+ VERSION = "1.8.3.7"
4
4
  end
@@ -0,0 +1,12 @@
1
+ {
2
+ "type": "account.application.deauthorized",
3
+ "object": "event",
4
+ "created": 1326853478,
5
+ "livemode": false,
6
+ "id": "evt_00000000000000",
7
+ "data": {
8
+ "object": {
9
+ "id": "cus_00000000000000"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "charge_enabled": false,
6
+ "currencies_supported": [
7
+ "USD"
8
+ ],
9
+ "details_submitted": true,
10
+ "email": "test@stripe.com",
11
+ "id": "acct_00000000000000",
12
+ "object": "account",
13
+ "statement_descriptor": "TEST",
14
+ "transfer_enabled": false
15
+ },
16
+ "previous_attributes": {
17
+ "details_submitted": false
18
+ }
19
+ },
20
+ "id": "evt_00000000000000",
21
+ "livemode": false,
22
+ "object": "event",
23
+ "type": "account.updated"
24
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "amount": 1000,
6
+ "charge": "ch_00000000000000",
7
+ "created": 1371500754,
8
+ "currency": "usd",
9
+ "evidence": "Here is some evidence",
10
+ "evidence_due_by": 1373155199,
11
+ "livemode": false,
12
+ "object": "dispute",
13
+ "reason": "general",
14
+ "status": "won"
15
+ }
16
+ },
17
+ "id": "evt_00000000000000",
18
+ "livemode": false,
19
+ "object": "event",
20
+ "type": "charge.dispute.closed"
21
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "amount": 1000,
6
+ "charge": "ch_00000000000000",
7
+ "created": 1371500744,
8
+ "currency": "usd",
9
+ "evidence": null,
10
+ "evidence_due_by": 1373155199,
11
+ "livemode": false,
12
+ "object": "dispute",
13
+ "reason": "general",
14
+ "status": "needs_response"
15
+ }
16
+ },
17
+ "id": "evt_00000000000000",
18
+ "livemode": false,
19
+ "object": "event",
20
+ "type": "charge.dispute.created"
21
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "amount": 1000,
6
+ "charge": "ch_00000000000000",
7
+ "created": 1371500750,
8
+ "currency": "usd",
9
+ "evidence": "Here is some evidence",
10
+ "evidence_due_by": 1373155199,
11
+ "livemode": false,
12
+ "object": "dispute",
13
+ "reason": "general",
14
+ "status": "under_review"
15
+ },
16
+ "previous_attributes": {
17
+ "evidence": null
18
+ }
19
+ },
20
+ "id": "evt_00000000000000",
21
+ "livemode": false,
22
+ "object": "event",
23
+ "type": "charge.dispute.updated"
24
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "amount": 14500,
6
+ "amount_refunded": 0,
7
+ "captured": true,
8
+ "card": {
9
+ "address_city": null,
10
+ "address_country": null,
11
+ "address_line1": null,
12
+ "address_line1_check": null,
13
+ "address_line2": null,
14
+ "address_state": null,
15
+ "address_zip": null,
16
+ "address_zip_check": null,
17
+ "country": "US",
18
+ "cvc_check": null,
19
+ "exp_month": 2,
20
+ "exp_year": 2016,
21
+ "fingerprint": "wXWJT135mEK107G8",
22
+ "last4": "4242",
23
+ "name": "Johnny Appleseed",
24
+ "object": "card",
25
+ "type": "Visa"
26
+ },
27
+ "created": 1360179715,
28
+ "currency": "usd",
29
+ "customer": null,
30
+ "description": "Customer: Johnny Appleseed Email: japp@mailinator.com Product: A Box of Happiness ID: 36 Quantity: 3 ",
31
+ "dispute": null,
32
+ "failure_code": null,
33
+ "failure_message": null,
34
+ "fee": 451,
35
+ "fee_details": [
36
+ {
37
+ "amount": 451,
38
+ "amount_refunded": 0,
39
+ "application": null,
40
+ "currency": "usd",
41
+ "description": "Stripe processing fees",
42
+ "type": "stripe_fee"
43
+ }
44
+ ],
45
+ "id": "ch_00000000000000",
46
+ "invoice": null,
47
+ "livemode": false,
48
+ "object": "charge",
49
+ "paid": false,
50
+ "refunded": false
51
+ }
52
+ },
53
+ "id": "evt_00000000000000",
54
+ "livemode": false,
55
+ "object": "event",
56
+ "type": "charge.failed"
57
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "amount": 14500,
6
+ "amount_refunded": 0,
7
+ "captured": true,
8
+ "card": {
9
+ "address_city": null,
10
+ "address_country": null,
11
+ "address_line1": null,
12
+ "address_line1_check": null,
13
+ "address_line2": null,
14
+ "address_state": null,
15
+ "address_zip": null,
16
+ "address_zip_check": null,
17
+ "country": "US",
18
+ "cvc_check": null,
19
+ "exp_month": 2,
20
+ "exp_year": 2016,
21
+ "fingerprint": "wXWJT135mEK107G8",
22
+ "last4": "4242",
23
+ "name": "Johnny Appleseed",
24
+ "object": "card",
25
+ "type": "Visa"
26
+ },
27
+ "created": 1360179715,
28
+ "currency": "usd",
29
+ "customer": null,
30
+ "description": "Customer: Johnny Appleseed Email: japp@mailinator.com Product: A Box of Happiness ID: 36 Quantity: 3 ",
31
+ "dispute": null,
32
+ "failure_code": null,
33
+ "failure_message": null,
34
+ "fee": 0,
35
+ "fee_details": [
36
+ {
37
+ "amount": 451,
38
+ "amount_refunded": 0,
39
+ "application": null,
40
+ "currency": "usd",
41
+ "description": "Stripe processing fees",
42
+ "type": "stripe_fee"
43
+ }
44
+ ],
45
+ "id": "ch_00000000000000",
46
+ "invoice": null,
47
+ "livemode": false,
48
+ "object": "charge",
49
+ "paid": true,
50
+ "refunded": true
51
+ }
52
+ },
53
+ "id": "evt_00000000000000",
54
+ "livemode": false,
55
+ "object": "event",
56
+ "type": "charge.refunded"
57
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "created": 1326853478,
3
+ "data": {
4
+ "object": {
5
+ "amount": 14500,
6
+ "amount_refunded": 0,
7
+ "captured": true,
8
+ "card": {
9
+ "address_city": null,
10
+ "address_country": null,
11
+ "address_line1": null,
12
+ "address_line1_check": null,
13
+ "address_line2": null,
14
+ "address_state": null,
15
+ "address_zip": null,
16
+ "address_zip_check": null,
17
+ "country": "US",
18
+ "cvc_check": null,
19
+ "exp_month": 2,
20
+ "exp_year": 2016,
21
+ "fingerprint": "wXWJT135mEK107G8",
22
+ "last4": "4242",
23
+ "name": "Johnny Appleseed",
24
+ "object": "card",
25
+ "type": "Visa"
26
+ },
27
+ "created": 1360179715,
28
+ "currency": "usd",
29
+ "customer": null,
30
+ "description": "Customer: Johnny Appleseed Email: japp@mailinator.com Product: A Box of Happiness ID: 36 Quantity: 3 ",
31
+ "dispute": null,
32
+ "failure_code": null,
33
+ "failure_message": null,
34
+ "fee": 451,
35
+ "fee_details": [
36
+ {
37
+ "amount": 451,
38
+ "amount_refunded": 0,
39
+ "application": null,
40
+ "currency": "usd",
41
+ "description": "Stripe processing fees",
42
+ "type": "stripe_fee"
43
+ }
44
+ ],
45
+ "id": "ch_00000000000000",
46
+ "invoice": null,
47
+ "livemode": false,
48
+ "object": "charge",
49
+ "paid": true,
50
+ "refunded": false
51
+ }
52
+ },
53
+ "id": "evt_00000000000000",
54
+ "livemode": false,
55
+ "object": "event",
56
+ "type": "charge.succeeded"
57
+ }