Skip to content

Instantly share code, notes, and snippets.

@cannapages
Created January 22, 2015 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cannapages/d06a3470cf7bba5ab7b4 to your computer and use it in GitHub Desktop.
Save cannapages/d06a3470cf7bba5ab7b4 to your computer and use it in GitHub Desktop.
Transaction Model for hemptemps
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