Class: Forge::CreditCardProcessor
- Inherits:
-
Object
- Object
- Forge::CreditCardProcessor
- Includes:
- ActiveMerchant::Billing
- Defined in:
- lib/forge/lib/forge/credit_card_processor.rb
Instance Attribute Summary collapse
-
#credit_card ⇒ Object
readonly
Returns the value of attribute credit_card.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #create_credit_card(args) ⇒ Object
-
#initialize(order, currency = "CAD") ⇒ CreditCardProcessor
constructor
A new instance of CreditCardProcessor.
- #pay(order) ⇒ Object
Constructor Details
#initialize(order, currency = "CAD") ⇒ CreditCardProcessor
Returns a new instance of CreditCardProcessor.
9 10 11 12 |
# File 'lib/forge/lib/forge/credit_card_processor.rb', line 9 def initialize(order, currency = "CAD") @order = order @currency = currency end |
Instance Attribute Details
#credit_card ⇒ Object (readonly)
Returns the value of attribute credit_card.
7 8 9 |
# File 'lib/forge/lib/forge/credit_card_processor.rb', line 7 def credit_card @credit_card end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/forge/lib/forge/credit_card_processor.rb', line 7 def @message end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/forge/lib/forge/credit_card_processor.rb', line 7 def status @status end |
Instance Method Details
#create_credit_card(args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/forge/lib/forge/credit_card_processor.rb', line 14 def create_credit_card(args) @credit_card = ActiveMerchant::Billing::CreditCard.new( :first_name => @order.billing_address[:first_name], :last_name => @order.billing_address[:last_name], :month => args[:month], :year => args[:year], :verification_value => args[:verification_value], :number => args[:number] ) end |
#pay(order) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/forge/lib/forge/credit_card_processor.rb', line 25 def pay(order) raise "Credit card cannot be nil" if @credit_card.nil? # build the options hash for the payment = ("Order ## #{order.id}") if @credit_card.valid? = order.(@credit_card, ) if .success? && order. # proceed to capture payment capture = order.capture_payment if capture.success? && order.paid? @message = "Successfully charged $#{sprintf("%.2f", order.total_price)} to the credit card #{credit_card.display_number}" else @status = :failure @message = "Payment capture failed. Please contact your credit card company to determine the problem, or retry with a different card." end else # could not authorize @status = :failure @message = "Payment authorization failed. Please contact your credit card company to determine the problem, or retry with a different card." end @status = @order.state.to_sym else @status = :invalid_credit_card @message = "The credit card number you have entered is not valid." end if @status == :paid true else false end end |