stripe_tester 0.0.3 → 0.0.4

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 (43) hide show
  1. data/README.md +49 -1
  2. data/lib/stripe_tester.rb +29 -6
  3. data/lib/stripe_tester/version.rb +1 -1
  4. data/spec/stripe_tester_spec.rb +19 -1
  5. data/stripe_webhooks/2013-08-13/account_updated.yml +21 -0
  6. data/stripe_webhooks/2013-08-13/balance_available.yml +18 -0
  7. data/stripe_webhooks/2013-08-13/charge_dispute_closed.yml +19 -0
  8. data/stripe_webhooks/2013-08-13/charge_dispute_created.yml +19 -0
  9. data/stripe_webhooks/2013-08-13/charge_dispute_updated.yml +21 -0
  10. data/stripe_webhooks/2013-08-13/charge_failed.yml +47 -0
  11. data/stripe_webhooks/2013-08-13/charge_refunded.yml +48 -0
  12. data/stripe_webhooks/2013-08-13/charge_succeeded.yml +47 -0
  13. data/stripe_webhooks/2013-08-13/coupon_created.yml +19 -0
  14. data/stripe_webhooks/2013-08-13/coupon_deleted.yml +19 -0
  15. data/stripe_webhooks/2013-08-13/customer_card_created.yml +29 -0
  16. data/stripe_webhooks/2013-08-13/customer_card_deleted.yml +29 -0
  17. data/stripe_webhooks/2013-08-13/customer_card_updated.yml +31 -0
  18. data/stripe_webhooks/2013-08-13/customer_created.yml +69 -0
  19. data/stripe_webhooks/2013-08-13/customer_deleted.yml +69 -0
  20. data/stripe_webhooks/2013-08-13/customer_discount_created.yml +24 -0
  21. data/stripe_webhooks/2013-08-13/customer_discount_deleted.yml +24 -0
  22. data/stripe_webhooks/2013-08-13/customer_discount_updated.yml +37 -0
  23. data/stripe_webhooks/2013-08-13/customer_subscription_created.yml +32 -0
  24. data/stripe_webhooks/2013-08-13/customer_subscription_deleted.yml +32 -0
  25. data/stripe_webhooks/2013-08-13/customer_subscription_trial_will_end.yml +32 -0
  26. data/stripe_webhooks/2013-08-13/customer_subscription_updated.yml +43 -0
  27. data/stripe_webhooks/2013-08-13/customer_updated.yml +71 -0
  28. data/stripe_webhooks/2013-08-13/invoice_created.yml +57 -0
  29. data/stripe_webhooks/2013-08-13/invoice_payment_failed.yml +57 -0
  30. data/stripe_webhooks/2013-08-13/invoice_payment_succeeded.yml +57 -0
  31. data/stripe_webhooks/2013-08-13/invoice_updated.yml +59 -0
  32. data/stripe_webhooks/2013-08-13/invoiceitem_created.yml +18 -0
  33. data/stripe_webhooks/2013-08-13/invoiceitem_deleted.yml +18 -0
  34. data/stripe_webhooks/2013-08-13/invoiceitem_updated.yml +20 -0
  35. data/stripe_webhooks/2013-08-13/plan_created.yml +17 -0
  36. data/stripe_webhooks/2013-08-13/plan_deleted.yml +17 -0
  37. data/stripe_webhooks/2013-08-13/plan_updated.yml +19 -0
  38. data/stripe_webhooks/2013-08-13/transfer_created.yml +21 -0
  39. data/stripe_webhooks/2013-08-13/transfer_failed.yml +21 -0
  40. data/stripe_webhooks/2013-08-13/transfer_paid.yml +21 -0
  41. data/stripe_webhooks/2013-08-13/transfer_updated.yml +23 -0
  42. data/wercker.yml +22 -0
  43. metadata +41 -3
data/README.md CHANGED
@@ -48,9 +48,14 @@ In your test:
48
48
  StripeTester.create_event("invoice_created")
49
49
  ```
50
50
 
51
- Or if you want to overwrite certain attributes:
51
+ Or if you want to overwrite certain attributes globally:
52
52
  ```ruby
53
53
  StripeTester.create_event(:invoice_created, {"amount" => 100, "currency" => 'gbp'})
