一个用于银联手机支付的GEM介绍

最新更新请看 https://github.com/oldfritter/upmp.git

A simple upmp ruby gem, without unnecessary magic or wraper, it's directly facing how upmp api works.

 

Installation

Add this line to your application's Gemfile:

gem 'upmp', :git => 'https://github.com/oldfritter/upmp'

And then execute:

$ bundle

Usage

Config

  Upmp.store_no = 'your number' #商户合作号
  Upmp.key = 'your key' #商户的KEY
  Upmp.UPMP_TRADE_URL = '222.66.233.198' #银联的网关(此处为测试网关)

 

Generate payment url

@options = {
        merId: Upmp.store_no,
        backEndUrl: "call_back_url",
        frontEndUrl: "call_back_url",
        # acqCode: '',
        orderTime: Time.now.strftime('%Y%m%d%H%M%S'),
        orderTimeout: 1.hour.from_now.localtime.strftime('%Y%m%d%H%M%S'),
        orderNumber: order.payment_sn,
        orderAmount: order.total_fee,
        orderCurrency: order.currency_code
      }

      http = Net::HTTP.new(Upmp.UPMP_TRADE_URL, 8080)
      response = http.post('/gateway/merchant/trade', Upmp::Service.mobile_payment_control(@option))
      tn = response.body #获取交易的流水号

result_url = CGI.escape "#{SITE_ROOT}/utility/upmp_success?payment_sn=#{payment_sn}&result="
    order_info = "tn=#{params},resultURL=#{result_url},usetestmode=true"
    render text: "<a href='uppay://uppayservice/?style=token&paydata=#{CGI.escape(Base64.encode64(order_info))}'><img src='/assets/yinlian.jpg' alt='银联手机支付' style='width: 300px; height: 200px;'/></a>".html_safe #返回一个跳转页面,点击银联的图标以启动银联的app

 

你可能感兴趣的:(Ruby,银联,upmp)