ruby实现桌面端银联支付

8 篇文章 0 订阅
1 篇文章 0 订阅

Installation

Add this line to your application's Gemfile:

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

And then execute:

$ bundle install

Usage

Config

  Upop.store_no = '105550149170027' # Your store NO.
  Upop.store_name = '上海一树网络科技有限公司' # Your company name.
  Upop.key = '88888888' # Your key.
  Upop.UPOP_TRADE_URL = 'http://58.246.226.99' # This is the test Gateway.

Generate payment options

      @option = {
        merId: Upop.store_no, 
        backEndUrl: orders.first.call_back_url{payment = 'upop'}, 
        frontEndUrl: orders.first.call_back_url{payment = 'upop'}, 
        orderTime: Time.now.strftime('%Y%m%d%H%M%S'), 
        orderNumber: orders.first.payment_sn, 
        orderAmount: (orders.collect{|order|order.order_total_price}.sum * 100).to_i, 
        orderCurrency: 156, 
        customerIp: orders.first.customer.ip
      } # 构建option

      @options = Upop::Service.desktop_payment @option

Payment form

<form id="union_pay_form" action="<%= Upop.UPOP_TRADE_URL %>/UpopWeb/api/Pay.action" method='POST'>
  <input type="hidden" name='backEndUrl'            value='<%= @options['backEndUrl'] %>'/>
  <input type="hidden" name='charset'               value='<%= @options['charset'] %>'/>
  <input type="hidden" name='customerIp'        value='<%= @options['customerIp'] %>'/>
  <input type="hidden" name='frontEndUrl'       value='<%= @options['frontEndUrl'] %>'/>
  <input type="hidden" name='merAbbr'               value='<%= @options['merAbbr'] %>'/>
  <input type="hidden" name='merId'                 value='<%= @options['merId'] %>'/>
  <input type="hidden" name='orderAmount'       value='<%= @options['orderAmount'] %>'/>
  <input type="hidden" name='orderCurrency' value='<%= @options['orderCurrency'] %>'/>
  <input type="hidden" name='orderNumber'       value='<%= @options['orderNumber'] %>'/>
  <input type="hidden" name='orderTime'         value='<%= @options['orderTime'] %>'/>
  <input type="hidden" name='orderTimeout'      value='<%= @options['orderTimeout'] %>'/>
  <input type="hidden" name='signMethod'            value='<%= @options['signMethod'] %>'/>
  <input type="hidden" name='signature'         value='<%= @options['signature'] %>'/>
  <input type="hidden" name='transType'         value='<%= @options['transType'] %>'/>
  <input type="hidden" name='version'               value='<%= @options['version'] %>'/>
    <input type='submit'/>
</form>

 

Verify

   def upop_notify
      return false unless Upop::Sign.verify? params.except('action', 'controller')
            # Do something.
      render text: 'success'
    end

    def upop_success
      return false unless Upop::Sign.verify? params.except('action', 'controller')
      # Do something.
      redirect_to #your success page.
    end

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值