Class: Gestpay::Gateway

Inherits:
Object
  • Object
show all
Includes:
CustomInfo
Defined in:
lib/gestpay/gateway.rb

Constant Summary collapse

URL =
{
  :test       => 'https://testecomm.sella.it/gestpay/gestpayws/WSs2s.asmx?WSDL',
  :production => 'https://ecomms2s.sella.it/gestpay/gestpayws/WSs2s.asmx?WSDL'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CustomInfo

#gestpay_decode, #gestpay_encode

Constructor Details

#initializeGateway

Returns a new instance of Gateway.



16
17
18
19
20
21
22
23
24
# File 'lib/gestpay/gateway.rb', line 16

def initialize
  # SOAP Client operations:
  # => [:call_refund_s2_s, :call_read_trx_s2_s, :call_pagam_s2_s, :call_delete_s2_s, :call_settle_s2_s, :call_verifycard_s2_s, :call_check_carta_s2_s, :call_renounce, :call_request_token_s2_s, :call_delete_token_s2_s]
  savon_options = {:wsdl => URL[Gestpay.config.environment]}
  if Gestpay.config.proxy
    savon_options.merge!({ :proxy=> URI.parse(Gestpay.config.proxy)})
  end
  @client = Savon.client(savon_options)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



15
16
17
# File 'lib/gestpay/gateway.rb', line 15

def client
  @client
end

Instance Method Details

#configObject



11
12
13
# File 'lib/gestpay/gateway.rb', line 11

def config
  Gestpay.config
end

#delete(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/gestpay/gateway.rb', line 67

def delete(data)
  data[:Bank_transaction_id] ||= data.delete(:bank_transaction_id)
  data[:Shop_transaction_id] ||= data.delete(:shop_transaction_id)

  data = Hash[data.select { |k, v| v.present? }]

  response = @client.call(:call_delete_s2_s, soap_options(data, [:shop_login]))
  response_content = response.body[:call_delete_s2_s_response][:call_delete_s2_s_result][:gest_pay_s2_s]
  Result::Delete.new(response_content)
end

#payment(data) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/gestpay/gateway.rb', line 38

def payment(data)
  # Custom info must be enabled on Gestpay backoffice interface, by adding new parameters
  data[:custom_info] = gestpay_encode(data[:custom_info]) if data[:custom_info]
  response = @client.call(:call_pagam_s2_s, soap_options(data))
  response_content = response.body[:call_pagam_s2_s_response][:call_pagam_s2_s_result][:gest_pay_s2_s]
  Result::Payment.new(response_content)
end

#request_token(data, verify = true) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/gestpay/gateway.rb', line 46

def request_token(data, verify=true)
  opts = {
    :request_token => 'MASKEDPAN',
    :with_auth => verify ? 'Y' : 'N'
  }
  response = @client.call(:call_request_token_s2_s, soap_options(data.merge(opts)))
  response_content = response.body[:call_request_token_s2_s_response][:call_request_token_s2_s_result][:gest_pay_s2_s]
  Result::TokenRequest.new(response_content)
end

#settle(data) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/gestpay/gateway.rb', line 56

def settle(data)
  data[:bank_trans_ID] ||= data.delete(:bank_trans_id)
  data[:shop_trans_ID] ||= data.delete(:shop_trans_id)

  data = Hash[data.select { |k, v| v.present? }]

  response = @client.call(:call_settle_s2_s, soap_options(data, [:shop_login, :uic_code]))
  response_content = response.body[:call_settle_s2_s_response][:call_settle_s2_s_result][:gest_pay_s2_s]
  Result::Settle.new(response_content)
end

#soap_options(data, options = [:shop_login, :uic_code, :language_id]) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gestpay/gateway.rb', line 26

def soap_options(data, options = [:shop_login, :uic_code, :language_id])
  configuration_options = {
    :shop_login  => config.,
    :uic_code    => config.currency_code,
    :language_id => config.language_code
  }

  {
    :message => configuration_options.slice(*options).merge(data)
  }
end