一个用于银联支付的GEM介绍_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > 一个用于银联支付的GEM介绍

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

 2014/4/15 16:24:16  南京老油条  程序员俱乐部  我要评论(0)
  • 摘要:Asimpleupmprubygem,withoutunnecessarymagicorwraper,it'sdirectlyfacinghowupmpapiworks.InstallationAddthislinetoyourapplication'sGemfile:gem'upmp',:git=>'https://github.com/oldfritter/upmp'Andthenexecute:$bundleUsageConfigUpmp
  • 标签:Gem 一个

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

class="ruby" name="code">  Upmp.store_no = '880000000001094' #商户合作号
  Upmp.key = 'ETXboGTeXVems2CD655WVSM0qAO122P4' #商户的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 = URI.encode "#{SITE_ROOT}/mobile/upmp_success?payment_sn=#{payment_sn}&result="
            order_info = "tn=#{params},resultURL=#{result_url},usetestmode=true"
            html =<<EOF
<a href='uppay://uppayservice/?style=token&paydata=#{Base64.encode64(order_info)}'>
<img src='/assets/yinlian.jpg' alt='银联手机支付' style='width: 300px; height: 200px;'/>
</a>
EOF
            render text: html.gsub!.html_safe #返回一个跳转页面,点击银联的图标以启动银联的app

?

发表评论
用户名: 匿名