Code Monkey home page Code Monkey logo

wxpay's Introduction

README

This README would normally document whatever steps are necessary to get the application up and running.

Things you may want to cover:

  • Ruby version 2.5.1

  • System dependencies

  • Configuration

    1. 支持多账号 账号设定
      wxpay:
        accounts:
          - appid: xxxxxx
            mch_id: xxxxxx
            key: xxxxxx
            notify_url: xxxxx
            package: Sign=WXPay
    1. 创建支付订单

    其中有以下的支付方式

      # 扫码 支付参数
      def wxpay_code_params(**params)
        {
          no:               params[:no],
          body:             params[:body],
          kind:             "code",
          appid:            params[:appid],
          total_fee:        params[:total_fee],
          out_trade_no:     params[:transaction_no],
          spbill_create_ip: params[:remote_ip]
        }
      end
    
      # H5 支付参数
      def wxpay_h5_params(**params)
        {
          no:               params[:no],
          body:             params[:body],
          kind:             'h5',
          appid:            params[:appid],
          total_fee:        params[:total_fee],
          out_trade_no:     params[:transaction_no],
          spbill_create_ip: params['remote_ip'],
          scene_info: {
            h5_info: {
              type: "Wap",
              wap_url: params[:host],
              wap_name: "订单付款"
            }
          }
        }
      end
    
      # APP 支付参数
      def wxpay_app_params(**params)
        {
          no:                params[:no],
          body:              params[:body],
          out_trade_no:      params[:transaction_no],
          total_fee:         params[:total_fee],
          spbill_create_ip:  params[:remote_ip],
          kind:             'app',
          appid:            params[:appid],
        }
      end
    
      # 小程序 支付参数
      #
      def wxpay_small_params(**params)
        {
          no:               params[:no],
          body:             params[:body],
          spbill_create_ip: params[:remote_ip],
          out_trade_no:     params[:transaction_no],
          total_fee:        params[:total_fee],
          appid:            params[:appid],
          openid:           params[:openid],
          kind:             'applets',
        }
      end
    
      ## 公众号 支付参数
      def wxpay_pub_params(**params)
        {
          no:               params[:no],
          body:             params[:body],
          spbill_create_ip: params[:remote_ip],
          out_trade_no:     params[:transaction_no],
          total_fee:        params[:total_fee],
          appid:            params[:appid],
          openid:           params[:openid],
          kind:             'pub'
        }
      end
    
      # 下单
      Wechat::MainService.new.create("wxpay_#{_kind.downcase}_params")
    1. 退款
      def wechat_pay_refund(params = {})
        wxpay = Wxpay.find_by(out_transaction_no: "xxxx")
    
        params = {
          out_refund_no:  params[:out_refund_no],         # 退款单号,一个单号 只能退一次
          total_fee:      params[:total_fee],             # 总支付金额
          refund_fee:     params[:refund_fee],            # 退款金额
          out_trade_no:   wxpay.try(:out_transaction_no), # 支付单号
        }
        result = Wechat::MainService.new
        response = result.refund(params)
      end
    1. 回调
    1. 首先微信的回调都是xml,如果是 用grape的话 需要指定 content_type ,format 最重要的是指定 status 为 200 ,默认post是201 ,导致 微信回调返回失败
  • Database creation

  • Database initialization

  • How to run the test suite

  • Services (job queues, cache servers, search engines, etc.)

  • Deployment instructions

  • ...

wxpay's People

Contributors

xunzi229 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.