wbase 0.3.16 → 0.3.17
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: f737866525a133d24be7dff57cfcab0dfad3a26c
|
4
|
+
data.tar.gz: 5ca0572e21ba92771724c9b5b6004578f3ce95cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70bc1dbff42bb371870d8faf6cf129da803fa510800d3aebb74b738db74c2190e79fdcb0ae5d45312a47765f53c3ee12f310f8cce35bc9e4222a2fd4b37e4a94
|
7
|
+
data.tar.gz: f48825e24bd5cc67d283859040ffc7a152fd190c81ce11fb572dabaa887ef8b292c02d637f8d4fb9cec8e9033b6d44f7aeb2ff06f6683aa1839ea960a66a8aa2
|
@@ -33,6 +33,15 @@ module Wbase
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def update
|
37
|
+
service = UpdateSubscription.new(current_user, subscription_params)
|
38
|
+
service.call
|
39
|
+
if !service.valid?
|
40
|
+
flash[:errors] = service.errors
|
41
|
+
end
|
42
|
+
redirect_to '/user'
|
43
|
+
end
|
44
|
+
|
36
45
|
private
|
37
46
|
|
38
47
|
def subscription_params
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Wbase
|
2
|
+
class UpdateSubscription
|
3
|
+
attr_reader :subscription, :user, :errors, :params
|
4
|
+
|
5
|
+
def initialize(user, params)
|
6
|
+
@params = params
|
7
|
+
@user = user
|
8
|
+
@errors = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def subscription
|
12
|
+
user.subscription
|
13
|
+
end
|
14
|
+
|
15
|
+
def stripe_customer
|
16
|
+
@stripe_customer ||= subscription.stripe_customer
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
Rails.logger.info("Updating Stripe Customer for #{ user.email }")
|
21
|
+
card = stripe_customer.sources.create(card: params[:credit_card_token])
|
22
|
+
card.save
|
23
|
+
stripe_customer.default_source = card.id
|
24
|
+
stripe_customer.save
|
25
|
+
subscription.update!(params)
|
26
|
+
Rails.logger.info stripe_customer
|
27
|
+
rescue Stripe::CardError => e
|
28
|
+
# Since it's a decline, Stripe::CardError will be caught
|
29
|
+
body = e.json_body
|
30
|
+
err = body[:error]
|
31
|
+
@errors << body[:error]
|
32
|
+
puts "Status is: #{e.http_status}"
|
33
|
+
puts "Type is: #{err[:type]}"
|
34
|
+
puts "Code is: #{err[:code]}"
|
35
|
+
# param is '' in this case
|
36
|
+
puts "Param is: #{err[:param]}"
|
37
|
+
puts "Message is: #{err[:message]}"
|
38
|
+
rescue Stripe::InvalidRequestError => e
|
39
|
+
Rails.logger.error "Stripe error while updating card: #{ e.message }"
|
40
|
+
@errors << e.message
|
41
|
+
end
|
42
|
+
|
43
|
+
def valid?
|
44
|
+
errors.empty?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,2 +1,92 @@
|
|
1
|
-
<
|
2
|
-
<
|
1
|
+
<div class="panel-heading">
|
2
|
+
<h3 class="text-center">
|
3
|
+
Current Plan: <strong><%= current_user.get_selected_plan.name %></strong>
|
4
|
+
</h3>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<p class="text-center">
|
8
|
+
<%= number_to_currency(current_user.get_selected_plan.price) %> / <small>month</small>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<!-- <p class="text-center"> -->
|
12
|
+
<!-- <%= link_to "See other plans", "/welcome#pricing-section" %> -->
|
13
|
+
<!-- </p> -->
|
14
|
+
|
15
|
+
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
|
16
|
+
<script type="text/javascript">
|
17
|
+
Stripe.setPublishableKey('<%= ENV["STRIPE_PUBLISHABLE_KEY"] %>');
|
18
|
+
</script>
|
19
|
+
|
20
|
+
<form action="/subscription" method="POST" id="payment-form">
|
21
|
+
<input type="hidden" name="_method" value="PATCH">
|
22
|
+
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
|
23
|
+
<input type="hidden" name="subscription[plan_id]" value="<%= current_user.get_selected_plan.id %>">
|
24
|
+
<span class="payment-errors"></span>
|
25
|
+
|
26
|
+
<div class="form-group">
|
27
|
+
<label for="card-number" class="control-label">Card Number</label>
|
28
|
+
<input id="card-number" type="text" size="20" data-stripe="number" class="form-control boxed" autofocus>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div class="row form-group">
|
32
|
+
<div class="col-xs-6">
|
33
|
+
<label for="exp_month">Exp (MM / YY)</label>
|
34
|
+
</div>
|
35
|
+
<div class="col-xs-4 col-xs-offset-2">
|
36
|
+
<label for="cvc">CVC</label>
|
37
|
+
</div>
|
38
|
+
<div class="col-xs-3">
|
39
|
+
<input id="exp_month" type="text" size="2" data-stripe="exp_month" class="form-control boxed" placeholder="MM">
|
40
|
+
</div>
|
41
|
+
<div class="col-xs-3">
|
42
|
+
<input type="text" size="2" data-stripe="exp_year" class="form-control boxed" placeholder="YY">
|
43
|
+
</div>
|
44
|
+
<div class="col-xs-4 col-xs-offset-2">
|
45
|
+
<input id="cvc" type="text" size="4" data-stripe="cvc" class="form-control boxed" placeholder="CVC">
|
46
|
+
</div>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<input type="submit" class="submit btn btn-block btn-primary" value="Update!">
|
50
|
+
<hr>
|
51
|
+
|
52
|
+
<div class="form-group">
|
53
|
+
<p class="text-muted text-center"><a href="/user">Nevermind...</a></p>
|
54
|
+
</div>
|
55
|
+
</form>
|
56
|
+
|
57
|
+
<% content_for :javascripts do %>
|
58
|
+
<script type="text/javascript">
|
59
|
+
function stripeResponseHandler(status, response) {
|
60
|
+
// Grab the form:
|
61
|
+
var $form = $('#payment-form');
|
62
|
+
|
63
|
+
if (response.error) { // Problem!
|
64
|
+
// Show the errors on the form:
|
65
|
+
$form.find('.payment-errors').text(response.error.message);
|
66
|
+
$form.find('.submit').prop('disabled', false); // Re-enable submission
|
67
|
+
} else { // Token was created!
|
68
|
+
// Get the token ID:
|
69
|
+
var token = response.id,
|
70
|
+
lastFour = response.card.last4,
|
71
|
+
cardType = response.card.brand;
|
72
|
+
// Insert the token ID into the form so it gets submitted to the server:
|
73
|
+
$form.append($('<input type="hidden" name="subscription[credit_card_token]">').val(token));
|
74
|
+
$form.append($('<input type="hidden" name="subscription[last_four]">').val(lastFour));
|
75
|
+
$form.append($('<input type="hidden" name="subscription[card_type]">').val(cardType));
|
76
|
+
// Submit the form:
|
77
|
+
$form.get(0).submit();
|
78
|
+
}
|
79
|
+
};
|
80
|
+
$(function() {
|
81
|
+
var $form = $('#payment-form');
|
82
|
+
$form.submit(function(event) {
|
83
|
+
// Disable the submit button to prevent repeated clicks:
|
84
|
+
$form.find('.submit').prop('disabled', true);
|
85
|
+
// Request a token from Stripe:
|
86
|
+
Stripe.card.createToken($form, stripeResponseHandler);
|
87
|
+
// Prevent the form from being submitted:
|
88
|
+
return false;
|
89
|
+
});
|
90
|
+
});
|
91
|
+
</script>
|
92
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -20,7 +20,7 @@ Wbase::Engine.routes.draw do
|
|
20
20
|
resource :session, only: [:new, :create, :destroy]
|
21
21
|
get '/session', to: 'sessions#new'
|
22
22
|
resource :password_reset, only: [:new, :create, :edit, :update]
|
23
|
-
resource :subscription, only: [:new, :create]
|
23
|
+
resource :subscription, only: [:new, :create, :update, :edit]
|
24
24
|
resources :mail_events
|
25
25
|
resources :stripe_webhooks
|
26
26
|
get '/.well-known/acme-challenge/:id' => 'static_pages#letsencrypt'
|
data/lib/wbase/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CJ Avilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -300,6 +300,7 @@ files:
|
|
300
300
|
- app/models/wbase/userable.rb
|
301
301
|
- app/services/wbase/mail_event_batch.rb
|
302
302
|
- app/services/wbase/start_subscription.rb
|
303
|
+
- app/services/wbase/update_subscription.rb
|
303
304
|
- app/views/layouts/mailer.html.erb
|
304
305
|
- app/views/layouts/mailer.text.erb
|
305
306
|
- app/views/layouts/wbase/_common_foot.html.erb
|
@@ -1171,7 +1172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1171
1172
|
version: '0'
|
1172
1173
|
requirements: []
|
1173
1174
|
rubyforge_project:
|
1174
|
-
rubygems_version: 2.6.
|
1175
|
+
rubygems_version: 2.6.11
|
1175
1176
|
signing_key:
|
1176
1177
|
specification_version: 4
|
1177
1178
|
summary: Base for SAAS Apps
|