summaryrefslogtreecommitdiff
path: root/engines/billing/app
diff options
context:
space:
mode:
Diffstat (limited to 'engines/billing/app')
-rw-r--r--engines/billing/app/controllers/billing_admin_controller.rb3
-rw-r--r--engines/billing/app/controllers/billing_base_controller.rb3
-rw-r--r--engines/billing/app/controllers/credit_card_info_controller.rb35
-rw-r--r--engines/billing/app/controllers/customer_controller.rb64
-rw-r--r--engines/billing/app/controllers/payments_controller.rb60
-rw-r--r--engines/billing/app/controllers/subscriptions_controller.rb97
-rw-r--r--engines/billing/app/helpers/billing_helper.rb6
-rw-r--r--engines/billing/app/helpers/braintree_form_helper.rb1
-rw-r--r--engines/billing/app/helpers/braintree_helper.rb2
-rw-r--r--engines/billing/app/models/customer.rb58
-rw-r--r--engines/billing/app/views/billing_admin/show.html.haml6
-rw-r--r--engines/billing/app/views/credit_card_info/confirm.html.haml5
-rw-r--r--engines/billing/app/views/credit_card_info/edit.html.haml16
-rw-r--r--engines/billing/app/views/customer/_customer_data.html.haml16
-rw-r--r--engines/billing/app/views/customer/_transaction.html.haml0
-rw-r--r--engines/billing/app/views/customer/confirm.html.haml14
-rw-r--r--engines/billing/app/views/customer/edit.html.haml23
-rw-r--r--engines/billing/app/views/customer/new.html.haml24
-rw-r--r--engines/billing/app/views/customer/show.html.haml27
-rw-r--r--engines/billing/app/views/payments/_customer_form.html.haml10
-rw-r--r--engines/billing/app/views/payments/_non_customer_fields.html.haml16
-rw-r--r--engines/billing/app/views/payments/_transaction_details.html.haml15
-rw-r--r--engines/billing/app/views/payments/confirm.html.haml26
-rw-r--r--engines/billing/app/views/payments/index.html.haml3
-rw-r--r--engines/billing/app/views/payments/new.html.haml37
-rw-r--r--engines/billing/app/views/subscriptions/_customer_form.html.haml10
-rw-r--r--engines/billing/app/views/subscriptions/_subscription_details.html.haml3
-rw-r--r--engines/billing/app/views/subscriptions/create.html.haml9
-rw-r--r--engines/billing/app/views/subscriptions/destroy.html.haml7
-rw-r--r--engines/billing/app/views/subscriptions/index.html.haml37
-rw-r--r--engines/billing/app/views/subscriptions/new.html.haml15
-rw-r--r--engines/billing/app/views/subscriptions/show.html.haml26
32 files changed, 208 insertions, 466 deletions
diff --git a/engines/billing/app/controllers/billing_admin_controller.rb b/engines/billing/app/controllers/billing_admin_controller.rb
index e11d4ee..23740d6 100644
--- a/engines/billing/app/controllers/billing_admin_controller.rb
+++ b/engines/billing/app/controllers/billing_admin_controller.rb
@@ -1,6 +1,9 @@
class BillingAdminController < BillingBaseController
before_filter :require_admin
+ #not sure if this controller is still needed. Admin can easly acess
+ #braintree's dashboard and check subscriptions. Don't know if everything
+ #should be 'self contained' in web_app""
def show
br_atleast_90_days = Braintree::Subscription.search do |search|
diff --git a/engines/billing/app/controllers/billing_base_controller.rb b/engines/billing/app/controllers/billing_base_controller.rb
index 0453677..c343938 100644
--- a/engines/billing/app/controllers/billing_base_controller.rb
+++ b/engines/billing/app/controllers/billing_base_controller.rb
@@ -13,6 +13,9 @@ class BillingBaseController < ApplicationController
elsif params[:id]
@user = User.find(params[:id])
else
+ #not sure if this is still needed. Donations work with either customer or
+ #anonymous_user. Subscriptions work with customer. Customer belongs to
+ #user.
# TODO
# hacky, what are cases where @user hasn't yet been set? certainly some cases with subscriptions and payments
@user = current_user
diff --git a/engines/billing/app/controllers/credit_card_info_controller.rb b/engines/billing/app/controllers/credit_card_info_controller.rb
deleted file mode 100644
index fbaa6f1..0000000
--- a/engines/billing/app/controllers/credit_card_info_controller.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-class CreditCardInfoController < ApplicationController
- before_filter :require_login, :set_user
-
- def edit
- @credit_card = Braintree::CreditCard.find(params[:id])
- customer = Customer.find_by_user_id(@user.id)
- if customer and customer.braintree_customer_id == @credit_card.customer_id
- @tr_data = Braintree::TransparentRedirect.
- update_credit_card_data(:redirect_url => confirm_credit_card_info_url,
- :payment_method_token => @credit_card.token)
- else
- access_denied
- end
-
- end
-
- def confirm
- @result = Braintree::TransparentRedirect.confirm(request.query_string)
- if @result.success?
- render :action => "confirm"
- else
- @credit_card = Braintree::CreditCard.find(@result.params[:payment_method_token])
- render :action => "edit"
- end
- end
-
-
- private
-
- def set_user
- # this assumes anybody, even an admin, will not access for another user.
- @user = current_user
- end
-
-end
diff --git a/engines/billing/app/controllers/customer_controller.rb b/engines/billing/app/controllers/customer_controller.rb
deleted file mode 100644
index 6cbcb44..0000000
--- a/engines/billing/app/controllers/customer_controller.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-class CustomerController < BillingBaseController
- before_filter :require_login, :fetch_customer
-
- def show
- if @customer
- @customer.with_braintree_data!
- @default_cc = @customer.default_credit_card
- @active_subscription = @customer.subscriptions
- @transactions = @customer.braintree_customer.transactions
- end
- end
-
- def new
- if @customer.has_payment_info?
- redirect_to edit_customer_path(@user), :notice => 'Here is your saved customer data'
- else
- fetch_new_transparent_redirect_data
- end
- end
-
- def edit
- fetch_edit_transparent_redirect_data
- end
-
- def confirm
- @result = Braintree::TransparentRedirect.confirm(request.query_string)
- if @result.success?
- @customer.braintree_customer = @result.customer
- @customer.save
- render :action => "confirm"
- elsif @customer.has_payment_info?
- fetch_edit_transparent_redirect_data
- render :action => "edit"
- else
- fetch_new_transparent_redirect_data
- render :action => "new"
- end
- end
-
- protected
-
- def fetch_new_transparent_redirect_data
- access_denied unless @user == current_user # admins cannot do this for others
- @tr_data = Braintree::TransparentRedirect.
- create_customer_data(:redirect_url => confirm_customer_url)
- end
-
- def fetch_edit_transparent_redirect_data
- access_denied unless @user == current_user # admins cannot do this for others
- @customer.with_braintree_data!
- @default_cc = @customer.default_credit_card
- @tr_data = Braintree::TransparentRedirect.
- update_customer_data(:redirect_url => confirm_customer_url,
- :customer_id => @customer.braintree_customer_id) ##??
- end
-
- def fetch_customer
- @customer = Customer.find_by_user_id(@user.id)
- if @user == current_user
- @customer ||= Customer.new(user: @user)
- end
- access_denied unless (@customer and (@customer.user == current_user)) or admin?
- end
-end
diff --git a/engines/billing/app/controllers/payments_controller.rb b/engines/billing/app/controllers/payments_controller.rb
index fce6570..871f1b4 100644
--- a/engines/billing/app/controllers/payments_controller.rb
+++ b/engines/billing/app/controllers/payments_controller.rb
@@ -2,19 +2,14 @@ class PaymentsController < BillingBaseController
before_filter :require_login, :only => [:index]
def new
- fetch_transparent_redirect
- end
-
- def confirm
- @result = Braintree::TransparentRedirect.confirm(request.query_string)
- if @result.success?
- render :action => "confirm"
+ if current_user.has_payment_info?
+ @client_token = Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id)
else
- fetch_transparent_redirect
- render :action => "new"
- end
+ @client_token = Braintree::ClientToken.generate
+ 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)
@@ -23,12 +18,49 @@ class PaymentsController < BillingBaseController
@transactions = braintree_data.transactions
end
- protected
+ def confirm
+ make_transaction
+ if @result.success?
+ flash[:success] = I18n.t(:donation_sucess)
+ else
+ flash[:error] = I18n.t(:donation_not_sucess)
+ end
+ redirect_to action: :new, locale: params[:locale]
+ end
- def fetch_transparent_redirect
- @tr_data = Braintree::TransparentRedirect.transaction_data redirect_url: confirm_payment_url,
- transaction: { type: "sale", options: {submit_for_settlement: true } }
+ private
+ def make_transaction
+ 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
+ def transact_with_user_info
+ @result = Braintree::Transaction.sale(
+ amount: params[:amount],
+ payment_method_nonce: params[:payment_method_nonce],
+ 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 transact_without_user_info
+ @result = Braintree::Transaction.sale(
+ amount: params[:amount],
+ payment_method_nonce: params[:payment_method_nonce],
+ )
+ end
end
diff --git a/engines/billing/app/controllers/subscriptions_controller.rb b/engines/billing/app/controllers/subscriptions_controller.rb
index f066b3c..1d29cac 100644
--- a/engines/billing/app/controllers/subscriptions_controller.rb
+++ b/engines/billing/app/controllers/subscriptions_controller.rb
@@ -1,63 +1,72 @@
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]
- # for now, admins cannot create or destroy subscriptions for others:
- before_filter :confirm_self, :only => [:new, :create]
+ before_filter :assign_user
+ before_filter :confirm_cancel_subscription, only: [:destroy]
+ before_filter :generate_client_token, only: [:show]
+ before_filter :get_braintree_customer, only: [:subscribe]
- 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
+ def index
+ if @user.subscription_id
+ @subscription = Braintree::Subscription.find @user.subscription_id
+ @plan = Braintree::Plan.all.select{ |plan| plan.id == @subscription.plan_id }.first
+ else
+ @subscriptions = Braintree::Plan.all
+ end
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
+ def show
+ @plan = Braintree::Plan.all.select{ |plan| plan.id == params[:id] }.first
end
- def destroy
- @result = Braintree::Subscription.cancel params[:id]
+ def subscribe
+ @result = Braintree::Subscription.create(payment_method_token: @customer.payment_methods.first.token,
+ plan_id: params[:id])
+ if @result.success?
+ @user.update_attributes subscription_id: @result.subscription.id
+ flash[:success] = I18n.t(:subscription_sucess)
+ else
+ flash[:error] = I18n.t(:subscription_not_sucess)
+ end
+ redirect_to action: :index, locale: params[:locale]
end
- def index
- customer = Customer.find_by_user_id(@user.id)
- @subscriptions = customer.subscriptions(nil, false)
+ def unsubscribe
+ @result = Braintree::Subscription.cancel(@user.subscription_id)
+ if @result.success?
+ @user.update_attributes subscription_id: nil
+ flash[:success] = I18n.t(:unsubscription_sucess)
+ else
+ flash[:error] = I18n.t(:unsubscription_not_sucess)
+ end
+ redirect_to action: :index, locale: params[:locale]
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)
+ def assign_user
+ @user = current_user
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'
+ def generate_client_token
+ 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
end
- def confirm_self
- @user == current_user
- end
-
- def confirm_self_or_admin
- access_denied unless confirm_self or admin?
+ def get_braintree_customer
+ if current_user.braintree_customer_id
+ @customer = Braintree::Customer.find(current_user.braintree_customer_id)
+ else
+ @customer = Braintree::Customer.create(
+ payment_method_nonce: params[:payment_method_nonce],
+ first_name: params[:first_name],
+ last_name: params[:last_name],
+ company: params[:company],
+ email: current_user.email,
+ phone: params[:phone]
+ ).customer
+ current_user.update_attributes braintree_customer_id: @customer.id
+ end
end
-
end
diff --git a/engines/billing/app/helpers/billing_helper.rb b/engines/billing/app/helpers/billing_helper.rb
index b9e5e2e..6d1df5a 100644
--- a/engines/billing/app/helpers/billing_helper.rb
+++ b/engines/billing/app/helpers/billing_helper.rb
@@ -1,5 +1,6 @@
module BillingHelper
+ #deprecated.. erase?
def braintree_form_for(object, options = {}, &block)
options.reverse_merge! params: @result && @result.params[object],
errors: @result && @result.errors.for(object),
@@ -14,10 +15,11 @@ module BillingHelper
if (admin? and user == current_user)
billing_admin_path
else
- show_or_new_customer_link(user)
+ subscriptions_path
end
end
+ #deprecated.. erase?
def show_or_new_customer_link(user)
# Link to show if user is admin viewing another user, or user is already a customer.
# Otherwise link to create a new customer.
@@ -28,6 +30,7 @@ module BillingHelper
end
end
+ #deprecated.. erase?
# a bit strange to put here, but we don't have a subscription model
def user_for_subscription(subscription)
@@ -44,6 +47,7 @@ module BillingHelper
end
+ #customer needs to see active or pending?
def allow_cancel_subscription(subscription)
['Active', 'Pending'].include? subscription.status or (admin? and subscription.status == 'Past Due')
end
diff --git a/engines/billing/app/helpers/braintree_form_helper.rb b/engines/billing/app/helpers/braintree_form_helper.rb
index cb322fa..31ea373 100644
--- a/engines/billing/app/helpers/braintree_form_helper.rb
+++ b/engines/billing/app/helpers/braintree_form_helper.rb
@@ -3,6 +3,7 @@ module BraintreeFormHelper
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::TagHelper
+ #check if needed
def initialize(object_name, object, template, options, proc)
super
@braintree_params = @options[:params]
diff --git a/engines/billing/app/helpers/braintree_helper.rb b/engines/billing/app/helpers/braintree_helper.rb
index 2d18b6c..a6322c5 100644
--- a/engines/billing/app/helpers/braintree_helper.rb
+++ b/engines/billing/app/helpers/braintree_helper.rb
@@ -1,5 +1,5 @@
module BraintreeHelper
-
+ #check if needed
end
diff --git a/engines/billing/app/models/customer.rb b/engines/billing/app/models/customer.rb
deleted file mode 100644
index 1acc7a5..0000000
--- a/engines/billing/app/models/customer.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-class Customer < CouchRest::Model::Base
-
- FIELDS = [:first_name, :last_name, :phone, :website, :company, :fax, :addresses, :credit_cards, :custom_fields]
- attr_accessor *FIELDS
-
- use_database "customers"
- belongs_to :user
- belongs_to :braintree_customer
-
- # Braintree::Customer - stored on braintrees servers - we only have the id.
- def braintree_customer
- @braintree_customer ||= Braintree::Customer.find(braintree_customer_id)
- end
-
- validates :user, presence: true
-
- design do
- view :by_user_id
- view :by_braintree_customer_id
- end
-
- def has_payment_info?
- !!braintree_customer_id
- end
-
- # from braintree_ruby_examples/rails3_tr_devise and should be tweaked
- def with_braintree_data!
- return self unless has_payment_info?
-
- FIELDS.each do |field|
- send(:"#{field}=", braintree_customer.send(field))
- end
- self
- end
-
- def default_credit_card
- return unless has_payment_info?
-
- credit_cards.find { |cc| cc.default? }
- end
-
- # based on 2nd parameter, either returns the single active subscription (or nil if there isn't one), or an array of all subsciptions
- def subscriptions(braintree_data=nil, only_pending_active_pastdue=true)
- self.with_braintree_data!
- return unless has_payment_info?
-
- subscriptions = []
- self.default_credit_card.subscriptions.each do |sub|
- if only_pending_active_pastdue and ['Pending', 'Active','Past Due'].include? sub.status
- return sub
- else
- subscriptions << sub
- end
- end
- only_pending_active_pastdue ? nil : subscriptions
- end
-
-end
diff --git a/engines/billing/app/views/billing_admin/show.html.haml b/engines/billing/app/views/billing_admin/show.html.haml
index 0382cf0..11f3928 100644
--- a/engines/billing/app/views/billing_admin/show.html.haml
+++ b/engines/billing/app/views/billing_admin/show.html.haml
@@ -1,7 +1,9 @@
+/ same concern as in controller
%legend= t(:more_than_90_days_past_due)
= render(:partial => "subscriptions/subscription_details", :collection => @past_due_atleast_90_days, :as => 'subscription', :locals => {:show_user => true}) || t(:none)
%legend= t(:all_past_due)
= render(:partial => "subscriptions/subscription_details", :collection => @all_past_due, :as => 'subscription', :locals => {:show_user => true}) || t(:none)
-%legend= t(:your_settings)
-= link_to 'view own billing settings', show_or_new_customer_link(current_user) \ No newline at end of file
+/needed?
+/%legend= t(:your_settings)
+/= link_to 'view own billing settings', show_or_new_customer_link(current_user)
diff --git a/engines/billing/app/views/credit_card_info/confirm.html.haml b/engines/billing/app/views/credit_card_info/confirm.html.haml
deleted file mode 100644
index 9dd8176..0000000
--- a/engines/billing/app/views/credit_card_info/confirm.html.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-%h1 Payment Info Confirmation
-%p Your payment information was successfully saved.
-%dl
- %dt Credit Card
- %dd= @result.credit_card.masked_number
diff --git a/engines/billing/app/views/credit_card_info/edit.html.haml b/engines/billing/app/views/credit_card_info/edit.html.haml
deleted file mode 100644
index 9e44344..0000000
--- a/engines/billing/app/views/credit_card_info/edit.html.haml
+++ /dev/null
@@ -1,16 +0,0 @@
-%h1 Change Credit Card
-- if @result
- #total-errors{:style => "color:red;"}
- = h(@result.errors.size)
- error(s)
-= braintree_form_for :credit_card, :existing => @credit_card do |f|
- = field_set_tag "Credit Card" do
- %dl
- %dt= f.label :number, 'Number'
- %dd= f.text_field :number
- %dt= f.label :expiration_date, 'Expiration Date (MM/YY)'
- %dd= f.text_field :expiration_date
- %dt= f.label :cvv, 'CVV'
- %dd= f.text_field :cvv
- = hidden_field_tag :tr_data, @tr_data
- = f.button :wrapped, 'Save Payment Info', cancel: edit_customer_path(@user.id)
diff --git a/engines/billing/app/views/customer/_customer_data.html.haml b/engines/billing/app/views/customer/_customer_data.html.haml
deleted file mode 100644
index 439ae5c..0000000
--- a/engines/billing/app/views/customer/_customer_data.html.haml
+++ /dev/null
@@ -1,16 +0,0 @@
-%legend= t(:customer_information)
-%dl
- %dt First Name
- %dd= @customer.first_name
- %dt Last Name
- %dd= @customer.last_name
- %dt Phone
- %dd= @customer.phone
-%legend= t(:credit_card_information)
-%dl
- %dt Number
- %dd= @default_cc.masked_number
- %dt Expiration Date
- %dd= @default_cc.expiration_date
- - if current_user == @user
- = btn t(:edit_saved_data), edit_customer_path(@user.id)
diff --git a/engines/billing/app/views/customer/_transaction.html.haml b/engines/billing/app/views/customer/_transaction.html.haml
deleted file mode 100644
index e69de29..0000000
--- a/engines/billing/app/views/customer/_transaction.html.haml
+++ /dev/null
diff --git a/engines/billing/app/views/customer/confirm.html.haml b/engines/billing/app/views/customer/confirm.html.haml
deleted file mode 100644
index eab9616..0000000
--- a/engines/billing/app/views/customer/confirm.html.haml
+++ /dev/null
@@ -1,14 +0,0 @@
-%h1 Payment Info Confirmation
-%p Your payment information was successfully saved.
-%dl
- %dt First Name
- %dd= @result.customer.first_name
- %dt Last Name
- %dd= @result.customer.last_name
- %dt Phone
- %dd= @result.customer.phone
- %dt Credit Card
- - @result.customer.credit_cards.each do |cc|
- %dd= cc.masked_number
-- customer = Customer.find_by_user_id(@user.id)
-= btn 'View Customer Info', show_customer_path(@user.id)
diff --git a/engines/billing/app/views/customer/edit.html.haml b/engines/billing/app/views/customer/edit.html.haml
deleted file mode 100644
index f461fcc..0000000
--- a/engines/billing/app/views/customer/edit.html.haml
+++ /dev/null
@@ -1,23 +0,0 @@
-- if @result
- #total-errors{:style => "color:red;"}
- = h(@result.errors.size)
- error(s)
-= braintree_form_for :customer, existing: @customer do |f|
- = field_set_tag "Customer" do
- %dl
- %dt= f.label :first_name, 'First Name'
- %dd= f.text_field :first_name
- %dt= f.label :last_name, 'Last Name'
- %dd= f.text_field :last_name
- %dt= f.label :phone, 'Phone'
- %dd= f.text_field :phone
- - if @default_cc
- = # todo, as they will need a credit card, so not sure about conditional?
- %dt= t(:stored_credit_card)
- %dd
- = @default_cc.masked_number
- = btn t(:change_credit_card), edit_credit_card_info_path(:id => @default_cc.token)
- = hidden_field_tag :tr_data, @tr_data
- .form-actions
- = f.submit t(:save_customer_info), :class => 'btn btn-primary'
- = btn t(:cancel), show_customer_path(@user)
diff --git a/engines/billing/app/views/customer/new.html.haml b/engines/billing/app/views/customer/new.html.haml
deleted file mode 100644
index e1f5ba9..0000000
--- a/engines/billing/app/views/customer/new.html.haml
+++ /dev/null
@@ -1,24 +0,0 @@
-- if @result
- #total-errors{:style => "color:red;"}
- = h(@result.errors.size)
- error(s)
-= braintree_form_for :customer do |f|
- = field_set_tag "Customer" do
- %dl
- %dt= f.label :first_name, 'First Name'
- %dd= f.text_field :first_name
- %dt= f.label :last_name, 'Last Name'
- %dd= f.text_field :last_name
- %dt= f.label :phone, 'Phone'
- %dd= f.text_field :phone
- = field_set_tag "Credit Card" do
- - f.fields_for :credit_card do |cc|
- %dl
- %dt= cc.label :number, 'Number'
- %dd= cc.text_field :number
- %dt= cc.label :expiration_date, 'Expiration Date (MM/YY)'
- %dd= cc.text_field :expiration_date
- %dt= cc.label :cvv, 'CVV'
- %dd= cc.text_field :cvv
- = hidden_field_tag :tr_data, @tr_data
- = f.submit 'Save Payment Info'
diff --git a/engines/billing/app/views/customer/show.html.haml b/engines/billing/app/views/customer/show.html.haml
deleted file mode 100644
index ce4d01a..0000000
--- a/engines/billing/app/views/customer/show.html.haml
+++ /dev/null
@@ -1,27 +0,0 @@
-- if admin? and !@customer
- = t(:no_saved_customer)
-- else
- = render :partial => 'customer_data'
- %legend= t(:last_three_transactions)
- - counter = 0
- = # these will be ordered with most recently created first, per http://stackoverflow.com/questions/16425475/
- - @transactions.each do |t|
- - break if counter > 2 # not ruby-like, but object is a Braintree::ResourceCollection so limited methods available
- = render :partial => "payments/transaction_details", :locals => {:transaction => t}
- - counter += 1
- = btn :transaction_history, user_payments_path(@user)
- %legend= t(:subscriptions)
- - if @active_subscription
- = render :partial => "subscriptions/subscription_details", :locals => {:subscription => @active_subscription}
- - else
- %p
- = t(:no_relevant_subscription)
- - if current_user == @user
- %p
- .form-actions
- = btn :subscribe_to_plan, new_subscription_path
- %p
- = link_to t(:all_subscriptions), user_subscriptions_path(@user)
-
-.form-actions
- = btn :make_donation, new_payment_path, :type => 'primary'
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..70b9b97
--- /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: "#{t(:first_name)}", class: "radius"
+%div
+ = text_field_tag :last_name, "",placeholder: "#{t(:last_name)}", class: "radius"
+%div
+ = text_field_tag :company, "",placeholder: "#{t(:company)}", class: "radius"
+%div
+ = text_field_tag :phone, "",placeholder: "#{t(:phone)}", class: "radius"
diff --git a/engines/billing/app/views/payments/_non_customer_fields.html.haml b/engines/billing/app/views/payments/_non_customer_fields.html.haml
deleted file mode 100644
index 77cfe95..0000000
--- a/engines/billing/app/views/payments/_non_customer_fields.html.haml
+++ /dev/null
@@ -1,16 +0,0 @@
-= field_set_tag "Personal Information" do
- = f.fields_for :customer do |c|
- %div= c.label :first_name, "First Name"
- %div= c.text_field :first_name
- %div= c.label :last_name, "Last Name"
- %div= c.text_field :last_name
- %div= c.label :email, "Email"
- %div= c.text_field :email
-= field_set_tag "Credit Card" do
- = f.fields_for :credit_card do |c|
- %div= c.label :number, "Number"
- %div= c.text_field :number
- %div= c.label :expiration_date, "Expiration Date (MM/YY)"
- %div= c.text_field :expiration_date
- %div= c.label :cvv, "CVV"
- %div= c.text_field :cvv \ No newline at end of file
diff --git a/engines/billing/app/views/payments/_transaction_details.html.haml b/engines/billing/app/views/payments/_transaction_details.html.haml
deleted file mode 100644
index 85e4f6a..0000000
--- a/engines/billing/app/views/payments/_transaction_details.html.haml
+++ /dev/null
@@ -1,15 +0,0 @@
-%p
- = transaction.id
- Type:
- = transaction.type
- Amount:
- = number_to_currency(transaction.amount)
- Status:
- = transaction.status
- Date
- = transaction.created_at.strftime("%Y-%m-%d")
- - if sub_start = transaction.subscription_details.billing_period_start_date
- From subscription which started
- = sub_start
- - else # should not have any of these
- Not paid as part of subscription \ No newline at end of file
diff --git a/engines/billing/app/views/payments/confirm.html.haml b/engines/billing/app/views/payments/confirm.html.haml
deleted file mode 100644
index 45af3c9..0000000
--- a/engines/billing/app/views/payments/confirm.html.haml
+++ /dev/null
@@ -1,26 +0,0 @@
-%h1 Payment Result
-%div Thank you for your donation.
-%h2 Transaction Details
-%table
- %tr
- %td Amount
- %td
- $#{@result.transaction.amount}
- %tr
- %td Transaction ID:
- %td= @result.transaction.id
- %tr
- %td First Name:
- %td= h @result.transaction.customer_details.first_name
- %tr
- %td Last Name:
- %td= h @result.transaction.customer_details.last_name
- %tr
- %td Email:
- %td= h @result.transaction.customer_details.email
- %tr
- %td Credit Card:
- %td= h @result.transaction.credit_card_details.masked_number
- %tr
- %td Card Type:
- %td= h @result.transaction.credit_card_details.card_type \ No newline at end of file
diff --git a/engines/billing/app/views/payments/index.html.haml b/engines/billing/app/views/payments/index.html.haml
index 7a89917..01aa660 100644
--- a/engines/billing/app/views/payments/index.html.haml
+++ b/engines/billing/app/views/payments/index.html.haml
@@ -1,5 +1,6 @@
+/ check if necessary
%h2=t :transaction_history
- if (@transactions.count == 0)
= t(:no_transaction_history)
- @transactions.each do |t|
- = render :partial => "transaction_details", :locals => {:transaction => t} \ No newline at end of file
+ = render :partial => "transaction_details", :locals => {:transaction => t}
diff --git a/engines/billing/app/views/payments/new.html.haml b/engines/billing/app/views/payments/new.html.haml
index e9a8273..67018b2 100644
--- a/engines/billing/app/views/payments/new.html.haml
+++ b/engines/billing/app/views/payments/new.html.haml
@@ -1,17 +1,20 @@
-%h1
- = t(:Donation)
-- if logged_in?
- = t(:donation_not_payment)
-- if @result and @result.errors.size > 0
- %div{:style => "color: red;"}
- = h @result.errors.size
- error(s)
-- if @result and @result.transaction and @result.transaction.status != 'success'
- %div{:style => "color: red;"}
- = t(:processor_declined)
-= braintree_form_for :transaction, :html => {:autocomplete => "off"} do |f|
- = f.label :amount, t(:amount)
- = f.text_field :amount
- = render :partial => 'non_customer_fields', :locals => {:f => f}
- = hidden_field_tag :tr_data, @tr_data
- = f.submit "Submit Donation", :class => 'btn btn-primary'
+%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?
+ %p
+ = t(:donation_info)
+ %div{:id => "payment-form" }
+ %div{:id => "coinbase-container-id" }
+ %input{:name => "amount", :placeholder => "#{t(:donation_amount)}", :type => "text"}
+ %input.btn.btn-primary{:type => "submit", :value => "#{t(: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/subscriptions/_customer_form.html.haml b/engines/billing/app/views/subscriptions/_customer_form.html.haml
new file mode 100644
index 0000000..70b9b97
--- /dev/null
+++ b/engines/billing/app/views/subscriptions/_customer_form.html.haml
@@ -0,0 +1,10 @@
+%p
+ = t(:personal_info)
+%div
+ = text_field_tag :first_name, "",placeholder: "#{t(:first_name)}", class: "radius"
+%div
+ = text_field_tag :last_name, "",placeholder: "#{t(:last_name)}", class: "radius"
+%div
+ = text_field_tag :company, "",placeholder: "#{t(:company)}", class: "radius"
+%div
+ = text_field_tag :phone, "",placeholder: "#{t(:phone)}", class: "radius"
diff --git a/engines/billing/app/views/subscriptions/_subscription_details.html.haml b/engines/billing/app/views/subscriptions/_subscription_details.html.haml
index 6145c95..e6cf87d 100644
--- a/engines/billing/app/views/subscriptions/_subscription_details.html.haml
+++ b/engines/billing/app/views/subscriptions/_subscription_details.html.haml
@@ -1,3 +1,4 @@
+/needed?
%p
- if local_assigns[:show_user]
User:
@@ -23,4 +24,4 @@
Status:
%font{:color => color}
= subscription.status
- - # would be good to get plan name but not sure if that is possible? \ No newline at end of file
+ - # would be good to get plan name but not sure if that is possible?
diff --git a/engines/billing/app/views/subscriptions/create.html.haml b/engines/billing/app/views/subscriptions/create.html.haml
deleted file mode 100644
index 2b6c5e9..0000000
--- a/engines/billing/app/views/subscriptions/create.html.haml
+++ /dev/null
@@ -1,9 +0,0 @@
-- if @result.success?
- %h1
- Subscription Status
- = @result.subscription.status
- = render :partial => "subscription_details", :locals => {:subscription => @result.subscription}
-- else
- %h1
- Error:
- = @result.message \ No newline at end of file
diff --git a/engines/billing/app/views/subscriptions/destroy.html.haml b/engines/billing/app/views/subscriptions/destroy.html.haml
deleted file mode 100644
index e6e8578..0000000
--- a/engines/billing/app/views/subscriptions/destroy.html.haml
+++ /dev/null
@@ -1,7 +0,0 @@
-- if @result.success?
- Subscription destroyed
-- else
- Error:
- = @result.message
-%p
- = btn 'Customer Information', show_customer_path(@user)
diff --git a/engines/billing/app/views/subscriptions/index.html.haml b/engines/billing/app/views/subscriptions/index.html.haml
index 1e3fb25..70fbf8d 100644
--- a/engines/billing/app/views/subscriptions/index.html.haml
+++ b/engines/billing/app/views/subscriptions/index.html.haml
@@ -1,8 +1,29 @@
-%h2=t :all_subscriptions
-- pending_active_pastdue = false
-- @subscriptions.each do |s|
- - if ['Pending', 'Active','Past Due'].include? s.status
- - pending_active_pastdue = true
- = render :partial => "subscription_details", :locals => {:subscription => s}
-- if !pending_active_pastdue and @user == current_user
- = btn 'subscribe to plan', new_subscription_path
+%h2.mbs
+ = t(:subscriptions)
+%h4{ :style => "line-height: 300%;" }
+ .last
+ = t(:lastestsubs)
+ - if @user.subscription_id
+ %ul
+ - @subscription.transactions.each do |transaction|
+ %li
+ %p{ :style => "font-size: 14px; font-weight: normal;" }
+ #{t(:date)} #{transaction.created_at}
+ %ul
+ = link_to "#{t(:unsubscribe_from)} #{@plan.name}", unsubscribe_subscription_path(@subscription.plan_id), method: :delete, class: "btn btn-danger"
+ %br
+ - else
+ %p{ :style => "font-size: 14px; font-weight: normal;"}
+ =t(:no_subs)
+ %h4
+ =t(:choose_subs)
+ %br
+ %ul.nav.nav-tabs.nav-stacked
+ - @subscriptions.each do |subscription|
+ .well
+ = subscription.name
+ = "$" + subscription.price.to_s
+ %div{ :style => "line-height: 300%;" }
+ = link_to t(:choose_button), subscription_path(subscription.id), class: "btn btn-info"
+
+
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/app/views/subscriptions/show.html.haml b/engines/billing/app/views/subscriptions/show.html.haml
index 246ebf0..45c54cc 100644
--- a/engines/billing/app/views/subscriptions/show.html.haml
+++ b/engines/billing/app/views/subscriptions/show.html.haml
@@ -1,7 +1,19 @@
-%h1
- - if @subscription.status == 'Active'
- Current
- Subscription
-= render :partial => "subscription_details", :locals => {:subscription => @subscription}
-- if allow_cancel_subscription(@subscription)
- = destroy_btn :cancel_subscription, user_subscription_path(@user, @subscription.id), type: 'danger'
+%script{:src => "https://js.braintreegateway.com/v2/braintree.js"}
+%h2.mbs
+ = t(:new_subs)
+= simple_form_for :subscription, :url => subscribe_subscription_path(@plan.id), :id => "checkout-form" do |f|
+ - if current_user and !current_user.has_payment_info?
+ = render 'customer_form'
+ %br/
+ %p
+ =t(:pay_details)
+ #payment-form
+ #coinbase-container-id
+ .form-actions
+ = f.submit t(:subscribe), :class => 'btn btn-primary'
+ :javascript
+ var clientToken = "#{@client_token}";
+ braintree.setup(clientToken, "dropin", {
+ container: "payment-form",
+ coinbase: { container: "coinbase-container-id" }
+ });