use full_name instead of first and last name, test changes, schema improvements
This commit is contained in:
parent
f00e051eff
commit
6d8605073f
10 changed files with 25 additions and 81 deletions
|
|
@ -14,12 +14,12 @@ class PaymentsController < ApplicationController
|
|||
|
||||
def create
|
||||
@payment = Payment.new(payment_params)
|
||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||
|
||||
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.' }
|
||||
else
|
||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
|
@ -27,17 +27,12 @@ class PaymentsController < ApplicationController
|
|||
private
|
||||
|
||||
def update_purchased_ticket_purchases
|
||||
paid_ticket_purchases = current_user.ticket_purchases.by_conference(@conference).unpaid
|
||||
paid_ticket_purchases.each do |ticket|
|
||||
ticket.paid = true
|
||||
ticket.payment_id = @payment.id
|
||||
ticket.save
|
||||
end
|
||||
current_user.ticket_purchases.by_conference(@conference).unpaid.update_all(paid: true, payment_id: @payment.id)
|
||||
end
|
||||
|
||||
def payment_params
|
||||
params.require(:payment)
|
||||
.permit(:first_name, :last_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
|
||||
.permit(:full_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
|
||||
.merge(user: current_user, conference: @conference)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ class Payment < ActiveRecord::Base
|
|||
attr_accessor :expiration_month
|
||||
attr_accessor :expiration_year
|
||||
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
validates :full_name, presence: true
|
||||
validates :credit_card_number, presence: true
|
||||
validates :card_verification_value, presence: true, length: { minimum: 3, maximum: 4 }
|
||||
validates :expiration_month, presence: true, numericality: { greater_than_or_equal_to: 1, less_than_or_equal_to: 12 }
|
||||
|
|
@ -27,8 +26,7 @@ class Payment < ActiveRecord::Base
|
|||
|
||||
def credit_card
|
||||
@credit_card ||= ActiveMerchant::Billing::CreditCard.new(
|
||||
first_name: first_name,
|
||||
last_name: last_name,
|
||||
name: full_name,
|
||||
number: credit_card_number,
|
||||
month: expiration_month,
|
||||
year: expiration_year,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
= semantic_form_for(@payment, url: conference_payments_path) do |f|
|
||||
.form-group
|
||||
= f.label :first_name, 'First name(as on card)'
|
||||
= f.text_field :first_name, class: "form-control", placeholder: "John", id: "first_name"
|
||||
.form-group
|
||||
= f.label :last_name, 'Last name(as on card)'
|
||||
= f.text_field :last_name,class: "form-control", placeholder: "Doe", id: "last_name"
|
||||
= f.label :full_name, 'Full name (as on card)'
|
||||
= f.text_field :full_name, class: "form-control", placeholder: "John Doe", id: "full_name"
|
||||
%span.pull-right
|
||||
%img.img-responsive{:src => image_url('credit_card.png')}
|
||||
.form-group
|
||||
= f.label :credit_card_number, "Credit Card number(without spaces)"
|
||||
= f.label :credit_card_number, "Credit Card number (without spaces)"
|
||||
.input-group
|
||||
= f.text_field :credit_card_number, class: "form-control", placeholder: "XXXX XXXX XXXX XXXX", id: "credit_card_number"
|
||||
%span.input-group-addon
|
||||
|
|
@ -20,7 +17,7 @@
|
|||
= f.label :expiration_year
|
||||
= f.select :expiration_year, years, {}, class: "form-control", id: "expiration_year"
|
||||
.form-group.col-md-10
|
||||
= f.label :card_verification_value, 'Security Code(3 on back, AmEx: 4 on front)'
|
||||
= f.label :card_verification_value, 'Security Code (3 on back, AmEx: 4 on front)'
|
||||
= f.text_field :card_verification_value, class: "form-control", placeholder: "XXX", id: "card_verification_value"
|
||||
= f.number_field :amount, value: @total_amount_to_pay, class: "form-control", type: 'hidden'
|
||||
%ul.price-tags.pull-right
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
.container
|
||||
.row
|
||||
.col-md-12
|
||||
.page-header
|
||||
%h1
|
||||
Payment Attempts for
|
||||
= @conference.title
|
||||
- if flash[:notice].present?
|
||||
.alert.alert-success
|
||||
= flash[:notice]
|
||||
%table.table.table-bordered.table-striped
|
||||
%tr
|
||||
%th First Name
|
||||
%th Last Name
|
||||
%th Last 4
|
||||
%th Amount
|
||||
%th Status
|
||||
%th Authorization Code
|
||||
- if @payments.size > 0
|
||||
- @payments.each do |payment|
|
||||
%tr
|
||||
%td= payment.first_name
|
||||
%td= payment.last_name
|
||||
%td= payment.last4
|
||||
%td= number_to_currency payment.amount
|
||||
%td= payment.status
|
||||
%td= payment.authorization_code
|
||||
- else
|
||||
%tr
|
||||
%td{:colspan => "5"} No payments have been attempted.
|
||||
.pull-right
|
||||
= link_to "Conference Registration", conference_conference_registration_path(@conference.short_title), class: 'btn btn-primary'
|
||||
|
|
@ -8,12 +8,8 @@
|
|||
-if !ticket.description.blank?
|
||||
= markdown(ticket.description)
|
||||
%td.col-sm-1.col-md-1
|
||||
- if ticket.bought?(current_user)
|
||||
= text_field_tag("tickets[][#{ticket.id}]", 0,
|
||||
= text_field_tag("tickets[][#{ticket.id}]", 0,
|
||||
type: 'number', min: 0, class: "form-control quantity", 'data-id' => ticket.id)
|
||||
- else
|
||||
= text_field_tag("tickets[][#{ticket.id}]", 0, type: 'number', min: 0,
|
||||
class: "form-control quantity", 'data-id' => ticket.id)
|
||||
%td.col-sm-1.col-md-1.text-center
|
||||
= ticket.price.symbol
|
||||
%span{id: "price_#{ticket.id}"}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
class CreatePayments < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :payments do |t|
|
||||
t.string :first_name
|
||||
t.string :last_name
|
||||
t.string :full_name, null: false
|
||||
t.string :last4
|
||||
t.decimal :amount, precision: 12, scale: 3
|
||||
t.integer :amount, null: false
|
||||
t.string :authorization_code
|
||||
t.integer :status, default: 0
|
||||
t.integer :status, default: 0, null: false
|
||||
t.integer :user_id, null: false
|
||||
t.integer :conference_id, null: false
|
||||
t.datetime :created_at
|
||||
t.datetime :updated_at
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
|
|
|||
15
db/schema.rb
15
db/schema.rb
|
|
@ -251,16 +251,15 @@ ActiveRecord::Schema.define(version: 20160624151257) do
|
|||
end
|
||||
|
||||
create_table "payments", force: :cascade do |t|
|
||||
t.string "first_name"
|
||||
t.string "last_name"
|
||||
t.string "full_name", null: false
|
||||
t.string "last4"
|
||||
t.decimal "amount", precision: 12, scale: 3
|
||||
t.integer "amount", null: false
|
||||
t.string "authorization_code"
|
||||
t.integer "status", default: 0
|
||||
t.integer "user_id"
|
||||
t.integer "conference_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "status", default: 0, null: false
|
||||
t.integer "user_id", null: false
|
||||
t.integer "conference_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "programs", force: :cascade do |t|
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ FactoryGirl.define do
|
|||
factory :payment do
|
||||
user
|
||||
conference
|
||||
first_name { "#{Faker::Hipster.word} abc" }
|
||||
last_name { "#{Faker::Hipster.word} xyz" }
|
||||
full_name { Faker::Hipster.word.to_s }
|
||||
credit_card_number '4242424242424111'
|
||||
card_verification_value '123'
|
||||
expiration_month 6
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ feature Registration do
|
|||
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
||||
expect(purchase.quantity).to eq(2)
|
||||
|
||||
fill_in 'first_name', with: 'foo'
|
||||
fill_in 'last_name', with: 'bar'
|
||||
fill_in 'full_name', with: 'foo'
|
||||
select Date.current.year + 2, from: 'expiration_year'
|
||||
fill_in 'card_verification_value', with: '123'
|
||||
fill_in 'credit_card_number', with: '4242424242423333'
|
||||
|
|
@ -61,8 +60,7 @@ feature Registration do
|
|||
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
||||
expect(purchase.quantity).to eq(2)
|
||||
|
||||
fill_in 'first_name', with: 'foo'
|
||||
fill_in 'last_name', with: 'bar'
|
||||
fill_in 'full_name', with: 'foo'
|
||||
select Date.current.year + 2, from: 'expiration_year'
|
||||
fill_in 'card_verification_value', with: '123'
|
||||
fill_in 'credit_card_number', with: '4242424242422222'
|
||||
|
|
@ -89,8 +87,7 @@ feature Registration do
|
|||
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
||||
expect(purchase.quantity).to eq(2)
|
||||
|
||||
fill_in 'first_name', with: 'foo'
|
||||
fill_in 'last_name', with: 'bar'
|
||||
fill_in 'full_name', with: 'foo'
|
||||
select Date.current.year + 2, from: 'expiration_year'
|
||||
fill_in 'card_verification_value', with: '123'
|
||||
fill_in 'credit_card_number', with: '4242424242421111'
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ describe Payment do
|
|||
expect(build(:payment)).to be_valid
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of(:first_name) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:last_name) }
|
||||
it { is_expected.to validate_presence_of(:full_name) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:credit_card_number) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue