Class: Piggybak::Payment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Piggybak::Payment
- Defined in:
- app/models/piggybak/payment.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
-
#verification_value ⇒ Object
Returns the value of attribute verification_value.
Instance Method Summary collapse
- #credit_card ⇒ Object
- #details ⇒ Object
- #month_enum ⇒ Object
- #process(order) ⇒ Object
-
#refund ⇒ Object
Note: It is not added now, because for methods that do not store user profiles, a credit card number must be passed If encrypted credit cards are stored on the system, this can be updated.
- #status_enum ⇒ Object
- #year_enum ⇒ Object
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
12 13 14 |
# File 'app/models/piggybak/payment.rb', line 12 def number @number end |
#verification_value ⇒ Object
Returns the value of attribute verification_value.
13 14 15 |
# File 'app/models/piggybak/payment.rb', line 13 def verification_value @verification_value end |
Instance Method Details
#credit_card ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/models/piggybak/payment.rb', line 27 def credit_card { "number" => self.number, "month" => self.month, "year" => self.year, "verification_value" => self.verification_value, "first_name" => self.line_item ? self.line_item.order.billing_address.firstname : nil, "last_name" => self.line_item ? self.line_item.order.billing_address.lastname : nil } end |
#details ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/models/piggybak/payment.rb', line 65 def details if !self.new_record? return "Payment ##{self.id} (#{self.created_at.strftime("%m-%d-%Y")}): " #+ #"$#{"%.2f" % self.total}" reference line item total here instead else return "" end end |
#month_enum ⇒ Object
19 20 21 |
# File 'app/models/piggybak/payment.rb', line 19 def month_enum 1.upto(12).to_a end |
#process(order) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/piggybak/payment.rb', line 36 def process(order) return true if !self.new_record? ActiveMerchant::Billing::Base.mode = Piggybak.config.activemerchant_mode payment_gateway = self.payment_method.klass.constantize gateway = payment_gateway::KLASS.new(self.payment_method.key_values) p_credit_card = ActiveMerchant::Billing::CreditCard.new(self.credit_card) gateway_response = gateway.(order.total_due*100, p_credit_card, :address => order.avs_address) if gateway_response.success? self.attributes = { :transaction_id => payment_gateway.transaction_id(gateway_response), :masked_number => self.number.mask_cc_number } gateway.capture(order.total_due*100, gateway_response., { :credit_card => p_credit_card } ) return true else self.errors.add :payment_method_id, gateway_response. return false end end |
#refund ⇒ Object
Note: It is not added now, because for methods that do not store user profiles, a credit card number must be passed If encrypted credit cards are stored on the system, this can be updated
60 61 62 63 |
# File 'app/models/piggybak/payment.rb', line 60 def refund # TODO: Create ActiveMerchant refund integration return end |
#status_enum ⇒ Object
15 16 17 |
# File 'app/models/piggybak/payment.rb', line 15 def status_enum ["paid"] end |
#year_enum ⇒ Object
23 24 25 |
# File 'app/models/piggybak/payment.rb', line 23 def year_enum Time.now.year.upto(Time.now.year + 10).to_a end |