change camel case variable to ruby style.
This commit is contained in:
parent
1f9338735c
commit
112d2c6fff
3 changed files with 23 additions and 24 deletions
|
|
@ -14,10 +14,11 @@ class PaymentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
|
||||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||||
|
|
||||||
@payment = Payment.new payment_params.merge(amount: @total_amount_to_pay.cents,
|
@payment = Payment.new payment_params.merge(stripe_customer_email: params[:stripeEmail],
|
||||||
|
stripe_customer_token: params[:stripeToken],
|
||||||
|
amount: @total_amount_to_pay.cents,
|
||||||
user: current_user,
|
user: current_user,
|
||||||
conference: @conference)
|
conference: @conference)
|
||||||
|
|
||||||
|
|
@ -26,6 +27,7 @@ class PaymentsController < ApplicationController
|
||||||
redirect_to conference_conference_registration_path(@conference.short_title), flash:
|
redirect_to conference_conference_registration_path(@conference.short_title), flash:
|
||||||
{ success: 'Thanks! You have purchased your tickets successfully.' }
|
{ success: 'Thanks! You have purchased your tickets successfully.' }
|
||||||
else
|
else
|
||||||
|
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -33,7 +35,7 @@ class PaymentsController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def payment_params
|
def payment_params
|
||||||
params.permit :stripeEmail, :stripeToken
|
params.permit :stripe_customer_email, :stripe_customer_token
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_purchased_ticket_purchases
|
def update_purchased_ticket_purchases
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ class Payment < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :conference
|
belongs_to :conference
|
||||||
|
|
||||||
attr_accessor :stripeEmail
|
attr_accessor :stripe_customer_email
|
||||||
attr_accessor :stripeToken
|
attr_accessor :stripe_customer_token
|
||||||
|
|
||||||
validates :status, presence: true
|
validates :status, presence: true
|
||||||
validates :amount, presence: true, numericality: { greater_than: 0 }
|
validates :amount, presence: true, numericality: { greater_than: 0 }
|
||||||
|
|
@ -22,26 +22,24 @@ class Payment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def purchase
|
def purchase
|
||||||
begin
|
customer = Stripe::Customer.create email: stripe_customer_email,
|
||||||
customer = Stripe::Customer.create email: stripeEmail,
|
source: stripe_customer_token,
|
||||||
source: stripeToken,
|
description: user.name
|
||||||
description: user.name
|
|
||||||
|
|
||||||
gateway_response = Stripe::Charge.create customer: customer.id,
|
gateway_response = Stripe::Charge.create customer: customer.id,
|
||||||
receipt_email: stripeEmail,
|
receipt_email: stripe_customer_email,
|
||||||
description: 'ticket purchases',
|
description: 'ticket purchases',
|
||||||
amount: amount_to_pay,
|
amount: amount_to_pay,
|
||||||
currency: conference.tickets.first.price_currency
|
currency: conference.tickets.first.price_currency
|
||||||
|
|
||||||
self.last4 = gateway_response[:source][:last4]
|
self.last4 = gateway_response[:source][:last4]
|
||||||
self.authorization_code = gateway_response[:id]
|
self.authorization_code = gateway_response[:id]
|
||||||
self.status = 'success'
|
self.status = 'success'
|
||||||
true
|
true
|
||||||
|
|
||||||
rescue => error
|
rescue => error
|
||||||
errors.add(:base, error.message)
|
errors.add(:base, error.message)
|
||||||
self.status = 'failure'
|
self.status = 'failure'
|
||||||
false
|
false
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
.div
|
.div
|
||||||
|
|
||||||
.col-md-12.table-responsive
|
.col-md-12.table-responsive
|
||||||
%table.table.table-hover
|
%table.table.table-hover
|
||||||
%thead
|
%thead
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue