summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/views/layouts/_navigation.html.haml4
-rw-r--r--config/locales/cs.yml1
-rw-r--r--config/locales/de.yml1
-rw-r--r--config/locales/en/footer.en.yml1
-rw-r--r--config/locales/en/users.en.yml2
-rw-r--r--config/locales/es.yml5
-rw-r--r--config/locales/fr.yml1
-rw-r--r--config/locales/it.yml3
-rw-r--r--config/locales/pt.yml1
-rw-r--r--engines/billing/:w99
-rw-r--r--engines/billing/app/controllers/payments_controller.rb10
-rw-r--r--engines/billing/app/controllers/subscriptions_controller.rb105
-rw-r--r--engines/billing/app/views/payments/_customer_form.html.haml10
-rw-r--r--engines/billing/app/views/payments/_form.html.erb16
-rw-r--r--engines/billing/app/views/payments/default.html.erb27
-rw-r--r--engines/billing/app/views/payments/new.html.erb31
-rw-r--r--engines/billing/app/views/payments/new.html.haml21
-rw-r--r--engines/billing/app/views/subscriptions/_customer_form.html.erb (renamed from engines/billing/app/views/payments/_customer_form.html.erb)0
-rw-r--r--engines/billing/app/views/subscriptions/new.html.erb35
-rw-r--r--engines/billing/app/views/subscriptions/new.html.haml15
-rw-r--r--engines/billing/config/locales/en.yml6
21 files changed, 303 insertions, 91 deletions
diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml
index dccba0c..0b81831 100644
--- a/app/views/layouts/_navigation.html.haml
+++ b/app/views/layouts/_navigation.html.haml
@@ -7,6 +7,8 @@
= link_to_navigation ".tickets", auto_tickets_path,
active: controller?(:tickets)
- if APP_CONFIG[:billing]
+ = link_to_navigation :donations, new_payment_path,
+ active: (controller?(:payments) and action?(:new))
= link_to_navigation :billing_settings, billing_top_link(@user),
- active: controller?(:customer, :payments, :subscriptions, :credit_card_info)
+ active: controller?(:subscriptions)
= link_to_navigation :logout, logout_path, method: :delete
diff --git a/config/locales/cs.yml b/config/locales/cs.yml
index 08e1321..32b0f03 100644
--- a/config/locales/cs.yml
+++ b/config/locales/cs.yml
@@ -23,6 +23,7 @@ cs:
pricing: Stanovéní cen
about: O nás
contact: Kontakt
+ donations: Donations
signup: Registrovat
login: Přihlásit
logout: Odhlásit
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 76ecc1d..1f78b88 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -23,6 +23,7 @@ de:
pricing: Kosten
about: über uns
contact: Kontakt
+ donations: Spende
signup: Registrieren
login: Anmelden
logout: Abmelden
diff --git a/config/locales/en/footer.en.yml b/config/locales/en/footer.en.yml
index 65f8ab2..7569070 100644
--- a/config/locales/en/footer.en.yml
+++ b/config/locales/en/footer.en.yml
@@ -5,3 +5,4 @@ en:
pricing: Pricing
about: About Us
contact: Contact
+ donations: Donations
diff --git a/config/locales/en/users.en.yml b/config/locales/en/users.en.yml
index 4c6bbc0..543b511 100644
--- a/config/locales/en/users.en.yml
+++ b/config/locales/en/users.en.yml
@@ -5,6 +5,8 @@ en:
identities: "Usernames"
tickets: "Tickets"
user_control_panel: "user control panel"
+ donations: "Donations"
+ billing_settings: "Billing Settings"
account_settings: "Account Settings"
username: "Username"
password: "Password"
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 2a36b6e..0a29604 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -23,6 +23,8 @@ es:
pricing: Tarifas
about: Sobre nosotros
contact: Contacto
+ donations: Donaciones
+ billing_settings: Configuración de cuenta
signup: Registrarse
login: Iniciar sesión
logout: Cerrar sesión
@@ -120,6 +122,9 @@ es:
description: Descripción
cost: Coste
free: Gratuito
+ new_donation: "Nueva Donación"
+ donation_info: "Por favor, llena los detalles de tu donación (esta no será cargada a tu cuenta, si tienes una):"
+ personal_info: "Por favor, ingresa tu información personal"
support_tickets: Soporte
email_notice_text: Ha sido añadido un nuevo comentario a esta instancia de ayuda.
email_no_reply_text: No responda a este correo.
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index fac4c32..2e0043b 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -24,6 +24,7 @@ fr:
about: À propos de nous
contact: Contact
signup: S'enregistrer
+ donations: Donation
login: Connexion
logout: Déconnexion
cancel: Annuler
diff --git a/config/locales/it.yml b/config/locales/it.yml
index 9e318fc..e6d746c 100644
--- a/config/locales/it.yml
+++ b/config/locales/it.yml
@@ -23,6 +23,7 @@ it:
pricing: Prezzario
about: A proposito di
contact: Contatti
+ donations: Donazioni
signup: Registrati
login: Accedi
logout: Log Out
@@ -32,7 +33,7 @@ it:
updated: Aggiornata
none: Nessuno
unknown: Sconosciuto
- admin: Admin
+ admin: Administratore
anonymous: Anonimo
save: Salva
add: Aggiungi
diff --git a/config/locales/pt.yml b/config/locales/pt.yml
index 256653e..3cf8820 100644
--- a/config/locales/pt.yml
+++ b/config/locales/pt.yml
@@ -23,6 +23,7 @@ pt:
pricing: Preço
about: Sobre Nós
contact: Contato
+ donations: Doações
signup: Cadastrar
login: Entrar
logout: Sair
diff --git a/engines/billing/:w b/engines/billing/:w
new file mode 100644
index 0000000..8629136
--- /dev/null
+++ b/engines/billing/:w
@@ -0,0 +1,99 @@
+class SubscriptionsController < BillingBaseController
+ before_filter :require_login
+ before_filter :confirm_cancel_subscription, :only => [:destroy]
+ before_filter :confirm_self_or_admin, :only => [:index]
+ before_filter :confirm_no_pending_active_pastdue_subscription, :only => [:new, :create]
+ # for now, admins cannot create or destroy subscriptions for others:
+ before_filter :confirm_self, :only => [:new, :create]
+
+ def new
+ if current_user.has_payment_info?
+ @client_token = Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id)
+ else
+ @client_token = Braintree::ClientToken.generate
+ end
+ @subscriptions = Braintree::Plan.all
+ end
+
+ def create
+ @result = Braintree::Subscription.create(
+ payment_method_token: params[:payment_method_nonce],
+ plan_id: Braintree::Plan.all
+ )
+ end
+
+ def confirm
+ make_subscription
+ if @result.success?
+ flash[:success] = "Congratulations! Your transaction has been successfully!"
+ else
+ flash[:error] = "Something went wrong while processing your donation. Please try again!"
+ end
+ redirect_to action: :new, locale: params[:locale]
+ end
+
+private
+
+ def make_subscription
+ unless current_user.has_payment_info?
+ subs_with_user_info
+ else
+ subs_without_user_info
+ end
+ end
+
+ def subs_with_user_info
+ # don't show link to subscribe if they are already subscribed?
+ @result = Braintree::Subscription.sale(
+ payment_method_token: params[:payment_method_nonce],
+ plans_id: Braintree::Plan.all,
+ customer: {
+ first_name: params[:first_name],
+ last_name: params[:last_name],
+ company: params[:company],
+ email: current_user.email,
+ phone: params[:phone]
+ },
+ options: {
+ store_in_vault: true
+ })
+ current_user.update_attributes(braintree_customer_id: @result.transaction.customer_details.id) if @result.success?
+ end
+
+ def subs_without_user_info
+ @result = Braintree::Subscription.sale(
+ payment_method_token: params[:payment_method_nonce],
+ plans_id: Braintree::Plan.all
+ )
+ end
+
+ def destroy
+ @result = Braintree::Subscription.cancel params[:id]
+ end
+
+ def index
+ customer = Customer.find_by_user_id(@user.id)
+ @subscriptions = customer.subscriptions(nil, false)
+ end
+
+
+ def confirm_cancel_subscription
+ access_denied unless view_context.allow_cancel_subscription(@subscription)
+ end
+
+ def confirm_no_pending_active_pastdue_subscription
+ @customer = Customer.find_by_user_id(@user.id)
+ if subscription = @customer.subscriptions # will return pending, active or pastdue subscription, if it exists
+ redirect_to user_subscription_path(@user, subscription.id), :notice => 'You already have a subscription'
+ end
+ end
+
+ def confirm_self
+ @user == current_user
+ end
+
+ def confirm_self_or_admin
+ access_denied unless confirm_self or admin?
+ end
+
+end
diff --git a/engines/billing/app/controllers/payments_controller.rb b/engines/billing/app/controllers/payments_controller.rb
index 6ea149f..4a047ad 100644
--- a/engines/billing/app/controllers/payments_controller.rb
+++ b/engines/billing/app/controllers/payments_controller.rb
@@ -9,6 +9,7 @@ class PaymentsController < BillingBaseController
end
end
+# not sure if this should be kept
def index
access_denied unless admin? or (@user == current_user)
customer = Customer.find_by_user_id(@user.id)
@@ -27,12 +28,15 @@ class PaymentsController < BillingBaseController
redirect_to action: :new, locale: params[:locale]
end
+
private
def make_transaction
- unless current_user.has_payment_info?
- transact_with_user_info
- else
+ if current_user.has_payment_info?
transact_without_user_info
+ elsif current_user.is_anonymous?
+ transact_without_user_info
+ else
+ transact_with_user_info
end
end
diff --git a/engines/billing/app/controllers/subscriptions_controller.rb b/engines/billing/app/controllers/subscriptions_controller.rb
index f066b3c..0a9b412 100644
--- a/engines/billing/app/controllers/subscriptions_controller.rb
+++ b/engines/billing/app/controllers/subscriptions_controller.rb
@@ -1,6 +1,5 @@
class SubscriptionsController < BillingBaseController
before_filter :require_login
- before_filter :fetch_subscription, :only => [:show, :destroy]
before_filter :confirm_cancel_subscription, :only => [:destroy]
before_filter :confirm_self_or_admin, :only => [:index]
before_filter :confirm_no_pending_active_pastdue_subscription, :only => [:new, :create]
@@ -8,17 +7,87 @@ class SubscriptionsController < BillingBaseController
before_filter :confirm_self, :only => [:new, :create]
def new
- # don't show link to subscribe if they are already subscribed?
- credit_card = @customer.default_credit_card #safe to assume default?
- @payment_method_token = credit_card.token
- @plans = Braintree::Plan.all
+ if current_user.braintree_customer_id
+ @client_token = Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id)
+ else
+ @client_token = Braintree::ClientToken.generate
+ end
+ @subscriptions = Braintree::Plan.all
end
- # show has no content, so not needed at this point.
-
def create
- @result = Braintree::Subscription.create( :payment_method_token => params[:payment_method_token], :plan_id => params[:plan_id] )
- #if you want to test pastdue, can add :price => '2001', :trial_period => true,:trial_duration => 1,:trial_duration_unit => "day" and then wait a day
+ @result = Braintree::Subscription.create(
+ payment_method_token: braintree_customer.payment_methods.first.token,
+ plan_id: params[:plan_id],
+ )
+ if @result.success?
+ flash[:success] = "Congratulations! Your transaction has been successfully!"
+ else
+ flash[:error] = "Something went wrong while processing your donation. Please try again!"
+ end
+ redirect_to action: :new, locale: params[:locale]
+ end
+
+ def braintree_customer
+ if current_user.braintree_customer_id
+ Braintree::Customer.find current_user.braintree_customer_id
+ else
+ customer = Braintree::Customer.create(payment_method_nonce: params[:payment_method_nonce]).customer
+ current_user.update_attributes braintree_customer_id: customer.id
+ customer
+ end
+ end
+
+ def confirm
+ @result = Braintree::Subscription.sale(
+ payment_method_token: params[:payment_method_nonce],
+ plans_id: params[:plan_id],
+ )
+ end
+
+ def _confirm
+ make_subscription
+ if @result.success?
+ flash[:success] = "Congratulations! Your transaction has been successfully!"
+ else
+ flash[:error] = "Something went wrong while processing your donation. Please try again!"
+ end
+ redirect_to action: :new, locale: params[:locale]
+ end
+
+private
+
+ def make_subscription
+ unless current_user.has_payment_info?
+ subs_with_user_info
+ else
+ subs_without_user_info
+ end
+ end
+
+ def subs_with_user_info
+ # don't show link to subscribe if they are already subscribed?
+ @result = Braintree::Subscription.sale(
+ payment_method_token: params[:payment_method_nonce],
+ plans_id: Braintree::Plan.all,
+ customer: {
+ first_name: params[:first_name],
+ last_name: params[:last_name],
+ company: params[:company],
+ email: current_user.email,
+ phone: params[:phone]
+ },
+ options: {
+ store_in_vault: true
+ })
+ current_user.update_attributes(braintree_customer_id: @result.transaction.customer_details.id) if @result.success?
+ end
+
+ def subs_without_user_info
+ @result = Braintree::Subscription.sale(
+ payment_method_token: params[:payment_method_nonce],
+ plans_id: Braintree::Plan.all
+ )
end
def destroy
@@ -30,26 +99,16 @@ class SubscriptionsController < BillingBaseController
@subscriptions = customer.subscriptions(nil, false)
end
- private
-
- def fetch_subscription
- @subscription = Braintree::Subscription.find params[:id]
- @credit_card = Braintree::CreditCard.find @subscription.payment_method_token
- @subscription_customer_id = @credit_card.customer_id
- current_user_customer = Customer.find_by_user_id(current_user.id)
- access_denied unless admin? or (current_user_customer and current_user_customer.braintree_customer_id == @subscription_customer_id)
-
- end
def confirm_cancel_subscription
access_denied unless view_context.allow_cancel_subscription(@subscription)
end
def confirm_no_pending_active_pastdue_subscription
- @customer = Customer.find_by_user_id(@user.id)
- if subscription = @customer.subscriptions # will return pending, active or pastdue subscription, if it exists
- redirect_to user_subscription_path(@user, subscription.id), :notice => 'You already have a subscription'
- end
+ #@customer = Customer.find_by_user_id(@user.id)
+ #if subscription = @customer.subscriptions # will return pending, active or pastdue subscription, if it exists
+ #redirect_to user_subscription_path(@user, subscription.id), :notice => 'You already have a subscription'
+ #end
end
def confirm_self
diff --git a/engines/billing/app/views/payments/_customer_form.html.haml b/engines/billing/app/views/payments/_customer_form.html.haml
new file mode 100644
index 0000000..82828cd
--- /dev/null
+++ b/engines/billing/app/views/payments/_customer_form.html.haml
@@ -0,0 +1,10 @@
+%p
+ = t(:personal_info)
+%div
+ = text_field_tag :first_name, "",placeholder: "First Name", class: "radius"
+%div
+ = text_field_tag :last_name, "",placeholder: "Last Name", class: "radius"
+%div
+ = text_field_tag :company, "",placeholder: "Company", class: "radius"
+%div
+ = text_field_tag :phone, "",placeholder: "Phone", class: "radius"
diff --git a/engines/billing/app/views/payments/_form.html.erb b/engines/billing/app/views/payments/_form.html.erb
deleted file mode 100644
index 9713981..0000000
--- a/engines/billing/app/views/payments/_form.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
--# slim template
-= form_tag organization_payment_path(organization) do
-
- #dropin
-
- = submit_tag 'Confirm', class: 'btn push--ends'
-
-- content_for :javascript do
- = javascript_include_tag "https://js.braintreegateway.com/v2/braintree.js"
- javascript:
- var client_token = "#{@organization.payment['client_token']}";
- braintree.setup(
- client_token,
- 'dropin', {
- container: 'dropin'
- });
diff --git a/engines/billing/app/views/payments/default.html.erb b/engines/billing/app/views/payments/default.html.erb
new file mode 100644
index 0000000..bbecf46
--- /dev/null
+++ b/engines/billing/app/views/payments/default.html.erb
@@ -0,0 +1,27 @@
+<h2 class="mbs">New Donation</h2>
+<br>
+<%= form_tag confirm_payment_path, id: "checkout-form" do %>
+ <% if current_user and !current_user.has_payment_info? %>
+ <%= render 'customer_form' unless @anonymous_user%>
+ <% end %>
+<br>
+<p>Please enter your donation details (this is a donation and will not be applied towards your account):</p>
+<div id="payment-form"></div>
+<div id='coinbase-container-id'></div>
+<input type="text" name="amount" placeholder="Enter amount">
+<input type="submit" class="btn btn-primary" value="Donate">
+<% end %>
+
+<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
+<script>
+ // We generated a client token for you so you can test out this code
+ // immediately. In a production-ready integration, you will need to
+ // generate a client token on your server (see section below).
+var clientToken = "<%= @client_token %>";
+braintree.setup(clientToken, "dropin", {
+ container: "payment-form",
+ form: "checkout-form",
+ coinbase: { container: "coinbase-container-id" }
+}
+ );
+</script>
diff --git a/engines/billing/app/views/payments/new.html.erb b/engines/billing/app/views/payments/new.html.erb
deleted file mode 100644
index 03fc5b9..0000000
--- a/engines/billing/app/views/payments/new.html.erb
+++ /dev/null
@@ -1,31 +0,0 @@
-<h2 class="mbs">New Donation</h2>
-<br>
-<%= form_tag confirm_payment_path, id: "checkout-form" do %>
- <%# add migration to user first. Not sure about the anonymous part. %>
- <%# render 'customer_form' unless current_user.has_payment_info? && current_user.where.not.is_anonymous? %>
- <% if current_user and !current_user.has_payment_info? %>
- <%= render 'customer_form' unless @anonymous_user%>
- <% end %>
- <br>
- <p>Please enter your donation details (this is a donation and will not be applied towards your account):</p>
- <div id="payment-form"></div>
- <div id='coinbase-container-id'></div>
- <input type="text" name="amount" placeholder="Enter amount">
- <input type="submit" class="btn btn-primary" value="Donate">
-<% end %>
-
-<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
-<script>
-// We generated a client token for you so you can test out this code
-// immediately. In a production-ready integration, you will need to
-// generate a client token on your server (see section below).
-var clientToken = "<%= @client_token %>";
-
-braintree.setup(clientToken, "dropin", {
- container: "payment-form",
- form: "checkout-form",
- coinbase: { container: "coinbase-container-id" }
-}
- );
-</script>
-
diff --git a/engines/billing/app/views/payments/new.html.haml b/engines/billing/app/views/payments/new.html.haml
new file mode 100644
index 0000000..8d5bd5a
--- /dev/null
+++ b/engines/billing/app/views/payments/new.html.haml
@@ -0,0 +1,21 @@
+%h2.mbs
+ = t(:new_donation)
+%br/
+= form_tag confirm_payment_path, id: "checkout-form" do
+ - if current_user and !current_user.has_payment_info?
+ = render 'customer_form' unless current_user.is_anonymous?
+ %br/
+ %p
+ = t(:donation_info)
+ %div{:id => "payment-form" }
+ %div{:id => "coinbase-container-id" }
+ %input{:name => "amount", :placeholder => "Enter amount", :type => "text"}
+ %input.btn.btn-primary{:type => "submit", :value => "Donate"}
+%script{:src => "https://js.braintreegateway.com/v2/braintree.js"}
+:javascript
+ var clientToken = "#{@client_token}";
+ braintree.setup(clientToken, "dropin", {
+ container: "payment-form",
+ form: "checkout-form",
+ coinbase: { container: "coinbase-container-id" }
+ });
diff --git a/engines/billing/app/views/payments/_customer_form.html.erb b/engines/billing/app/views/subscriptions/_customer_form.html.erb
index 2e8a3b1..2e8a3b1 100644
--- a/engines/billing/app/views/payments/_customer_form.html.erb
+++ b/engines/billing/app/views/subscriptions/_customer_form.html.erb
diff --git a/engines/billing/app/views/subscriptions/new.html.erb b/engines/billing/app/views/subscriptions/new.html.erb
new file mode 100644
index 0000000..f3e143a
--- /dev/null
+++ b/engines/billing/app/views/subscriptions/new.html.erb
@@ -0,0 +1,35 @@
+<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
+<h2 class="mbs">Subscriptions</h2>
+<br>
+<%= form_tag subscriptions_path, id: "checkout-form" do %>
+ <% if current_user and !current_user.has_payment_info? %>
+ <%= render 'customer_form' unless @anonymous_user%>
+ <% end %>
+<br>
+<p>Choose subcription:</p>
+<ul>
+ <% @subscriptions.each do |subscription| %>
+ <li>
+ <%= subscription.name %>
+ -
+ <%= subscription.price %>
+ <%= simple_form_for :subscription, :url => :subscriptions, :id => "checkout-form-#{subscription.id}" do |f| %>
+ <input type="hidden" name="plan_id" id="" value="<%= subscription.id%>" />
+ <div id="payment-form-<%= subscription.id%>"></div>
+ <div class="form-actions">
+ <%= f.submit t(:subscribe), :class => 'btn btn-primary' %>
+ </div>
+ <script type="text/javascript" charset="utf-8">
+ var clientToken = "<%= @client_token %>";
+ braintree.setup(clientToken, "dropin", {
+ container: "payment-form-<%= subscription.id%>",
+ coinbase: { container: "coinbase-container-id" }
+ });
+ </script>
+ <% end %>
+ </li>
+ <% end %>
+</ul>
+<div id="payment-form"></div>
+<div id='coinbase-container-id'></div>
+<% end %>
diff --git a/engines/billing/app/views/subscriptions/new.html.haml b/engines/billing/app/views/subscriptions/new.html.haml
deleted file mode 100644
index 4183458..0000000
--- a/engines/billing/app/views/subscriptions/new.html.haml
+++ /dev/null
@@ -1,15 +0,0 @@
-- if @payment_method_token
- %h1
- Subscribe to plan
- = #currently just one plan
- = @plans[0].name
- = number_to_currency(@plans[0].price)
- = simple_form_for :subscription, :url => :subscriptions do |f|
- = hidden_field_tag :payment_method_token, @payment_method_token
- = hidden_field_tag :plan_id, @plans[0].id
- .form-actions
- = f.submit t(:subscribe), :class => 'btn btn-primary'
-- else
- = t(:must_create_customer)
- %p
- = link_to t(:create_new_customer), new_customer_path
diff --git a/engines/billing/config/locales/en.yml b/engines/billing/config/locales/en.yml
index 1300958..20ba03c 100644
--- a/engines/billing/config/locales/en.yml
+++ b/engines/billing/config/locales/en.yml
@@ -8,4 +8,8 @@ en:
plan: "Plan"
description: "Description"
cost: "Cost"
- free: "Free" \ No newline at end of file
+ free: "Free"
+ new_donation: "New Donation"
+ donation_info: "Please enter your donation details (this is a donation and will not be applied towards your account, if you have one):"
+ donation_amount: "Enter amount"
+ personal_info: "Please enter your personal info:"