pay 1.0.0.rc3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pay might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/app/controllers/pay/webhooks/braintree_controller.rb +9 -9
- data/app/models/pay/charge.rb +12 -0
- data/config/routes.rb +5 -3
- data/lib/pay.rb +6 -0
- data/lib/pay/engine.rb +22 -1
- data/lib/pay/version.rb +1 -1
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1379b5a5fc93c593764ac038baee7860777e332bf0eb38fb5084a0610a4eea9
|
4
|
+
data.tar.gz: 1eaa3e6cde35255ce8f52cecce8baea3929bebd26866aad652a112eb23993494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633fc15ad852abb42240be46dd842190ae8de87b8a8907435004851a13912ad8c71ea4fb5fe3444d85c813c08171875bcae43aaf85a567b9c6b66823143deea6
|
7
|
+
data.tar.gz: f75e3bd6a55de8f98e879c3a5a02413a8796d747e98184ac524d914aa5cc90343e6e3cc48a3f86820af3f195d448954814917eda0bdc45d246995b55f7cb5275
|
data/README.md
CHANGED
@@ -135,6 +135,9 @@ Pay.setup do |config|
|
|
135
135
|
config.support_email = "helpme@example.com"
|
136
136
|
|
137
137
|
config.send_emails = true
|
138
|
+
|
139
|
+
config.automount_webhook_routes = true
|
140
|
+
config.webhooks_path = "/webhooks" # Only when automount_webhook_routes is true
|
138
141
|
end
|
139
142
|
```
|
140
143
|
|
@@ -427,6 +430,30 @@ Rails.application.config.to_prepare do
|
|
427
430
|
end
|
428
431
|
```
|
429
432
|
|
433
|
+
## Webhooks
|
434
|
+
|
435
|
+
Webhooks are automatically mounted to `/webhooks/{provider}`.
|
436
|
+
|
437
|
+
#### Customizing webhook mount path
|
438
|
+
|
439
|
+
If you have a catch all route (for 404s etc) and need to control where/when the webhook endpoints mount, you will need to disable automatic mounting and mount the engine above your catch all route.
|
440
|
+
|
441
|
+
```ruby
|
442
|
+
# config/initializers/pay.rb
|
443
|
+
config.automount_webhook_routes = false
|
444
|
+
|
445
|
+
# config/routes.rb
|
446
|
+
mount Pay::Engine, at: '/secret-webhook-path'
|
447
|
+
```
|
448
|
+
|
449
|
+
If you just want to modify where the engine mounts it's routes then you can change the path.
|
450
|
+
|
451
|
+
```ruby
|
452
|
+
# config/initializers/pay.rb
|
453
|
+
|
454
|
+
config.webhooks_path = '/secret-webhook-path'
|
455
|
+
```
|
456
|
+
|
430
457
|
## Contributors
|
431
458
|
|
432
459
|
- [Jason Charnes](https://twitter.com/jmcharnes)
|
@@ -6,15 +6,15 @@ module Pay
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def create
|
9
|
-
case
|
10
|
-
when
|
11
|
-
subscription_charged_successfully(
|
12
|
-
when
|
13
|
-
subscription_canceled(
|
9
|
+
case webhook_notification.kind
|
10
|
+
when 'subscription_charged_successfully'
|
11
|
+
subscription_charged_successfully(webhook_notification)
|
12
|
+
when 'subscription_canceled'
|
13
|
+
subscription_canceled(webhook_notification)
|
14
14
|
end
|
15
15
|
|
16
|
-
render json: {success: true}
|
17
|
-
rescue Braintree::InvalidSignature => e
|
16
|
+
render json: { success: true }, status: :ok
|
17
|
+
rescue ::Braintree::InvalidSignature => e
|
18
18
|
head :ok
|
19
19
|
end
|
20
20
|
|
@@ -45,8 +45,8 @@ module Pay
|
|
45
45
|
user.update(braintree_subscription_id: nil)
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
@webhook_notification ||= Braintree::WebhookNotification.parse(
|
48
|
+
def webhook_notification
|
49
|
+
@webhook_notification ||= ::Braintree::WebhookNotification.parse(
|
50
50
|
params[:bt_signature],
|
51
51
|
params[:bt_payload]
|
52
52
|
)
|
data/app/models/pay/charge.rb
CHANGED
@@ -27,5 +27,17 @@ module Pay
|
|
27
27
|
def charged_to
|
28
28
|
"#{card_type} (**** **** **** #{card_last4})"
|
29
29
|
end
|
30
|
+
|
31
|
+
def stripe?
|
32
|
+
processor == "stripe"
|
33
|
+
end
|
34
|
+
|
35
|
+
def braintree?
|
36
|
+
processor == "braintree"
|
37
|
+
end
|
38
|
+
|
39
|
+
def paypal?
|
40
|
+
braintree? && card_type == "PayPal"
|
41
|
+
end
|
30
42
|
end
|
31
43
|
end
|
data/config/routes.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Pay::Engine.routes.draw do
|
4
|
+
post 'stripe', to: 'stripe_event/webhook#event'
|
5
|
+
post 'braintree', to: 'pay/webhooks/braintree#create'
|
4
6
|
end
|
data/lib/pay.rb
CHANGED
@@ -38,6 +38,12 @@ module Pay
|
|
38
38
|
mattr_accessor :email_renewing_subject
|
39
39
|
@@email_renewing_subject = 'Your upcoming subscription renewal'
|
40
40
|
|
41
|
+
mattr_accessor :automount_webhook_routes
|
42
|
+
@@automount_webhook_routes = true
|
43
|
+
|
44
|
+
mattr_accessor :webhooks_path
|
45
|
+
@@webhooks_path = '/webhooks'
|
46
|
+
|
41
47
|
def self.setup
|
42
48
|
yield self
|
43
49
|
end
|
data/lib/pay/engine.rb
CHANGED
@@ -1,11 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Lint/HandleExceptions
|
4
|
+
begin
|
5
|
+
require 'braintree'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'stripe'
|
11
|
+
require 'stripe_event'
|
12
|
+
rescue LoadError
|
13
|
+
end
|
14
|
+
# rubocop:enable Lint/HandleExceptions
|
15
|
+
|
1
16
|
module Pay
|
2
17
|
class Engine < ::Rails::Engine
|
3
18
|
engine_name 'pay'
|
4
19
|
|
5
|
-
initializer 'pay.processors' do
|
20
|
+
initializer 'pay.processors' do |app|
|
6
21
|
# Include processor backends
|
7
22
|
require 'pay/stripe' if defined? ::Stripe
|
8
23
|
require 'pay/braintree' if defined? ::Braintree
|
24
|
+
|
25
|
+
if Pay.automount_webhook_routes
|
26
|
+
app.routes.append do
|
27
|
+
mount Pay::Engine, at: Pay.webhooks_path, as: 'pay'
|
28
|
+
end
|
29
|
+
end
|
9
30
|
end
|
10
31
|
|
11
32
|
config.to_prepare do
|
data/lib/pay/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Charnes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -121,6 +121,20 @@ dependencies:
|
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: minitest-rails
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '3'
|
131
|
+
type: :development
|
132
|
+
prerelease: false
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3'
|
124
138
|
- !ruby/object:Gem::Dependency
|
125
139
|
name: mocha
|
126
140
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,6 +163,20 @@ dependencies:
|
|
149
163
|
- - ">="
|
150
164
|
- !ruby/object:Gem::Version
|
151
165
|
version: '0'
|
166
|
+
- !ruby/object:Gem::Dependency
|
167
|
+
name: rubocop
|
168
|
+
requirement: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0.7'
|
173
|
+
type: :development
|
174
|
+
prerelease: false
|
175
|
+
version_requirements: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0.7'
|
152
180
|
- !ruby/object:Gem::Dependency
|
153
181
|
name: sqlite3
|
154
182
|
requirement: !ruby/object:Gem::Requirement
|
@@ -278,9 +306,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
278
306
|
version: '0'
|
279
307
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
308
|
requirements:
|
281
|
-
- - "
|
309
|
+
- - ">="
|
282
310
|
- !ruby/object:Gem::Version
|
283
|
-
version:
|
311
|
+
version: '0'
|
284
312
|
requirements: []
|
285
313
|
rubygems_version: 3.0.3
|
286
314
|
signing_key:
|