effective_orders 4.0.0beta16 → 4.0.0beta17
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c31920616d5695fbd44ffee53ce1528e1e9f0826
|
4
|
+
data.tar.gz: 8aaa54b4c98ed47cf86a8502f7e697d0c4e3b1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d8e03922d776a594b302a0e5ffafcc7ffba9370d5bf8506af0e3411f2c39a073ec1731c0c6acc42459d295724d0d1b0a75cc0bb8f709c76e7fb11ecb2f2829
|
7
|
+
data.tar.gz: 88b80cc28b73baf51057c91c99d090c1d4fc8e4809632c35aa9132ab48edf8639ebe3faa303c6ec5b13d675b399c408c0fc71d383241c5c0e12a8d1610307bf4
|
data/README.md
CHANGED
@@ -588,6 +588,31 @@ Create a Product with the name you want customers to see on their receipts
|
|
588
588
|
Yearly and a Monthly per team
|
589
589
|
|
590
590
|
|
591
|
+
#### Callbacks
|
592
|
+
|
593
|
+
The event is the Stripe event JSON.
|
594
|
+
|
595
|
+
```ruby
|
596
|
+
after_invoice_payment_succeeded do |event|
|
597
|
+
end
|
598
|
+
|
599
|
+
after_invoice_payment_failed do |event|
|
600
|
+
end
|
601
|
+
|
602
|
+
after_customer_subscription_created do |event|
|
603
|
+
end
|
604
|
+
|
605
|
+
after_customer_subscription_updated do |event|
|
606
|
+
end
|
607
|
+
|
608
|
+
after_customer_subscription_deleted do |event|
|
609
|
+
end
|
610
|
+
|
611
|
+
after_customer_updated do |event|
|
612
|
+
end
|
613
|
+
```
|
614
|
+
|
615
|
+
|
591
616
|
### Admin Screen
|
592
617
|
|
593
618
|
To use the Admin screen, please also install the effective_datatables gem:
|
@@ -13,6 +13,8 @@ module Effective
|
|
13
13
|
protect_from_forgery except: [:stripe]
|
14
14
|
skip_authorization_check if defined?(CanCan)
|
15
15
|
|
16
|
+
after_action :run_subscribable_buyer_callbacks!
|
17
|
+
|
16
18
|
def stripe
|
17
19
|
@event = (Stripe::Webhook.construct_event(request.body.read, request.env['HTTP_STRIPE_SIGNATURE'], EffectiveOrders.subscriptions[:webhook_secret]) rescue nil)
|
18
20
|
(head(:bad_request) and return) unless @event
|
@@ -21,7 +23,7 @@ module Effective
|
|
21
23
|
(head(:bad_request) and return) if (params[:livemode] == false && Rails.env.production?)
|
22
24
|
end
|
23
25
|
|
24
|
-
Rails.logger.info "[STRIPE] webhook received: #{@event.type}"
|
26
|
+
Rails.logger.info "[STRIPE] webhook received: #{@event.type} for #{customer || 'unknown customer'}" # Customer must be called here
|
25
27
|
|
26
28
|
Effective::Customer.transaction do
|
27
29
|
case @event.type
|
@@ -66,12 +68,30 @@ module Effective
|
|
66
68
|
private
|
67
69
|
|
68
70
|
def customer
|
69
|
-
|
71
|
+
return unless @event.respond_to?(:data)
|
72
|
+
|
73
|
+
@customer ||= (
|
74
|
+
stripe_customer_id = @event.data.object.customer if @event.data.object.respond_to?(:customer)
|
75
|
+
stripe_customer_id = @event.data.object.id if @event.data.object.object == 'customer'
|
76
|
+
|
77
|
+
Effective::Customer.where(stripe_customer_id: stripe_customer_id || 'unknown').first!
|
78
|
+
)
|
70
79
|
end
|
71
80
|
|
72
81
|
def send_email(email, *mailer_args)
|
73
82
|
Effective::OrdersMailer.public_send(email, *mailer_args).public_send(EffectiveOrders.mailer[:deliver_method])
|
74
83
|
end
|
75
84
|
|
85
|
+
def run_subscribable_buyer_callbacks!
|
86
|
+
return if @event.blank? || @customer.blank?
|
87
|
+
|
88
|
+
name = ('after_' + @event.type.to_s.gsub('.', '_')).to_sym
|
89
|
+
buyer = @customer.user
|
90
|
+
|
91
|
+
buyer.public_send(name, @event) if buyer.respond_to?(name)
|
92
|
+
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
76
96
|
end
|
77
97
|
end
|
@@ -18,5 +18,32 @@ module ActsAsSubscribableBuyer
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
module ClassMethods
|
22
|
+
def after_invoice_payment_succeeded(&block)
|
23
|
+
send :define_method, :after_invoice_payment_succeeded do |event| self.instance_exec(event, &block) end
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_invoice_payment_failed(&block)
|
27
|
+
send :define_method, :after_invoice_payment_failed do |event| self.instance_exec(event, &block) end
|
28
|
+
end
|
29
|
+
|
30
|
+
def after_customer_subscription_created(&block)
|
31
|
+
send :define_method, :after_customer_subscription_created do |event| self.instance_exec(event, &block) end
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_customer_subscription_updated(&block)
|
35
|
+
send :define_method, :after_customer_subscription_updated do |event| self.instance_exec(event, &block) end
|
36
|
+
end
|
37
|
+
|
38
|
+
def after_customer_subscription_deleted(&block)
|
39
|
+
send :define_method, :after_customer_subscription_deleted do |event| self.instance_exec(event, &block) end
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_customer_updated(&block)
|
43
|
+
send :define_method, :after_customer_updated do |event| self.instance_exec(event, &block) end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
21
48
|
end
|
22
49
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.0beta17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|