54
+ ```
55
+
56
+ Or you can explicitly overwrite certain attributes using deep object merging:
57
+ ```ruby
58
+ StripeTester.create_event(:customer_subscription_created, {"data"=>{"object"=>{"plan"=>{"id"=>"gold-v1"}}}}, :method=>:merge)
54
59
  ```
55
60
 
56
61
  If you want to load the JSON only:
@@ -60,6 +65,8 @@ json = StripeTester.load_template(:invoice_payment_failed)
60
65
 
61
66
  ## Supported Webhooks
62
67
 
68
+ Version 2013-07-05:
69
+
63
70
  * charge_failed
64
71
  * charge_refunded
65
72
  * charge_succeeded
@@ -74,8 +81,49 @@ json = StripeTester.load_template(:invoice_payment_failed)
74
81
  * invoice_payment_succeeded
75
82
  * invoice_updated
76
83
 
84
+ Version 2013-08-13:
85
+
86
+ * account.updated
87
+ * balance.available
88
+ * charge.dispute.closed
89
+ * charge.dispute.created
90
+ * charge.dispute.updated
91
+ * charge.failed
92
+ * charge.refunded
93
+ * charge.succeeded
94
+ * coupon.created
95
+ * coupon.deleted
96
+ * customer.card.created
97
+ * customer.card.deleted
98
+ * customer.card.updated
99
+ * customer.created
100
+ * customer.deleted
101
+ * customer.discount.created
102
+ * customer.discount.deleted
103
+ * customer.discount.updated
104
+ * customer.subscription.created
105
+ * customer.subscription.deleted
106
+ * customer.subscription.trial_will_end
107
+ * customer.subscription.updated
108
+ * customer.updated
109
+ * invoice.created
110
+ * invoice.payment_failed
111
+ * invoice.payment_succeeded
112
+ * invoice.updated
113
+ * invoiceitem.created
114
+ * invoiceitem.deleted
115
+ * invoiceitem.updated
116
+ * plan.created
117
+ * plan.deleted
118
+ * plan.updated
119
+ * transfer.created
120
+ * transfer.failed
121
+ * transfer.paid
122
+ * transfer.updated
123
+
77
124
  ## Supported Stripe Webhook API Versions
78
125
 
126
+ * 2013-08-13
79
127
  * 2013-07-05
80
128
  * 2013-02-13
81
129
 
data/lib/stripe_tester.rb CHANGED
@@ -5,23 +5,31 @@ require 'json'
5
5
 
6
6
  module StripeTester
7
7
 
8
- LATEST_STRIPE_VERSION = "2013-07-05"
8
+ LATEST_STRIPE_VERSION = "2013-08-13"
9
9
 
10
10
  # send the url the webhook event
11
- def self.create_event(callback_type, options={})
11
+ # There are two options you can use. :method=>:overwrite, or :method=>:merge
12
+ # Each will use a different way of merging the new attributes.
13
+ def self.create_event(callback_type, attributes={}, options={method: :overwrite})
12
14
  webhook_data = self.load_template(callback_type)
13
15
 
14
16
  if webhook_data
15
- webhook_data = overwrite_attributes(webhook_data, options) unless options.empty?
17
+ unless attributes.empty?
18
+ if options[:method] == :merge
19
+ webhook_data = merge_attributes(webhook_data, attributes)
20
+ else
21
+ webhook_data = overwrite_attributes(webhook_data, attributes)
22
+ end
23
+ end
16
24
  post_to_url(webhook_data)
17
25
  end
18
26
  end
19
27
 
20
28
  # replace multiple values for multiple keys in a hash
21
- def self.overwrite_attributes(original_data, options={})
29
+ def self.overwrite_attributes(original_data, attributes={})
22
30
  data = original_data.clone
23
- if options
24
- options.each do |k,v|
31
+ if attributes
32
+ attributes.each do |k,v|
25
33
  replace_value(data, k, v)
26
34
  end
27
35
  end
@@ -41,6 +49,21 @@ module StripeTester
41
49
  end
42
50
  end
43
51
 
52
+ # deep merge original_attributes with new_attributes
53
+ def self.merge_attributes(original_attributes, new_attributes={})
54
+ original_attributes = original_attributes.clone
55
+ if new_attributes
56
+ new_attributes.each do |key, value|
57
+ if value.is_a?(Hash) && original_attributes[key].is_a?(Hash)
58
+ original_attributes[key] = self.merge_attributes original_attributes[key], value
59
+ else
60
+ original_attributes[key] = value
61
+ end
62
+ end
63
+ end
64
+ original_attributes
65
+ end
66
+
44
67
  def self.post_to_url(data={})
45
68
  post_url = webhook_url
46
69
 
@@ -1,3 +1,3 @@
1
1
  module StripeTester
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,7 +4,7 @@ describe StripeTester do
4
4
 
5
5
  describe "instance methods" do
6
6
 
7
- LATEST_STRIPE_VERSION = "2013-07-05"
7
+ LATEST_STRIPE_VERSION = "2013-08-13"
8
8
 
9
9
  before(:each) do
10
10
  StripeTester.remove_url
@@ -127,5 +127,23 @@ describe StripeTester do
127
127
 
128
128
  expect(new_data[:info][:age]).to eq(99)
129
129
  end
130
+
131
+ it "#merge_attributes should do a deep merge" do
132
+ original_data = {name: 'john smith',
133
+ info: {age: 45,
134
+ gender: 'male',
135
+ occupation: {title: 'Software Developer',
136
+ employer: 'ACME, Inc'},
137
+ address: {street: '123 Fake St',
138
+ city: 'Somewhere',
139
+ state: 'NC',
140
+ zip: '12345'}}}
141
+ new_data = StripeTester.merge_attributes(original_data, {name: 'jane smith', info: {gender: 'female', address: {city: 'Springfield'}}})
142
+ expect(new_data[:name]).to eq('jane smith')
143
+ expect(new_data[:info][:gender]).to eq('female')
144
+ expect(new_data[:info][:age]).to eq(45)
145
+ expect(new_data[:info][:address][:city]).to eq('Springfield')
146
+ expect(new_data[:info][:address][:state]).to eq('NC')
147
+ end
130
148
  end
131
149
  end
@@ -0,0 +1,21 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: account.updated
6
+ object: event
7
+ data:
8
+ object:
9
+ id: user_00000000000000
10
+ email: test@stripe.com
11
+ statement_descriptor: TEST
12
+ details_submitted: true
13
+ charge_enabled: false
14
+ transfer_enabled: false
15
+ currencies_supported:
16
+ - USD
17
+ default_currency: USD
18
+ country: US
19
+ object: account
20
+ previous_attributes:
21
+ details_submitted: false
@@ -0,0 +1,18 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: balance.available
6
+ object: event
7
+ data:
8
+ object:
9
+ pending:
10
+ -
11
+ amount: 0
12
+ currency: usd
13
+ available:
14
+ -
15
+ amount: 0
16
+ currency: usd
17
+ livemode: false
18
+ object: balance
@@ -0,0 +1,19 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: charge.dispute.closed
6
+ object: event
7
+ data:
8
+ object:
9
+ charge: ch_00000000000000
10
+ amount: 1000
11
+ created: 1381515417
12
+ status: won
13
+ livemode: false
14
+ currency: usd
15
+ object: dispute
16
+ reason: general
17
+ balance_transaction: txn_00000000000000
18
+ evidence_due_by: 1383177599
19
+ evidence: Here is some evidence
@@ -0,0 +1,19 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: charge.dispute.created
6
+ object: event
7
+ data:
8
+ object:
9
+ charge: ch_00000000000000
10
+ amount: 1000
11
+ created: 1381515413
12
+ status: needs_response
13
+ livemode: false
14
+ currency: usd
15
+ object: dispute
16
+ reason: general
17
+ balance_transaction: txn_00000000000000
18
+ evidence_due_by: 1383177599
19
+ evidence:
@@ -0,0 +1,21 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: charge.dispute.updated
6
+ object: event
7
+ data:
8
+ object:
9
+ charge: ch_00000000000000
10
+ amount: 1000
11
+ created: 1381515415
12
+ status: under_review
13
+ livemode: false
14
+ currency: usd
15
+ object: dispute
16
+ reason: general
17
+ balance_transaction: txn_00000000000000
18
+ evidence_due_by: 1383177599
19
+ evidence: Here is some evidence
20
+ previous_attributes:
21
+ evidence:
@@ -0,0 +1,47 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: charge.failed
6
+ object: event
7
+ data:
8
+ object:
9
+ id: ch_00000000000000
10
+ object: charge
11
+ created: 1381510413
12
+ livemode: false
13
+ paid: false
14
+ amount: 0
15
+ currency: usd
16
+ refunded: false
17
+ card:
18
+ id: card_00000000000000
19
+ object: card
20
+ last4: '4242'
21
+ type: Visa
22
+ exp_month: 8
23
+ exp_year: 2018
24
+ fingerprint: XslDljXmd9D6ii0D
25
+ customer: cus_00000000000000
26
+ country: US
27
+ name:
28
+ address_line1:
29
+ address_line2:
30
+ address_city:
31
+ address_state:
32
+ address_zip:
33
+ address_country:
34
+ cvc_check: pass
35
+ address_line1_check:
36
+ address_zip_check:
37
+ captured: false
38
+ refunds:
39
+ balance_transaction: txn_00000000000000
40
+ failure_message:
41
+ failure_code:
42
+ amount_refunded: 0
43
+ customer:
44
+ invoice:
45
+ description:
46
+ dispute:
47
+ metadata:
@@ -0,0 +1,48 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: charge.refunded
6
+ object: event
7
+ data:
8
+ object:
9
+ id: ch_00000000000000
10
+ object: charge
11
+ created: 1381510413
12
+ livemode: false
13
+ paid: true
14
+ amount: 0
15
+ currency: usd
16
+ refunded: true
17
+ card:
18
+ id: card_00000000000000
19
+ object: card
20
+ last4: '4242'
21
+ type: Visa
22
+ exp_month: 8
23
+ exp_year: 2018
24
+ fingerprint: XslDljXmd9D6ii0D
25
+ customer: cus_00000000000000
26
+ country: US
27
+ name:
28
+ address_line1:
29
+ address_line2:
30
+ address_city:
31
+ address_state:
32
+ address_zip:
33
+ address_country:
34
+ cvc_check: pass
35
+ address_line1_check:
36
+ address_zip_check:
37
+ captured: false
38
+ refunds:
39
+ balance_transaction: txn_00000000000000
40
+ failure_message:
41
+ failure_code:
42
+ amount_refunded: 0
43
+ customer:
44
+ invoice:
45
+ description:
46
+ dispute:
47
+ metadata:
48
+ fee: 0
@@ -0,0 +1,47 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: charge.succeeded
6
+ object: event
7
+ data:
8
+ object:
9
+ id: ch_00000000000000
10
+ object: charge
11
+ created: 1381510413
12
+ livemode: false
13
+ paid: true
14
+ amount: 0
15
+ currency: usd
16
+ refunded: false
17
+ card:
18
+ id: card_00000000000000
19
+ object: card
20
+ last4: '4242'
21
+ type: Visa
22
+ exp_month: 8
23
+ exp_year: 2018
24
+ fingerprint: XslDljXmd9D6ii0D
25
+ customer: cus_00000000000000
26
+ country: US
27
+ name:
28
+ address_line1:
29
+ address_line2:
30
+ address_city:
31
+ address_state:
32
+ address_zip:
33
+ address_country:
34
+ cvc_check: pass
35
+ address_line1_check:
36
+ address_zip_check:
37
+ captured: false
38
+ refunds:
39
+ balance_transaction: txn_00000000000000
40
+ failure_message:
41
+ failure_code:
42
+ amount_refunded: 0
43
+ customer:
44
+ invoice:
45
+ description:
46
+ dispute:
47
+ metadata:
@@ -0,0 +1,19 @@
1
+ ---
2
+ created: 1326853478
3
+ livemode: false
4
+ id: evt_00000000000000
5
+ type: coupon.created
6
+ object: event
7
+ data:
8
+ object:
9
+ id: BETAYEAR_00000000000000
10
+ percent_off: 100
11
+ amount_off:
12
+ currency: usd
13
+ object: coupon
14
+ livemode: false
15
+ duration: repeating
16
+ redeem_by:
17
+ max_redemptions:
18
+ times_redeemed: 0
19
+ duration_in_months: 12