Class: YlPay::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/yl_pay/service.rb

Constant Summary collapse

H5_URI =
'/ppi/h5/plugin/itf.do'.freeze
AUTHORIZE_URI =
'/ppi/merchant/itf.do'.freeze
INVOKE_ORDER_REQUIRED_FIELDS =
[:amount, :order_desc, :client_ip, :merch_order_id, :trade_time]

Class Method Summary collapse

Class Method Details

.check_notify_sign(params) ⇒ Object



38
39
40
41
42
# File 'lib/yl_pay/service.rb', line 38

def self.check_notify_sign(params)
  sign = params.delete('Sign')
  notify_sign = YlPay::Utils.notify_sign(params)
  YlPay::Sign.verify?(notify_sign, sign)
end

.generate_order_url(params, options = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/yl_pay/service.rb', line 11

def self.generate_order_url(params, options = {})
  check_required_options(params, INVOKE_ORDER_REQUIRED_FIELDS)
  params = set_params(params, options)
  result = YlPay::Result.new(Hash.from_xml(invoke_remote(YlPay.payeco_url + AUTHORIZE_URI, make_payload(params))))
  JSON(parse_result(result))
end

.h5_pay_url(params) ⇒ Object



34
35
36
# File 'lib/yl_pay/service.rb', line 34

def self.h5_pay_url(params)
  YlPay.payeco_url + H5_URI + '?tradeId=h5Init' + "&#{params}"
end

.parse_result(result) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/yl_pay/service.rb', line 18

def self.parse_result(result)
  return result.failure unless result.success?

  back_sign = check_back_sign(result.body)
  return result.sign_error unless back_sign

  url = pay_url(back_sign[0] + "&Sign=#{back_sign[1]}")
  result.success(url)
end

.pay_url(params, options = { pay_way: 'h5_pay_url' }) ⇒ Object

根据返回回来的参数,生成去支付页面的url



29
30
31
32
# File 'lib/yl_pay/service.rb', line 29

def self.pay_url(params, options = { pay_way: 'h5_pay_url' })
  pay_way = options.delete(:pay_way)
  send(pay_way, params)
end