stripe_local 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/stripe_local/application.js +13 -0
- data/app/assets/javascripts/stripe_local/cards.js +2 -0
- data/app/assets/javascripts/stripe_local/charges.js +2 -0
- data/app/assets/javascripts/stripe_local/coupons.js +2 -0
- data/app/assets/javascripts/stripe_local/customers.js +2 -0
- data/app/assets/javascripts/stripe_local/discounts.js +2 -0
- data/app/assets/javascripts/stripe_local/invoices.js +2 -0
- data/app/assets/javascripts/stripe_local/line_items.js +2 -0
- data/app/assets/javascripts/stripe_local/plans.js +2 -0
- data/app/assets/javascripts/stripe_local/subscriptions.js +2 -0
- data/app/assets/stylesheets/stripe_local/application.css +13 -0
- data/app/assets/stylesheets/stripe_local/cards.css +4 -0
- data/app/assets/stylesheets/stripe_local/charges.css +4 -0
- data/app/assets/stylesheets/stripe_local/coupons.css +4 -0
- data/app/assets/stylesheets/stripe_local/customers.css +4 -0
- data/app/assets/stylesheets/stripe_local/discounts.css +4 -0
- data/app/assets/stylesheets/stripe_local/invoices.css +4 -0
- data/app/assets/stylesheets/stripe_local/line_items.css +4 -0
- data/app/assets/stylesheets/stripe_local/plans.css +4 -0
- data/app/assets/stylesheets/stripe_local/subscriptions.css +4 -0
- data/app/callbacks/stripe_local/plan_sync.rb +33 -0
- data/app/controllers/stripe_local/application_controller.rb +4 -0
- data/app/controllers/stripe_local/cards_controller.rb +6 -0
- data/app/controllers/stripe_local/charges_controller.rb +6 -0
- data/app/controllers/stripe_local/coupons_controller.rb +6 -0
- data/app/controllers/stripe_local/customers_controller.rb +6 -0
- data/app/controllers/stripe_local/discounts_controller.rb +6 -0
- data/app/controllers/stripe_local/invoices_controller.rb +6 -0
- data/app/controllers/stripe_local/line_items_controller.rb +6 -0
- data/app/controllers/stripe_local/plans_controller.rb +6 -0
- data/app/controllers/stripe_local/subscriptions_controller.rb +6 -0
- data/app/controllers/stripe_local/webhooks_controller.rb +13 -0
- data/app/helpers/stripe_local/application_helper.rb +4 -0
- data/app/helpers/stripe_local/cards_helper.rb +4 -0
- data/app/helpers/stripe_local/charges_helper.rb +4 -0
- data/app/helpers/stripe_local/coupons_helper.rb +4 -0
- data/app/helpers/stripe_local/customers_helper.rb +4 -0
- data/app/helpers/stripe_local/discounts_helper.rb +4 -0
- data/app/helpers/stripe_local/invoices_helper.rb +4 -0
- data/app/helpers/stripe_local/line_items_helper.rb +4 -0
- data/app/helpers/stripe_local/plans_helper.rb +4 -0
- data/app/helpers/stripe_local/subscriptions_helper.rb +4 -0
- data/app/mixins/stripe_local/object_adapter.rb +33 -0
- data/app/mixins/stripe_local/sync_plans.rb +39 -0
- data/app/models/stripe_local/balance.rb +48 -0
- data/app/models/stripe_local/card.rb +39 -0
- data/app/models/stripe_local/charge.rb +63 -0
- data/app/models/stripe_local/coupon.rb +21 -0
- data/app/models/stripe_local/customer.rb +98 -0
- data/app/models/stripe_local/discount.rb +36 -0
- data/app/models/stripe_local/invoice.rb +68 -0
- data/app/models/stripe_local/line_item.rb +56 -0
- data/app/models/stripe_local/plan.rb +41 -0
- data/app/models/stripe_local/subscription.rb +50 -0
- data/app/models/stripe_local/transaction.rb +45 -0
- data/app/models/stripe_local/transfer.rb +48 -0
- data/app/validators/email_pattern_validator.rb +7 -0
- data/app/validators/full_name_pattern_validator.rb +7 -0
- data/app/validators/legal_name_pattern_validator.rb +7 -0
- data/app/validators/phone_pattern_validator.rb +17 -0
- data/app/validators/plan_id_pattern_validator.rb +7 -0
- data/app/validators/slug_pattern_validator.rb +38 -0
- data/app/validators/state_abbreviation_validator.rb +13 -0
- data/app/validators/stripe_type_validator.rb +7 -0
- data/app/validators/zip_type_validator.rb +8 -0
- data/app/views/layouts/stripe_local/application.html.erb +14 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20131122063517_load_stripe_tables.rb +200 -0
- data/lib/stripe_local/engine.rb +7 -0
- data/lib/stripe_local/version.rb +3 -0
- data/lib/stripe_local/webhook/subscriber.rb +34 -0
- data/lib/stripe_local/webhook/types.rb +45 -0
- data/lib/stripe_local/webhook.rb +55 -0
- data/lib/stripe_local/webhooks.rb +20 -0
- data/lib/stripe_local.rb +48 -0
- data/lib/tasks/stripe_local_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/client.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +21 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +17 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20131102200937_create_clients.rb +11 -0
- data/spec/dummy/db/migrate/20131122104223_add_stripe_customer_id_to_clients.rb +5 -0
- data/spec/dummy/db/schema.rb +236 -0
- data/spec/dummy/log/development.log +1290 -0
- data/spec/dummy/log/test.log +7041 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/spec_helper.rb +42 -0
- data/spec/fixtures/client_params.json +18 -0
- data/spec/fixtures/credit_card.json +18 -0
- data/spec/fixtures/stripe_local/balance_transactions.yml +25 -0
- data/spec/fixtures/stripe_local/cards.yml +21 -0
- data/spec/fixtures/stripe_local/charges.yml +37 -0
- data/spec/fixtures/stripe_local/coupons.yml +23 -0
- data/spec/fixtures/stripe_local/customers.yml +21 -0
- data/spec/fixtures/stripe_local/discounts.yml +13 -0
- data/spec/fixtures/stripe_local/invoices.yml +37 -0
- data/spec/fixtures/stripe_local/line_items.yml +19 -0
- data/spec/fixtures/stripe_local/plans.yml +17 -0
- data/spec/fixtures/stripe_local/subscriptions.yml +25 -0
- data/spec/fixtures/stripe_local/transfers.yml +17 -0
- data/spec/models/stripe_local/balance_spec.rb +47 -0
- data/spec/models/stripe_local/card_spec.rb +13 -0
- data/spec/models/stripe_local/charge_spec.rb +13 -0
- data/spec/models/stripe_local/customer_spec.rb +17 -0
- data/spec/models/stripe_local/invoice_spec.rb +17 -0
- data/spec/models/stripe_local/plan_spec.rb +33 -0
- data/spec/models/stripe_local/subscription_spec.rb +15 -0
- data/spec/models/stripe_local/transaction_spec.rb +14 -0
- data/spec/models/stripe_local/transfer_spec.rb +13 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/webhook_fixtures/balance_transaction.json +23 -0
- data/spec/webhook_fixtures/charge.succeeded.json +45 -0
- data/spec/webhook_fixtures/customer.created.json +41 -0
- data/spec/webhook_fixtures/customer.subscription.created.json +27 -0
- data/spec/webhook_fixtures/customer_creation_response.json +66 -0
- data/spec/webhook_fixtures/invoice.payment_succeeded.json +55 -0
- data/spec/webhook_fixtures/plan.created.json +12 -0
- data/spec/webhook_fixtures/transfer.json +32 -0
- metadata +403 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
class LoadStripeTables < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :stripe_local_customers, id: false do |t|
|
4
|
+
t.string :id, primary_key: true
|
5
|
+
t.integer :account_balance
|
6
|
+
t.string :default_card
|
7
|
+
t.boolean :delinquent
|
8
|
+
t.string :description
|
9
|
+
t.string :email
|
10
|
+
t.text :metadata
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
add_index :stripe_local_customers, :id, unique: true
|
15
|
+
|
16
|
+
create_table :stripe_local_cards, id: false do |t|
|
17
|
+
t.string :id, primary_key: true
|
18
|
+
t.string :customer_id
|
19
|
+
t.string :name
|
20
|
+
t.integer :exp_month
|
21
|
+
t.integer :exp_year
|
22
|
+
t.string :brand
|
23
|
+
t.string :last4
|
24
|
+
t.string :cvc_check
|
25
|
+
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
add_index :stripe_local_cards, :id, unique: true
|
29
|
+
add_index :stripe_local_cards, :customer_id
|
30
|
+
|
31
|
+
create_table :stripe_local_plans, id: false do |t|
|
32
|
+
t.string :id, primary_key: true
|
33
|
+
t.string :name
|
34
|
+
t.integer :amount
|
35
|
+
t.string :interval
|
36
|
+
t.integer :interval_count, default: 1
|
37
|
+
t.integer :trial_period_days, default: 0
|
38
|
+
t.string :currency, default: 'usd'
|
39
|
+
t.boolean :synced, default: false
|
40
|
+
|
41
|
+
t.timestamps
|
42
|
+
end
|
43
|
+
add_index :stripe_local_plans, :id, unique: true
|
44
|
+
|
45
|
+
create_table :stripe_local_coupons, id: false do |t|
|
46
|
+
t.string :id, primary_key: true
|
47
|
+
t.integer :percent_off
|
48
|
+
t.integer :amount_off
|
49
|
+
t.string :currency, default: 'usd'
|
50
|
+
t.string :duration
|
51
|
+
t.datetime :redeem_by
|
52
|
+
t.integer :max_redemptions
|
53
|
+
t.integer :times_redeemed, default: 0
|
54
|
+
t.integer :duration_in_months
|
55
|
+
t.boolean :synced, default: false
|
56
|
+
|
57
|
+
t.timestamps
|
58
|
+
end
|
59
|
+
add_index :stripe_local_coupons, :id, unique: true
|
60
|
+
|
61
|
+
create_table :stripe_local_discounts do |t|
|
62
|
+
t.string :coupon_id
|
63
|
+
t.string :subscription_id
|
64
|
+
t.datetime :start
|
65
|
+
t.datetime :end
|
66
|
+
|
67
|
+
t.timestamps
|
68
|
+
end
|
69
|
+
add_index :stripe_local_discounts, [ :coupon_id, :subscription_id ]
|
70
|
+
|
71
|
+
create_table :stripe_local_subscriptions do |t|
|
72
|
+
t.string :customer_id
|
73
|
+
t.string :plan_id
|
74
|
+
t.string :status
|
75
|
+
t.integer :quantity, default: 1
|
76
|
+
t.datetime :start
|
77
|
+
t.datetime :canceled_at
|
78
|
+
t.datetime :ended_at
|
79
|
+
t.datetime :current_period_start
|
80
|
+
t.datetime :current_period_end
|
81
|
+
t.datetime :trial_start
|
82
|
+
t.datetime :trial_end
|
83
|
+
|
84
|
+
t.timestamps
|
85
|
+
end
|
86
|
+
add_index :stripe_local_subscriptions, :customer_id
|
87
|
+
add_index :stripe_local_subscriptions, :plan_id
|
88
|
+
|
89
|
+
create_table :stripe_local_invoices, id: false do |t|
|
90
|
+
t.string :id, primary_key: true
|
91
|
+
t.string :customer_id
|
92
|
+
t.integer :amount_due
|
93
|
+
t.integer :subtotal
|
94
|
+
t.integer :total
|
95
|
+
t.boolean :attempted
|
96
|
+
t.integer :attempt_count
|
97
|
+
t.boolean :paid
|
98
|
+
t.boolean :closed
|
99
|
+
t.datetime :date
|
100
|
+
t.datetime :period_start
|
101
|
+
t.datetime :period_end
|
102
|
+
t.string :currency, default: 'usd'
|
103
|
+
t.integer :starting_balance
|
104
|
+
t.integer :ending_balance
|
105
|
+
t.string :charge_id
|
106
|
+
t.integer :discount, default: 0
|
107
|
+
t.integer :application_fee
|
108
|
+
t.datetime :next_payment_attempt
|
109
|
+
|
110
|
+
t.timestamps
|
111
|
+
end
|
112
|
+
add_index :stripe_local_invoices, :id, unique: true
|
113
|
+
add_index :stripe_local_invoices, :customer_id
|
114
|
+
|
115
|
+
create_table :stripe_local_line_items, id: false do |t|
|
116
|
+
t.string :id, primary_key: true
|
117
|
+
t.string :invoice_id
|
118
|
+
t.boolean :subscription, default: true
|
119
|
+
t.integer :amount
|
120
|
+
t.string :currency, default: 'usd'
|
121
|
+
t.boolean :proration, dafault: false
|
122
|
+
t.datetime :period_start
|
123
|
+
t.datetime :period_end
|
124
|
+
t.integer :quantity
|
125
|
+
t.string :plan_id
|
126
|
+
t.string :description
|
127
|
+
t.text :metadata
|
128
|
+
|
129
|
+
t.timestamps
|
130
|
+
end
|
131
|
+
add_index :stripe_local_line_items, :id, unique: true
|
132
|
+
add_index :stripe_local_line_items, :invoice_id
|
133
|
+
|
134
|
+
create_table :stripe_local_charges, id: false do |t|
|
135
|
+
t.string :id, primary_key: true
|
136
|
+
t.string :card_id
|
137
|
+
t.string :customer_id
|
138
|
+
t.string :invoice_id
|
139
|
+
t.string :transaction_id
|
140
|
+
t.integer :amount
|
141
|
+
t.boolean :captured, default: true
|
142
|
+
t.boolean :refunded, default: false
|
143
|
+
t.boolean :paid
|
144
|
+
t.datetime :created
|
145
|
+
t.string :currency, default: 'usd'
|
146
|
+
t.integer :amount_refunded, default: 0
|
147
|
+
t.string :description
|
148
|
+
t.string :failure_code
|
149
|
+
t.string :failure_message
|
150
|
+
t.text :metadata
|
151
|
+
|
152
|
+
t.timestamps
|
153
|
+
end
|
154
|
+
add_index :stripe_local_charges, :id, unique: true
|
155
|
+
add_index :stripe_local_charges, :card_id
|
156
|
+
add_index :stripe_local_charges, :customer_id
|
157
|
+
add_index :stripe_local_charges, :invoice_id
|
158
|
+
add_index :stripe_local_charges, :transaction_id
|
159
|
+
|
160
|
+
create_table :stripe_local_transfers, id: false do |t|
|
161
|
+
t.string :id, primary_key: true
|
162
|
+
t.integer :amount
|
163
|
+
t.datetime :date
|
164
|
+
t.string :status
|
165
|
+
t.string :transaction_id
|
166
|
+
t.string :description
|
167
|
+
t.text :metadata
|
168
|
+
|
169
|
+
t.timestamps
|
170
|
+
end
|
171
|
+
add_index :stripe_local_transfers, :id, unique: true
|
172
|
+
add_index :stripe_local_transfers, :status
|
173
|
+
add_index :stripe_local_transfers, :transaction_id
|
174
|
+
|
175
|
+
create_table :stripe_local_transactions, id: false do |t|
|
176
|
+
t.string :id, primary_key: true
|
177
|
+
t.integer :amount
|
178
|
+
t.datetime :available_on
|
179
|
+
t.datetime :created
|
180
|
+
t.integer :fee
|
181
|
+
t.integer :net
|
182
|
+
t.string :source_id
|
183
|
+
t.string :source_type
|
184
|
+
t.string :status
|
185
|
+
t.string :description
|
186
|
+
|
187
|
+
t.timestamps
|
188
|
+
end
|
189
|
+
add_index :stripe_local_transactions, :id, unique: true
|
190
|
+
add_index :stripe_local_transactions, :status
|
191
|
+
add_index :stripe_local_transactions, %i( source_id source_type ), name: 'index_transactions_on_source_id_and_source_type'
|
192
|
+
|
193
|
+
create_table :stripe_local_balances do |t|
|
194
|
+
t.integer :available
|
195
|
+
t.integer :pending
|
196
|
+
|
197
|
+
t.timestamps
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module StripeLocal
|
2
|
+
module Webhook
|
3
|
+
|
4
|
+
#
|
5
|
+
# basically taken straight from the StripeEvents gem
|
6
|
+
# https://github.com/integrallis/stripe_event
|
7
|
+
#
|
8
|
+
#
|
9
|
+
class Subscriber
|
10
|
+
def initialize *names, &block
|
11
|
+
@names = names
|
12
|
+
@block = block
|
13
|
+
ensure_valid_types!
|
14
|
+
end
|
15
|
+
|
16
|
+
def register
|
17
|
+
ActiveSupport::Notifications.subscribe(pattern) do |_, _, _, _, payload|
|
18
|
+
@block.call payload[:event]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def pattern
|
25
|
+
Regexp.union(@names.empty? ? TYPE_LIST : @names)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ensure_valid_types!
|
29
|
+
invalid_names = @names.select { |name| !TYPE_LIST.include?(name) }
|
30
|
+
raise InvalidEventType.new(invalid_names) if invalid_names.any?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module StripeLocal
|
2
|
+
module Webhook
|
3
|
+
InvalidEventType = Class.new(StandardError)
|
4
|
+
|
5
|
+
TYPE_LIST = [
|
6
|
+
'account.updated',
|
7
|
+
'account.application.deauthorized',
|
8
|
+
'charge.succeeded',
|
9
|
+
'charge.failed',
|
10
|
+
'charge.refunded',
|
11
|
+
'charge.dispute.created',
|
12
|
+
'charge.dispute.updated',
|
13
|
+
'charge.dispute.closed',
|
14
|
+
'customer.created',
|
15
|
+
'customer.updated',
|
16
|
+
'customer.deleted',
|
17
|
+
'customer.subscription.created',
|
18
|
+
'customer.subscription.updated',
|
19
|
+
'customer.subscription.deleted',
|
20
|
+
'customer.subscription.trial_will_end',
|
21
|
+
'customer.discount.created',
|
22
|
+
'customer.discount.updated',
|
23
|
+
'customer.discount.deleted',
|
24
|
+
'invoice.created',
|
25
|
+
'invoice.updated',
|
26
|
+
'invoice.payment_succeeded',
|
27
|
+
'invoice.payment_failed',
|
28
|
+
'invoiceitem.created',
|
29
|
+
'invoiceitem.updated',
|
30
|
+
'invoiceitem.deleted',
|
31
|
+
'plan.created',
|
32
|
+
'plan.updated',
|
33
|
+
'plan.deleted',
|
34
|
+
'coupon.created',
|
35
|
+
'coupon.updated',
|
36
|
+
'coupon.deleted',
|
37
|
+
'transfer.created',
|
38
|
+
'transfer.paid',
|
39
|
+
'transfer.updated',
|
40
|
+
'transfer.failed',
|
41
|
+
'balance.available',
|
42
|
+
'ping'
|
43
|
+
]
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "stripe"
|
2
|
+
require_relative "./webhook/subscriber"
|
3
|
+
require_relative "./webhook/types"
|
4
|
+
|
5
|
+
module StripeLocal
|
6
|
+
|
7
|
+
#
|
8
|
+
# basically taken straight from the StripeEvents gem
|
9
|
+
# https://github.com/integrallis/stripe_event
|
10
|
+
#
|
11
|
+
#
|
12
|
+
module Webhook
|
13
|
+
class << self
|
14
|
+
alias :setup :instance_eval
|
15
|
+
|
16
|
+
def publish event_obj
|
17
|
+
ActiveSupport::Notifications.instrument event_obj.type, event: event_obj
|
18
|
+
end
|
19
|
+
|
20
|
+
def subscribe *names, &block
|
21
|
+
Subscriber.new(*names, &block).register
|
22
|
+
end
|
23
|
+
|
24
|
+
def subscribers name
|
25
|
+
ActiveSupport::Notifications.notifier.listeners_for name
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear_subscribers!
|
29
|
+
TYPE_LIST.each do |type|
|
30
|
+
subscribers(type).each { |s| unsubscribe(s) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def unsubscribe subscriber
|
35
|
+
ActiveSupport::Notifications.notifier.unsubscribe subscriber
|
36
|
+
end
|
37
|
+
|
38
|
+
def translate object, action, event
|
39
|
+
klass = object.camelize.constantize
|
40
|
+
klass.send action, event
|
41
|
+
end
|
42
|
+
|
43
|
+
def dispatch event
|
44
|
+
object,action,sub_action = event.type.split('.')
|
45
|
+
unless sub_action.nil?
|
46
|
+
object = [object,action].join('_')
|
47
|
+
action = sub_action
|
48
|
+
end
|
49
|
+
translate object, action, event
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
require_relative "./webhooks"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
StripeLocal::Webhook.subscribe do |event|
|
2
|
+
Prowly.notify do |n|
|
3
|
+
n.apikey = '2c6f33b43638a402c4c5b1872d4c974127971a5f'
|
4
|
+
n.application = 'StripeLocal'
|
5
|
+
n.event = event.type
|
6
|
+
n.description = event
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
StripeLocal::Webhook.setup do
|
11
|
+
subscribe( 'charge.succeeded' ) { |event| StripeLocal::Charge.create event.data.object }
|
12
|
+
subscribe( 'charge.failed' ) { |event| StripeLocal::Charge.create event.data.object }
|
13
|
+
subscribe( 'invoice.created' ) { |event| StripeLocal::Invoice.create event.data.object }
|
14
|
+
subscribe( 'invoice.payment_succeeded' ) { |event| StripeLocal::Invoice.succeed event.data.object }
|
15
|
+
subscribe( 'invoice.payment_failed' ) { |event| StripeLocal::Invoice.fail event.data.object }
|
16
|
+
subscribe( 'plan.created' ) { |event| StripeLocal::Plan.create event.data.object }
|
17
|
+
subscribe( 'plan.deleted' ) { |event| StripeLocal::Plan.delete event.data.object.id, false }
|
18
|
+
subscribe( 'coupon.created' ) { |event| event.data.object } #TODO: need to implement this
|
19
|
+
subscribe( 'coupon.deleted' ) { |event| event.data.object } #TODO: need to implement this
|
20
|
+
end
|
data/lib/stripe_local.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "stripe_local/engine"
|
2
|
+
require "stripe_local/webhook"
|
3
|
+
|
4
|
+
module StripeLocal
|
5
|
+
|
6
|
+
mattr_accessor :model_class
|
7
|
+
|
8
|
+
def stripe_customer
|
9
|
+
StripeLocal::model_class = self
|
10
|
+
belongs_to :customer, inverse_of: :model, foreign_key: :stripe_customer_id, class_name: 'StripeLocal::Customer'
|
11
|
+
setup_delegate
|
12
|
+
include InstanceMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
module InstanceMethods
|
16
|
+
|
17
|
+
# for argument details, see StripeLocal::Customer#signup definition
|
18
|
+
def signup params
|
19
|
+
stripe_customer_id = StripeLocal::Customer.signup(params)
|
20
|
+
save
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def setup_delegate
|
27
|
+
class_eval <<-DEF
|
28
|
+
def method_missing method, *args, &block
|
29
|
+
if self.customer && self.customer.respond_to?( method )
|
30
|
+
self.customer.send method, *args, &block
|
31
|
+
else
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def respond_to_missing? method, include_private = false
|
37
|
+
super unless self.customer && self.customer.respond_to?( method )
|
38
|
+
end
|
39
|
+
|
40
|
+
def respond_to? method, include_private = false
|
41
|
+
super unless self.customer && self.customer.respond_to?( method )
|
42
|
+
end
|
43
|
+
DEF
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
ActiveRecord::Base.extend StripeLocal
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "stripe_local"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# config.active_record.observers = %i( plan_observer coupon_observer )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
development: &base
|
2
|
+
adapter: postgresql
|
3
|
+
encoding: unicode
|
4
|
+
database: dummy_development
|
5
|
+
pool: 5
|
6
|
+
username: Outlawandy
|
7
|
+
password:
|
8
|
+
|
9
|
+
test:
|
10
|
+
<<: *base
|
11
|
+
database: dummy_test
|
12
|
+
|
13
|
+
production:
|
14
|
+
<<: *base
|
15
|
+
database: dummy_production
|
16
|
+
username: dummy
|
17
|
+
pool: 25
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
end
|