Class: SpreeUsaEpay::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/spree_usa_epay/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
# File 'lib/spree_usa_epay/client.rb', line 5

def initialize(options)
  @source_key = options[:source_key]
  @pin = options[:pin]
  @test_mode = options[:test_mode]
  @client = Savon::Client.new(soap_url)
end

Instance Attribute Details

#pinObject

Returns the value of attribute pin.



3
4
5
# File 'lib/spree_usa_epay/client.rb', line 3

def pin
  @pin
end

#source_keyObject

Returns the value of attribute source_key.



3
4
5
# File 'lib/spree_usa_epay/client.rb', line 3

def source_key
  @source_key
end

#test_modeObject

Returns the value of attribute test_mode.



3
4
5
# File 'lib/spree_usa_epay/client.rb', line 3

def test_mode
  @test_mode
end

Instance Method Details

#add_customer(amount, creditcard, gateway_options) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/spree_usa_epay/client.rb', line 42

def add_customer(amount, creditcard, gateway_options)
  token = security_token(gateway_options)
  customer = customer_data(amount, creditcard, gateway_options)

  response = request(:add_customer, { "Token" => token, "CustomerData" => customer })
  response[:add_customer_response][:add_customer_return]
end

#authorize(amount, creditcard, gateway_options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/spree_usa_epay/client.rb', line 22

def authorize(amount, creditcard, gateway_options)
  if creditcard.gateway_customer_profile_id?
    run_customer_transaction('AuthOnly', amount, creditcard, gateway_options)
  else
    token = security_token(gateway_options)
    request = transaction_request_object(amount, creditcard, gateway_options)
    response = request(:run_auth_only, { "Token" => token, "Params" => request })
    billing_response response[:run_auth_only_response][:run_auth_only_return]
  end
end

#capture(payment, creditcard, gateway_options) ⇒ Object



51
52
53
54
# File 'lib/spree_usa_epay/client.rb', line 51

def capture(payment, creditcard, gateway_options)
  amount = (payment.amount * 100).round
  run_customer_transaction('Sale', amount, creditcard, gateway_options)
end

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



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/spree_usa_epay/client.rb', line 56

def credit(amount, creditcard, response_code, gateway_options)
  if creditcard.gateway_customer_profile_id?
    run_customer_transaction('Credit', amount, creditcard, gateway_options)
  else
    token = security_token(gateway_options)
    request = transaction_request_object(amount, creditcard, gateway_options)

    response = request(:run_credit, { "Token" => token, "Params" => request })
    billing_response response[:run_credit_response][:run_credit_return]
  end
end

#purchase(amount, creditcard, gateway_options) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/spree_usa_epay/client.rb', line 34

def purchase(amount, creditcard, gateway_options)
  token = security_token(gateway_options)
  request = transaction_request_object(amount, creditcard, gateway_options)

  response = request(:run_transaction, { "Token" => token, "Params" => request })
  billing_response response[:run_transaction_response][:run_transaction_return]
end

#request(name, body) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/spree_usa_epay/client.rb', line 12

def request(name, body)
  begin
    @client.request name do 
      soap.body = body 
    end
  rescue Exception => e
    raise Spree::Core::GatewayError.new(e.message)
  end
end

#void(response_code, gateway_options) ⇒ Object



68
69
70
71
72
# File 'lib/spree_usa_epay/client.rb', line 68

def void(response_code, gateway_options)
  response = request(:void_transaction, { "Token" => security_token(gateway_options), "RefNum" => response_code })
  success = response[:void_transaction_response][:void_transaction_return] #just returns true
  ActiveMerchant::Billing::Response.new(success, "", {}, {})
end