Class: Gateway::Samurai

Inherits:
Gateway
  • Object
show all
Defined in:
app/models/spree/gateway/samurai.rb

Instance Method Summary collapse

Instance Method Details

#authorize(money, creditcard, gateway_options) ⇒ Object



24
25
26
27
28
29
# File 'app/models/spree/gateway/samurai.rb', line 24

def authorize(money, creditcard, gateway_options)
  gateway_options[:billing_reference] = gateway_options[:order_id]
  gateway_options[:customer_reference] = gateway_options[:customer]
  gateway_options[:description] = "Spree Order"
  provider.authorize(money, creditcard.gateway_customer_profile_id, gateway_options)
end

#capture(authorization, creditcard, gateway_options) ⇒ Object



31
32
33
34
35
36
# File 'app/models/spree/gateway/samurai.rb', line 31

def capture(authorization, creditcard, gateway_options)
  gateway_options[:billing_reference] = gateway_options[:order_id]
  gateway_options[:customer_reference] = gateway_options[:customer]
  gateway_options[:description] = "Spree Order"
  provider.capture(nil, authorization.response_code, {})
end

#create_profile(payment) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/spree/gateway/samurai.rb', line 46

def create_profile(payment)
  return unless payment.source.gateway_customer_profile_id.nil?

  options = {}
  options[:email] = payment.order.email
  options[:address] = {}
  options[:address][:address1] = payment.order.bill_address.address1
  options[:address][:address2] = payment.order.bill_address.address2
  options[:address][:city] = payment.order.bill_address.city
  options[:address][:state] = payment.order.bill_address.state.abbr
  options[:address][:zip] = payment.order.bill_address.zipcode
  response = provider.store(payment.source, options)
  if response.success?
    payment.source.update_attributes!(:gateway_customer_profile_id => response.params['payment_method_token'])
  else
    payment.send(:gateway_error, response.message)
  end
end

#credit(money, creditcard, response_code, gateway_options) ⇒ Object



38
39
40
# File 'app/models/spree/gateway/samurai.rb', line 38

def credit(money, creditcard, response_code, gateway_options)
  provider.credit(money, response_code, {})
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/models/spree/gateway/samurai.rb', line 13

def payment_profiles_supported?
  true
end

#provider_classObject



9
10
11
# File 'app/models/spree/gateway/samurai.rb', line 9

def provider_class
  ActiveMerchant::Billing::SamuraiGateway
end

#purchase(money, creditcard, gateway_options) ⇒ Object



17
18
19
20
21
22
# File 'app/models/spree/gateway/samurai.rb', line 17

def purchase(money, creditcard, gateway_options)
  gateway_options[:billing_reference] = gateway_options[:order_id]
  gateway_options[:customer_reference] = gateway_options[:customer]
  gateway_options[:description] = "Spree Order"
  provider.purchase(money, creditcard.gateway_customer_profile_id, gateway_options)
end

#void(response_code, gateway_options) ⇒ Object



42
43
44
# File 'app/models/spree/gateway/samurai.rb', line 42

def void(response_code, gateway_options)
  provider.void(response_code, {})
end