Module: Models::Order::PaymentMethods::InstanceMethods

Defined in:
lib/forge/lib/models/order/payment_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_credit_card(args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/forge/lib/models/order/payment_methods.rb', line 37

def create_credit_card(args)
  @credit_card = ActiveMerchant::Billing::CreditCard.new(
    :first_name => self.billing_address.first_name,
    :last_name => self.billing_address.last_name,
    :month => args[:month],
    :year => args[:year],
    :verification_value => args[:verification_value],
    :number => args[:number]
  )
end

#payObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/forge/lib/models/order/payment_methods.rb', line 48

def pay
  raise "Credit card cannot be nil" if @credit_card.nil?

  # build the options hash for the payment
  options = options_hash(self.description)
  if @credit_card.valid?
    capture = purchase(@credit_card, options)
    if capture.success? && self.paid?
      @message = "Successfully charged $#{sprintf("%.2f", self.total)} to the credit card #{credit_card.display_number}"
    else
      @status = :failure
      @message = "Payment capture failed.  <br />#{capture.message}<br />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
  return @status == :paid
end