Skip to content

Instantly share code, notes, and snippets.

@sanchojaf
Last active August 29, 2015 14:04
Show Gist options
  • Save sanchojaf/47c5f149b8f651125f2a to your computer and use it in GitHub Desktop.
Save sanchojaf/47c5f149b8f651125f2a to your computer and use it in GitHub Desktop.
for send credit card through wombat
#spree_wombat
#===========
require 'active_model/serializer'
module Spree
module Wombat
class SourceSerializer < ActiveModel::Serializer
attributes :name, :cc_type, :last_digits, :month, :year
def name
object.name
end
def cc_type
object.cc_type
end
def last_digits
object.last_digits
end
def month
object.month
end
def year
object.year
end
end
end
end
#Spree
#======
#Spree::Core::Importer::Order
module Spree
module Core
module Importer
class Order
...
def self.create_payments_from_params(payments_hash, order)
return [] unless payments_hash
payments_hash.each do |p|
begin
payment = order.payments.build order: order
payment.amount = p[:amount].to_f
# Order API should be using state as that's the normal payment field.
# spree_wombat serializes payment state as status so imported orders should fall back to status field.
payment.state = p[:state] || p[:status] || 'completed'
payment.payment_method = Spree::PaymentMethod.find_by_name!(p[:payment_method])
payment.source = create_source_payment_from_params(p[:source], payment)
payment.save!
rescue Exception => e
raise "Order import payments: #{e.message} #{p}"
end
end
end
def self.create_source_payment_from_params(source_hash, payment)
s = source_hash
begin
cc = Spree::CreditCard.new(month: s[:month], year: s[:year], cc_type: s[:cc_type],
last_digits: s[:last_digists], name: s[:mame])
cc.payment_method = payment.payment_method
cc.save
rescue Exception => e
raise "Order import source payments: #{e.message} #{s}"
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment