Class: SpreeUsaEpay::Client
- Inherits:
-
Object
- Object
- SpreeUsaEpay::Client
- Defined in:
- lib/spree_usa_epay/client.rb
Instance Attribute Summary collapse
-
#pin ⇒ Object
Returns the value of attribute pin.
-
#source_key ⇒ Object
Returns the value of attribute source_key.
-
#test_mode ⇒ Object
Returns the value of attribute test_mode.
Instance Method Summary collapse
- #add_customer(amount, creditcard, gateway_options) ⇒ Object
- #authorize(amount, creditcard, gateway_options) ⇒ Object
- #capture(payment, creditcard, gateway_options) ⇒ Object
- #credit(amount, creditcard, response_code, gateway_options) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #purchase(amount, creditcard, gateway_options) ⇒ Object
- #request(name, body) ⇒ Object
- #void(response_code, gateway_options) ⇒ Object
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() @source_key = [:source_key] @pin = [:pin] @test_mode = [:test_mode] @client = Savon::Client.new(soap_url) end |
Instance Attribute Details
#pin ⇒ Object
Returns the value of attribute pin.
3 4 5 |
# File 'lib/spree_usa_epay/client.rb', line 3 def pin @pin end |
#source_key ⇒ Object
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_mode ⇒ Object
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, ) token = security_token() customer = customer_data(amount, creditcard, ) 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 (amount, creditcard, ) if creditcard.gateway_customer_profile_id? run_customer_transaction('AuthOnly', amount, creditcard, ) else token = security_token() request = transaction_request_object(amount, creditcard, ) 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, ) amount = (payment.amount * 100).round run_customer_transaction('Sale', amount, creditcard, ) 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, ) if creditcard.gateway_customer_profile_id? run_customer_transaction('Credit', amount, creditcard, ) else token = security_token() request = transaction_request_object(amount, creditcard, ) 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, ) token = security_token() request = transaction_request_object(amount, creditcard, ) 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.) 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, ) response = request(:void_transaction, { "Token" => security_token(), "RefNum" => response_code }) success = response[:void_transaction_response][:void_transaction_return] #just returns true ActiveMerchant::Billing::Response.new(success, "", {}, {}) end |