Module: UnionpayOpen

Defined in:
lib/unionpay_open.rb,
lib/unionpay_open/wap.rb,
lib/unionpay_open/base.rb,
lib/unionpay_open/version.rb

Defined Under Namespace

Classes: Wap

Constant Summary collapse

ENDPOINT_DEV =
'https://101.231.204.80:5000/gateway/api/'
ENDPOINT_PRO =
'https://gateway.95516.com/gateway/api/'
Base =
Class.new do
  class << self

    def faraday
      Faraday.new(@@endpoint, :ssl => {:verify => false})
    end

    def sign(data)
      Base64.strict_encode64(
        @@pkcs12.key.sign(OpenSSL::Digest::SHA1.new,
                          Digest::SHA1.hexdigest(data)) )
    end

    def global_fixed_params
      { version: '5.0.0',
        encoding: 'UTF-8',
        txnTime: Time.now.strftime("%Y%m%d%H%M%S"),
        certId: @@pkcs12.certificate.serial.to_s,
        merId: @@merchant_no }
    end

  end
end
VERSION =
"0.1.0"
@@env =
ENV['RACK_ENV']
@@endpoint =
( @@env == "production" ? ENDPOINT_PRO : ENDPOINT_DEV )

Class Method Summary collapse

Class Method Details

.config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (UnionpayOpen)

    the object that the method was called on



20
21
22
23
24
25
26
27
28
# File 'lib/unionpay_open.rb', line 20

def config
  yield(self) if block_given?

  @@endpoint = ENDPOINT_PRO if @@env == "production"
  @@x509_certificate = OpenSSL::X509::Certificate.new(File.read(@@ca_file)) if @@ca_file
  if @@pfx_file and @@pfx_file_password
    @@pkcs12 = OpenSSL::PKCS12.new( File.read(@@pfx_file), @@pfx_file_password )
  end
end

.fen2yuan(amount) ⇒ Object

10fen = 0.1yuan; 100fen = 1.0yuan



30
31
32
33
# File 'lib/unionpay_open.rb', line 30

def fen2yuan(amount) # 10fen = 0.1yuan; 100fen = 1.0yuan
  value = "00" + amount.to_s
  [ value[0..-3], value[-2..-1] ].join('.').to_f
end

.yuan2fen(amount) ⇒ Object

100yuan = 10000fen



35
36
37
38
39
40
41
42
43
# File 'lib/unionpay_open.rb', line 35

def yuan2fen(amount)  # 100yuan = 10000fen
  value = amount.to_s.split('.')

  return (value.first + "00").to_i if value.size == 1

  a, b = value.first, value.last
  (b += "0") if b.size == 1
  (a + b[0..1]).to_i
end