Module: CmbPay::Service

Defined in:
lib/cmb_pay/service.rb

Constant Summary collapse

GATEWAY_URL =
{
  production: {
    NP_BindCard:  'https://mobile.cmbchina.com/mobilehtml/DebitCard/M_NetPay/OneNetRegister/NP_BindCard.aspx',
    PrePayEUserP: 'https://netpay.cmbchina.com/netpayment/BaseHttp.dll?PrePayEUserP',
    PrePayC2: 'https://netpay.cmbchina.com/netpayment/BaseHttp.dll?PrePayC2',
    PrePayWAP: 'https://netpay.cmbchina.com/netpayment/BaseHttp.dll?PrePayWAP',
    DirectRequestX: 'https://payment.ebank.cmbchina.com/netpayment/basehttp.dll?DirectRequestX'
  },
  test: {
    NP_BindCard:  'http://61.144.248.29:801/mobilehtml/DebitCard/M_NetPay/OneNetRegister/NP_BindCard.aspx',
    PrePayEUserP: 'http://61.144.248.29:801/netpayment/BaseHttp.dll?PrePayEUserP',
    PrePayC2: 'https://netpay.cmbchina.com/netpayment/BaseHttp.dll?TestPrePayC2',
    PrePayWAP: 'https://netpay.cmbchina.com/netpayment/BaseHttp.dll?TestPrePayWAP',
    DirectRequestX: 'http://218.17.27.197/netpayment/basehttp.dll?DirectRequestX'
  }
}.freeze

Class Method Summary collapse

Class Method Details

.encode_merchant_para(para) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/cmb_pay/service.rb', line 36

def self.encode_merchant_para(para)
  if para.nil?
    ''
  else
    para.to_a.collect { |c| "#{c[0]}=#{c[1]}" }.join '|'
  end
end

.request_gateway_url(api_action) ⇒ Object



20
21
22
# File 'lib/cmb_pay/service.rb', line 20

def self.request_gateway_url(api_action)
  GATEWAY_URL[CmbPay.environment.to_sym][api_action.to_sym]
end

.request_uri(api_action, params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cmb_pay/service.rb', line 24

def self.request_uri(api_action, params)
  uri = URI(request_gateway_url(api_action))
  uri.query = if CmbPay.environment.to_sym == :test && api_action.to_sym == :PrePayC2
                "TestPrePayC2?#{URI.encode_www_form(params)}"
              elsif CmbPay.environment.to_sym == :test && api_action.to_sym == :PrePayWAP
                "TestPrePayWAP?#{URI.encode_www_form(params)}"
              else
                "#{uri.query}?#{URI.encode_www_form(params)}"
              end
  uri
end