Created
January 22, 2015 23:57
-
-
Save cannapages/d06a3470cf7bba5ab7b4 to your computer and use it in GitHub Desktop.
Transaction Model for hemptemps
This file contains hidden or 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
class Transaction < ActiveRecord::Base | |
attr_accessor :card_number, :card_expiration_date, :card_cvv, :card_street_address, :card_city, :card_state, :card_zipcode, :is_online_cc | |
has_one :student_cart | |
belongs_to :student | |
belongs_to :user | |
include PayPal::SDK::REST | |
def submit_to_paypal | |
@payment = Payment.new({ | |
:intent => "sale", | |
:payer => { | |
:payment_method => "credit_card", | |
:funding_instruments => [{ | |
:credit_card => { | |
:type => CreditCardValidator::Validator.card_type(card_number), | |
:number => card_number, | |
:expire_month => card_expiration_date.split('/').first, | |
:expire_year => card_expiration_date.split('/').last, | |
:cvv2 => card_cvv, | |
:first_name => student.first_name, | |
:last_name => student.last_name, | |
:billing_address => { | |
:line1 => card_street_address, | |
:city => card_city, | |
:state => card_state, | |
:postal_code => card_zipcode, | |
:country_code => "US" }}}]}, | |
:transactions => [{ | |
:amount => { | |
:total => ("%.2f" % student_cart.total), | |
:currency => "USD" }, | |
:description => "Online course payment" }]}) | |
if @payment.create | |
self.transaction_id = @payment.id | |
self.amount = @payment.transactions.first.amount.total.to_f | |
self.status = "settled" | |
self.payment_type = "Online CC" | |
true | |
else | |
self.status = @payment.error | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment