stripe_local 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +35 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/stripe_local/application.js +13 -0
  6. data/app/assets/javascripts/stripe_local/cards.js +2 -0
  7. data/app/assets/javascripts/stripe_local/charges.js +2 -0
  8. data/app/assets/javascripts/stripe_local/coupons.js +2 -0
  9. data/app/assets/javascripts/stripe_local/customers.js +2 -0
  10. data/app/assets/javascripts/stripe_local/discounts.js +2 -0
  11. data/app/assets/javascripts/stripe_local/invoices.js +2 -0
  12. data/app/assets/javascripts/stripe_local/line_items.js +2 -0
  13. data/app/assets/javascripts/stripe_local/plans.js +2 -0
  14. data/app/assets/javascripts/stripe_local/subscriptions.js +2 -0
  15. data/app/assets/stylesheets/stripe_local/application.css +13 -0
  16. data/app/assets/stylesheets/stripe_local/cards.css +4 -0
  17. data/app/assets/stylesheets/stripe_local/charges.css +4 -0
  18. data/app/assets/stylesheets/stripe_local/coupons.css +4 -0
  19. data/app/assets/stylesheets/stripe_local/customers.css +4 -0
  20. data/app/assets/stylesheets/stripe_local/discounts.css +4 -0
  21. data/app/assets/stylesheets/stripe_local/invoices.css +4 -0
  22. data/app/assets/stylesheets/stripe_local/line_items.css +4 -0
  23. data/app/assets/stylesheets/stripe_local/plans.css +4 -0
  24. data/app/assets/stylesheets/stripe_local/subscriptions.css +4 -0
  25. data/app/callbacks/stripe_local/plan_sync.rb +33 -0
  26. data/app/controllers/stripe_local/application_controller.rb +4 -0
  27. data/app/controllers/stripe_local/cards_controller.rb +6 -0
  28. data/app/controllers/stripe_local/charges_controller.rb +6 -0
  29. data/app/controllers/stripe_local/coupons_controller.rb +6 -0
  30. data/app/controllers/stripe_local/customers_controller.rb +6 -0
  31. data/app/controllers/stripe_local/discounts_controller.rb +6 -0
  32. data/app/controllers/stripe_local/invoices_controller.rb +6 -0
  33. data/app/controllers/stripe_local/line_items_controller.rb +6 -0
  34. data/app/controllers/stripe_local/plans_controller.rb +6 -0
  35. data/app/controllers/stripe_local/subscriptions_controller.rb +6 -0
  36. data/app/controllers/stripe_local/webhooks_controller.rb +13 -0
  37. data/app/helpers/stripe_local/application_helper.rb +4 -0
  38. data/app/helpers/stripe_local/cards_helper.rb +4 -0
  39. data/app/helpers/stripe_local/charges_helper.rb +4 -0
  40. data/app/helpers/stripe_local/coupons_helper.rb +4 -0
  41. data/app/helpers/stripe_local/customers_helper.rb +4 -0
  42. data/app/helpers/stripe_local/discounts_helper.rb +4 -0
  43. data/app/helpers/stripe_local/invoices_helper.rb +4 -0
  44. data/app/helpers/stripe_local/line_items_helper.rb +4 -0
  45. data/app/helpers/stripe_local/plans_helper.rb +4 -0
  46. data/app/helpers/stripe_local/subscriptions_helper.rb +4 -0
  47. data/app/mixins/stripe_local/object_adapter.rb +33 -0
  48. data/app/mixins/stripe_local/sync_plans.rb +39 -0
  49. data/app/models/stripe_local/balance.rb +48 -0
  50. data/app/models/stripe_local/card.rb +39 -0
  51. data/app/models/stripe_local/charge.rb +63 -0
  52. data/app/models/stripe_local/coupon.rb +21 -0
  53. data/app/models/stripe_local/customer.rb +98 -0
  54. data/app/models/stripe_local/discount.rb +36 -0
  55. data/app/models/stripe_local/invoice.rb +68 -0
  56. data/app/models/stripe_local/line_item.rb +56 -0
  57. data/app/models/stripe_local/plan.rb +41 -0
  58. data/app/models/stripe_local/subscription.rb +50 -0
  59. data/app/models/stripe_local/transaction.rb +45 -0
  60. data/app/models/stripe_local/transfer.rb +48 -0
  61. data/app/validators/email_pattern_validator.rb +7 -0
  62. data/app/validators/full_name_pattern_validator.rb +7 -0
  63. data/app/validators/legal_name_pattern_validator.rb +7 -0
  64. data/app/validators/phone_pattern_validator.rb +17 -0
  65. data/app/validators/plan_id_pattern_validator.rb +7 -0
  66. data/app/validators/slug_pattern_validator.rb +38 -0
  67. data/app/validators/state_abbreviation_validator.rb +13 -0
  68. data/app/validators/stripe_type_validator.rb +7 -0
  69. data/app/validators/zip_type_validator.rb +8 -0
  70. data/app/views/layouts/stripe_local/application.html.erb +14 -0
  71. data/config/routes.rb +22 -0
  72. data/db/migrate/20131122063517_load_stripe_tables.rb +200 -0
  73. data/lib/stripe_local/engine.rb +7 -0
  74. data/lib/stripe_local/version.rb +3 -0
  75. data/lib/stripe_local/webhook/subscriber.rb +34 -0
  76. data/lib/stripe_local/webhook/types.rb +45 -0
  77. data/lib/stripe_local/webhook.rb +55 -0
  78. data/lib/stripe_local/webhooks.rb +20 -0
  79. data/lib/stripe_local.rb +48 -0
  80. data/lib/tasks/stripe_local_tasks.rake +4 -0
  81. data/spec/dummy/README.rdoc +28 -0
  82. data/spec/dummy/Rakefile +6 -0
  83. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  84. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  85. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  86. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  87. data/spec/dummy/app/models/client.rb +4 -0
  88. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  89. data/spec/dummy/bin/bundle +3 -0
  90. data/spec/dummy/bin/rails +4 -0
  91. data/spec/dummy/bin/rake +4 -0
  92. data/spec/dummy/config/application.rb +21 -0
  93. data/spec/dummy/config/boot.rb +5 -0
  94. data/spec/dummy/config/database.yml +17 -0
  95. data/spec/dummy/config/environment.rb +5 -0
  96. data/spec/dummy/config/environments/development.rb +29 -0
  97. data/spec/dummy/config/environments/production.rb +80 -0
  98. data/spec/dummy/config/environments/test.rb +36 -0
  99. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  100. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  101. data/spec/dummy/config/initializers/inflections.rb +16 -0
  102. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  103. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  104. data/spec/dummy/config/initializers/session_store.rb +3 -0
  105. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  106. data/spec/dummy/config/locales/en.yml +23 -0
  107. data/spec/dummy/config/routes.rb +4 -0
  108. data/spec/dummy/config.ru +4 -0
  109. data/spec/dummy/db/migrate/20131102200937_create_clients.rb +11 -0
  110. data/spec/dummy/db/migrate/20131122104223_add_stripe_customer_id_to_clients.rb +5 -0
  111. data/spec/dummy/db/schema.rb +236 -0
  112. data/spec/dummy/log/development.log +1290 -0
  113. data/spec/dummy/log/test.log +7041 -0
  114. data/spec/dummy/public/404.html +58 -0
  115. data/spec/dummy/public/422.html +58 -0
  116. data/spec/dummy/public/500.html +57 -0
  117. data/spec/dummy/public/favicon.ico +0 -0
  118. data/spec/dummy/spec/spec_helper.rb +42 -0
  119. data/spec/fixtures/client_params.json +18 -0
  120. data/spec/fixtures/credit_card.json +18 -0
  121. data/spec/fixtures/stripe_local/balance_transactions.yml +25 -0
  122. data/spec/fixtures/stripe_local/cards.yml +21 -0
  123. data/spec/fixtures/stripe_local/charges.yml +37 -0
  124. data/spec/fixtures/stripe_local/coupons.yml +23 -0
  125. data/spec/fixtures/stripe_local/customers.yml +21 -0
  126. data/spec/fixtures/stripe_local/discounts.yml +13 -0
  127. data/spec/fixtures/stripe_local/invoices.yml +37 -0
  128. data/spec/fixtures/stripe_local/line_items.yml +19 -0
  129. data/spec/fixtures/stripe_local/plans.yml +17 -0
  130. data/spec/fixtures/stripe_local/subscriptions.yml +25 -0
  131. data/spec/fixtures/stripe_local/transfers.yml +17 -0
  132. data/spec/models/stripe_local/balance_spec.rb +47 -0
  133. data/spec/models/stripe_local/card_spec.rb +13 -0
  134. data/spec/models/stripe_local/charge_spec.rb +13 -0
  135. data/spec/models/stripe_local/customer_spec.rb +17 -0
  136. data/spec/models/stripe_local/invoice_spec.rb +17 -0
  137. data/spec/models/stripe_local/plan_spec.rb +33 -0
  138. data/spec/models/stripe_local/subscription_spec.rb +15 -0
  139. data/spec/models/stripe_local/transaction_spec.rb +14 -0
  140. data/spec/models/stripe_local/transfer_spec.rb +13 -0
  141. data/spec/spec_helper.rb +19 -0
  142. data/spec/webhook_fixtures/balance_transaction.json +23 -0
  143. data/spec/webhook_fixtures/charge.succeeded.json +45 -0
  144. data/spec/webhook_fixtures/customer.created.json +41 -0
  145. data/spec/webhook_fixtures/customer.subscription.created.json +27 -0
  146. data/spec/webhook_fixtures/customer_creation_response.json +66 -0
  147. data/spec/webhook_fixtures/invoice.payment_succeeded.json +55 -0
  148. data/spec/webhook_fixtures/plan.created.json +12 -0
  149. data/spec/webhook_fixtures/transfer.json +32 -0
  150. metadata +403 -0
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeLocal::Subscription do
4
+ let(:response) { File.read("./spec/webhook_fixtures/customer.subscription.created.json") }
5
+ let(:subscription) { Stripe::StripeObject.construct_from(MultiJson.load(response)) }
6
+
7
+ it "can normalize attributes from Stripe on create" do
8
+ s = StripeLocal::Subscription.create( subscription )
9
+ s.plan_id.should eq "HR99"
10
+ s.customer_id.should eq "cus_2vIuZmAfWK89Yk"
11
+ s.status.should eq "active"
12
+ s.start.should eq "2013-11-11 15:32:46 -0600"
13
+ end
14
+
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeLocal::Transaction do
4
+ let(:response) { File.read("./spec/webhook_fixtures/balance_transaction.json") }
5
+ let(:transaction) { Stripe::StripeObject.construct_from(MultiJson.load(response)) }
6
+
7
+ it "can normalize attributes from Stripe on create" do
8
+ t = StripeLocal::Transaction.create( transaction )
9
+ t.source_type.should eq "transfer"
10
+ t.source_id.should eq "tr_2fOGfKABdHu3uf"
11
+ t.status.should eq "available"
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeLocal::Transfer do
4
+ let(:response) { File.read("./spec/webhook_fixtures/transfer.json") }
5
+ let(:transfer) { Stripe::StripeObject.construct_from(MultiJson.load(response)) }
6
+
7
+ it "can normalize a stripe transfer on create" do
8
+ t = StripeLocal::Transfer.create( transfer )
9
+ t.status.should eq "paid"
10
+ t.amount.should eq 100
11
+ t.id.should eq "tr_2fOGfKABdHu3uf"
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../spec/dummy/config/environment', __FILE__)
3
+ require 'rspec/rails'
4
+ require 'database_cleaner'
5
+
6
+ Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ config.order = 'random'
10
+
11
+ config.before(:suite) do
12
+ DatabaseCleaner.clean_with(:truncation)
13
+ run_dummy_app_migrations
14
+ end
15
+
16
+ def run_dummy_app_migrations
17
+ ActiveRecord::Migrator.migrate(Rails.root.join('db', 'migrate'))
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ {
2
+ "amount": -100,
3
+ "available_on": 1381140061,
4
+ "created": 1380535261,
5
+ "currency": "usd",
6
+ "description": "a dollar for Don Atello",
7
+ "fee": 25,
8
+ "fee_details": [
9
+ {
10
+ "amount": 25,
11
+ "application": null,
12
+ "currency": "usd",
13
+ "description": "Stripe processing fees",
14
+ "type": "stripe_fee"
15
+ }
16
+ ],
17
+ "id": "txn_2fOGkiBkDgpObU",
18
+ "net": -125,
19
+ "object": "balance_transaction",
20
+ "source": "tr_2fOGfKABdHu3uf",
21
+ "status": "available",
22
+ "type": "transfer"
23
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "amount": 9900,
3
+ "amount_refunded": 0,
4
+ "balance_transaction": "txn_2wiSFq1N6BTZTQ",
5
+ "captured": "true",
6
+ "card": {
7
+ "address_city": null,
8
+ "address_country": null,
9
+ "address_line1": null,
10
+ "address_line1_check": null,
11
+ "address_line2": null,
12
+ "address_state": null,
13
+ "address_zip": null,
14
+ "address_zip_check": null,
15
+ "country": "US",
16
+ "customer": "cus_1eX7onie2gq8m1",
17
+ "cvc_check": null,
18
+ "exp_month": 1,
19
+ "exp_year": 2016,
20
+ "fingerprint": "oIGflimx8B0svWgw",
21
+ "id": "cc_1eX7GyRo6wivEf",
22
+ "last4": "4242",
23
+ "name": "Jacob Johnson",
24
+ "object": "card",
25
+ "type": "Visa"
26
+ },
27
+ "created": 1375398494,
28
+ "currency": "usd",
29
+ "customer": "cus_1eX7onie2gq8m1",
30
+ "description": null,
31
+ "dispute": null,
32
+ "failure_code": null,
33
+ "failure_message": null,
34
+ "id": "ch_2wiSyZQkZw8F50",
35
+ "invoice": "in_2whTLSkV2ItHAv",
36
+ "livemode": "false",
37
+ "metadata": {
38
+ "desc": "a charge object",
39
+ "number": 1
40
+ },
41
+ "object": "charge",
42
+ "paid": "true",
43
+ "refunded": "false",
44
+ "refunds": []
45
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "account_balance": 0,
3
+ "cards": {
4
+ "count": 1,
5
+ "data": [
6
+ {
7
+ "address_city": null,
8
+ "address_country": null,
9
+ "address_line1": null,
10
+ "address_line1_check": null,
11
+ "address_line2": null,
12
+ "address_state": null,
13
+ "address_zip": null,
14
+ "address_zip_check": null,
15
+ "country": "US",
16
+ "customer": "cus_2J7PZ8ncCbR10Z",
17
+ "cvc_check": "pass",
18
+ "exp_month": 1,
19
+ "exp_year": 2014,
20
+ "fingerprint": "oIGflimx8B0svWgw",
21
+ "id": "cc_2J7Pscoh4jvFjJ",
22
+ "last4": "4242",
23
+ "name": "Connor Tumbleson",
24
+ "object": "card",
25
+ "type": "Visa"
26
+ }
27
+ ],
28
+ "object": "list",
29
+ "url": "/v1/customers/cus_2J7PZ8ncCbR10Z/cards"
30
+ },
31
+ "created": 1375398494,
32
+ "default_card": "cc_2J7Pscoh4jvFjJ",
33
+ "delinquent": "false",
34
+ "description": "Term: Thursday, August 1st, 2013 - Friday, August 1st, 2014",
35
+ "discount": null,
36
+ "email": "connor.tumbleson@gmail.com",
37
+ "id": "cus_2J7PZ8ncCbR10Z",
38
+ "livemode": "false",
39
+ "object": "customer",
40
+ "subscription": null
41
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "application_fee_percent": null,
3
+ "cancel_at_period_end": false,
4
+ "canceled_at": null,
5
+ "current_period_end": 1386797566,
6
+ "current_period_start": 1384205566,
7
+ "customer": "cus_2vIuZmAfWK89Yk",
8
+ "ended_at": null,
9
+ "id": "su_2vIueLAzHmGhRG",
10
+ "object": "subscription",
11
+ "plan": {
12
+ "amount": 9900,
13
+ "currency": "usd",
14
+ "id": "HR99",
15
+ "interval": "month",
16
+ "interval_count": 1,
17
+ "livemode": false,
18
+ "name": "HR Solutions On-Call",
19
+ "object": "plan",
20
+ "trial_period_days": null
21
+ },
22
+ "quantity": 1,
23
+ "start": 1384205566,
24
+ "status": "active",
25
+ "trial_end": null,
26
+ "trial_start": null
27
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "account_balance": 0,
3
+ "cards": {
4
+ "count": 1,
5
+ "data": [
6
+ {
7
+ "address_city": null,
8
+ "address_country": null,
9
+ "address_line1": null,
10
+ "address_line1_check": null,
11
+ "address_line2": null,
12
+ "address_state": null,
13
+ "address_zip": null,
14
+ "address_zip_check": null,
15
+ "country": "US",
16
+ "customer": "cus_123",
17
+ "cvc_check": "pass",
18
+ "exp_month": 8,
19
+ "exp_year": 2014,
20
+ "fingerprint": "Y7M2OsbpnbUz91ED",
21
+ "id": "card_102Y2J1Cmf55uWiejglofO7j",
22
+ "last4": "4242",
23
+ "name": "Test Case",
24
+ "object": "card",
25
+ "type": "Visa"
26
+ }
27
+ ],
28
+ "object": "list",
29
+ "url": "/v1/customers/cus_123/cards"
30
+ },
31
+ "created": 1378839122,
32
+ "default_card": "card_102Y2J1Cmf55uWiejglofO7j",
33
+ "delinquent": "false",
34
+ "description": "On September 10th, Test signed up for CA50.",
35
+ "discount": null,
36
+ "email": "test@test.com",
37
+ "id": "cus_123",
38
+ "livemode": "false",
39
+ "object": "customer",
40
+ "subscription": {
41
+ "cancel_at_period_end": "false",
42
+ "canceled_at": null,
43
+ "current_period_end": 1381431124,
44
+ "current_period_start": 1378839124,
45
+ "customer": "",
46
+ "ended_at": null,
47
+ "id": "su_102Y2J1Cmf55uWiekSeb7fb0",
48
+ "object": "subscription",
49
+ "plan": {
50
+ "amount": 4995,
51
+ "currency": "usd",
52
+ "id": "GIN100",
53
+ "interval": "month",
54
+ "interval_count": 1,
55
+ "livemode": "false",
56
+ "name": "Complyability",
57
+ "object": "plan",
58
+ "trial_period_days": null
59
+ },
60
+ "quantity": 1,
61
+ "start": 1378839124,
62
+ "status": "active",
63
+ "trial_end": null,
64
+ "trial_start": null
65
+ }
66
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "amount_due": 9900,
3
+ "attempt_count": 0,
4
+ "attempted": true,
5
+ "charge": "ch_blahblahblah",
6
+ "closed": true,
7
+ "currency": "usd",
8
+ "customer": "cus_1A3zUmx7NpUgrT",
9
+ "date": 1367969027,
10
+ "discount": null,
11
+ "ending_balance": 0,
12
+ "id": "in_2blahblahagain",
13
+ "lines": {
14
+ "count": 1,
15
+ "data": [
16
+ {
17
+ "amount": 9900,
18
+ "currency": "usd",
19
+ "description": null,
20
+ "id": "su_1bfTBoL3o7blah",
21
+ "livemode": false,
22
+ "object": "line_item",
23
+ "period": {
24
+ "end": 1370561027,
25
+ "start": 1367969027
26
+ },
27
+ "plan": {
28
+ "amount": 9900,
29
+ "currency": "usd",
30
+ "id": "HR99",
31
+ "interval": "month",
32
+ "interval_count": 1,
33
+ "livemode": false,
34
+ "name": "HR Solutions On-Call",
35
+ "object": "plan",
36
+ "trial_period_days": null
37
+ },
38
+ "proration": false,
39
+ "quantity": 1,
40
+ "type": "subscription"
41
+ }
42
+ ],
43
+ "object": "list",
44
+ "url": "/v1/invoices/in_2blahblahagain/lines"
45
+ },
46
+ "livemode": false,
47
+ "next_payment_attempt": null,
48
+ "object": "invoice",
49
+ "paid": true,
50
+ "period_end": 1367969027,
51
+ "period_start": 1367969027,
52
+ "starting_balance": 0,
53
+ "subtotal": 9900,
54
+ "total": 9900
55
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "amount": 9900,
3
+ "currency": "usd",
4
+ "id": "HR99",
5
+ "interval": "month",
6
+ "interval_count": 1,
7
+ "livemode": false,
8
+ "metadata": {},
9
+ "name": "HR Solutions On-Call",
10
+ "object": "plan",
11
+ "trial_period_days": null
12
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "account": {
3
+ "bank_name": "STRIPE TEST BANK",
4
+ "country": "US",
5
+ "currency": "usd",
6
+ "fingerprint": "Os7B4bbyVewMDVUT",
7
+ "id": "ba_2fOFGB7eur8QVV",
8
+ "last4": "6789",
9
+ "object": "bank_account",
10
+ "validated": "false",
11
+ "verified": "false"
12
+ },
13
+ "amount": 100,
14
+ "balance_transaction": "txn_2fOGkiBkDgpObU",
15
+ "currency": "usd",
16
+ "date": 1380535261,
17
+ "description": "a dollar for Don Atello",
18
+ "id": "tr_2fOGfKABdHu3uf",
19
+ "livemode": "false",
20
+ "metadata": {},
21
+ "object": "transfer",
22
+ "other_transfers": [
23
+ "tr_2fODmiKUnck7bj",
24
+ "tr_2fOGfKABdHu3uf",
25
+ "tr_2fOHVNt0wM8iIO",
26
+ "tr_2fOdARkVPa7l1Q",
27
+ "tr_2fOyxlx9hMcZGH"
28
+ ],
29
+ "recipient": "rp_2fOFKSa9bt2NNM",
30
+ "statement_descriptor": null,
31
+ "status": "paid"
32
+ }