summaryrefslogtreecommitdiff
path: root/engines/billing/:w
diff options
context:
space:
mode:
authorclaucece <soficeli0@gmail.com>2015-09-27 23:04:55 -0500
committerclaucece <soficeli0@gmail.com>2015-10-05 22:41:21 -0500
commit6c4f02fd2d530c28899561fac40ca76075975dc8 (patch)
tree575f0aa91e189a6894f3bd1bce7fb5e83f02a6f7 /engines/billing/:w
parentb26d10fe7d87b570bd888fa2a2543f3675278f8b (diff)
update to haml, created translations, deleted files
Diffstat (limited to 'engines/billing/:w')
-rw-r--r--engines/billing/:w99
1 files changed, 0 insertions, 99 deletions
diff --git a/engines/billing/:w b/engines/billing/:w
deleted file mode 100644
index 8629136..0000000
--- a/engines/billing/:w
+++ /dev/null
@@ -1,99 +0,0 @@
-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