change rails initialisation.

repair abilities. add ticket purchasing check.
This commit is contained in:
Rishabh Saxena 2016-08-05 20:17:27 +05:30
parent 72ef33cbe6
commit a9ab1186f8
9 changed files with 14 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View file

@ -21,8 +21,8 @@ class PaymentsController < ApplicationController
if @payment.purchase && @payment.save
update_purchased_ticket_purchases
redirect_to conference_conference_registration_path(@conference.short_title), flash:
{ success: 'Thanks! You have purchased your tickets successfully.' }
redirect_to conference_conference_registration_path(@conference.short_title),
notice: 'Thanks! You have purchased your tickets successfully.'
else
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)

View file

@ -8,9 +8,11 @@ class TicketPurchasesController < ApplicationController
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
if message.blank?
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
redirect_to new_conference_payment_path,
notice: 'Please pay here to purchase tickets.'
else
redirect_to conference_conference_registration_path(@conference.short_title)
redirect_to conference_tickets_path(@conference.short_title),
error: 'Please purchase atleast one ticket to continue.'
end
else
redirect_to conference_conference_registration_path(@conference.short_title),

View file

@ -81,7 +81,7 @@ class Ability
can :index, Ticket
can :manage, TicketPurchase, user_id: user.id
can [:new], Payment, user_id: user.id
can [:new, :create], Payment, user_id: user.id
can [:create, :destroy], Subscription, user_id: user.id

View file

@ -109,7 +109,7 @@
You haven't bought any tickets.
= link_to 'Please buy some tickets to support us!', conference_tickets_path(@conference.short_title)
%p
(Your registration won't be complete without buying a ticket)
(Your participation won't be valid without buying a ticket)
.row
.col-md-12

View file

@ -26,8 +26,8 @@
= humanized_money_with_symbol @total_amount_to_pay
%script.stripe-button{ src: "https://checkout.stripe.com/checkout.js",
data: { amount: @total_amount_to_pay.cents,
email: current_user.email,
currency: @total_amount_to_pay.currency,
image: image_url('OSEM_ICON.jpg'),
name: ENV['OSEM_NAME'] || 'OSEM',
description: "book your tickets",
key: Rails.application.secrets.stripe_publishable_key,

View file

@ -42,4 +42,4 @@
.col-md-13
%p.text-muted.text-center
%small
* Buying a ticket is mandatory. Your registration will not complete until you buy a ticket.
* Buying a ticket is mandatory. Your participation will not be valid until you buy a ticket.

View file

@ -1,6 +1 @@
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.secrets.stripe_publishable_key,
:secret_key => ENV['STRIPE_SECRET_KEY'] || Rails.application.secrets.stripe_secret_key
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
Stripe.api_key = Rails.application.secret.stripe_secret_key

View file

@ -105,6 +105,9 @@ describe 'User' do
it{ should be_able_to(:index, Ticket) }
it{ should be_able_to(:manage, TicketPurchase.new(user_id: user.id)) }
it{ should be_able_to(:new, Payment.new(user_id: user.id)) }
it{ should be_able_to(:create, Payment.new(user_id: user.id)) }
it{ should be_able_to(:create, Subscription.new(user_id: user.id)) }
it{ should be_able_to(:destroy, subscription) }