Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bb8315
commit 1189120
Showing
11 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Payment < ActiveRecord::Base | ||
|
||
belongs_to :order | ||
|
||
attr_accessor :number, :month, :year, :verification_value, :name | ||
|
||
validate :credit_card | ||
|
||
def first_name | ||
order.name.split(" ")[0] | ||
end | ||
|
||
def last_name | ||
order.name.split(" ")[1] | ||
end | ||
|
||
def credit_card | ||
credit_card = ActiveMerchant::Billing::CreditCard.new( | ||
:number => number, | ||
:month => month, | ||
:year => year, | ||
:first_name => first_name, | ||
:last_name => last_name, | ||
:verification_value => verification_value | ||
) | ||
|
||
unless credit_card.valid? | ||
credit_card.errors.full_messages.each do |message| | ||
errors.add_to_base message | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<h1>Showing Order</h1> | ||
|
||
<% if @order.paid? %><p>This order is currently pending delivery, <%= button_to "mark as delivered", admin_order_path(@order, :order => { :status => "paid" }), :method => :put %></p><% end %> | ||
<% if @order.paid? %> | ||
<p>This order is currently pending delivery, <%= button_to "mark as delivered", admin_order_path(@order), :method => :put %></p><% end %> | ||
<% if @order.sent? %><p>This order has been delivered</p><% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreatePayments < ActiveRecord::Migration | ||
def self.up | ||
create_table :payments do |t| | ||
t.text :return_params | ||
t.boolean :success | ||
t.integer :order_id | ||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :payments | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
return_params: MyText | ||
success: false | ||
|
||
two: | ||
return_params: MyText | ||
success: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
describe Payment do | ||
before(:each) do | ||
@order = Order.make | ||
@valid_attributes = { | ||
:success => false, | ||
:order => @order, | ||
:name => @order.name, | ||
:number => "0000 0000 0000 0000", | ||
:month => "05", | ||
:year => "2011", | ||
:verification_value => "123" | ||
} | ||
@payment = Payment.new(@valid_attributes) | ||
end | ||
|
||
it "should create a new instance given valid attributes" do | ||
Payment.create!(@valid_attributes) | ||
end | ||
|
||
it "should validate that the credit card is validated" do | ||
@payment.number = nil | ||
@payment.save | ||
@payment.should have(1).error | ||
end | ||
|
||
end |