wechat-pay 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.github/workflows/code_quality.yml +35 -0
 - data/.gitignore +6 -0
 - data/.rspec +2 -0
 - data/.rubocop.yml +21 -0
 - data/.yardopts +3 -0
 - data/CHANGELOG.md +15 -0
 - data/Gemfile +15 -0
 - data/README.md +92 -0
 - data/Rakefile +19 -0
 - data/lib/wechat-pay.rb +3 -1
 - data/lib/wechat-pay/direct.rb +81 -323
 - data/lib/wechat-pay/ecommerce/applyment.rb +177 -178
 - data/lib/wechat-pay/ecommerce/balance.rb +100 -101
 - data/lib/wechat-pay/ecommerce/bill.rb +1 -0
 - data/lib/wechat-pay/ecommerce/combine_order.rb +42 -176
 - data/lib/wechat-pay/ecommerce/order.rb +34 -105
 - data/lib/wechat-pay/ecommerce/profitsharing.rb +1 -0
 - data/lib/wechat-pay/ecommerce/refund.rb +118 -119
 - data/lib/wechat-pay/ecommerce/subsidies.rb +68 -69
 - data/lib/wechat-pay/ecommerce/withdraw.rb +133 -134
 - data/lib/wechat-pay/helper.rb +2 -1
 - data/lib/wechat-pay/version.rb +1 -1
 - data/wechat-pay.gemspec +27 -0
 - metadata +27 -4
 - data/lib/set_base_envrionment.rb +0 -8
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 97a1465d8d7d51844df252100062b9a93e3fca7ec95ba71b3c6efde5be055fdd
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 79f475e4b12bd326b67ba5eb20600f2c085fbdfbafcab8dc3c6dfc74e904f948
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a4fcb7ab75a019b3de65aae0946bc8db4b3812a651c8ab6652fb2e47bbb31afaf98a10f6d5b6028f81385ac69c319f7f46e872b72b21c1ab0930d8fe36f579b4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 208c39a3eb250aaa7fc13c49d34bc75d093698641b28cb5b992bf33aa825f8c175b8ca3fc4ab9503a11c86f81e0df7628f60fc5669571dc5cb56fb80d8737299
         
     | 
| 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # This workflow uses actions that are not certified by GitHub.
         
     | 
| 
      
 2 
     | 
    
         
            +
            # They are provided by a third-party and are governed by
         
     | 
| 
      
 3 
     | 
    
         
            +
            # separate terms of service, privacy policy, and support
         
     | 
| 
      
 4 
     | 
    
         
            +
            # documentation.
         
     | 
| 
      
 5 
     | 
    
         
            +
            # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
         
     | 
| 
      
 6 
     | 
    
         
            +
            # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            name: Ruby
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            on:
         
     | 
| 
      
 11 
     | 
    
         
            +
              pull_request:
         
     | 
| 
      
 12 
     | 
    
         
            +
                branches: [ master ]
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            jobs:
         
     | 
| 
      
 15 
     | 
    
         
            +
              test:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                runs-on: ubuntu-latest
         
     | 
| 
      
 18 
     | 
    
         
            +
                strategy:
         
     | 
| 
      
 19 
     | 
    
         
            +
                  matrix:
         
     | 
| 
      
 20 
     | 
    
         
            +
                    ruby-version: ['2.6', '2.7', '3.0']
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                steps:
         
     | 
| 
      
 23 
     | 
    
         
            +
                - uses: actions/checkout@v2
         
     | 
| 
      
 24 
     | 
    
         
            +
                - name: Set up Ruby
         
     | 
| 
      
 25 
     | 
    
         
            +
                # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
         
     | 
| 
      
 26 
     | 
    
         
            +
                # change this to (see https://github.com/ruby/setup-ruby#versioning):
         
     | 
| 
      
 27 
     | 
    
         
            +
                # uses: ruby/setup-ruby@v1
         
     | 
| 
      
 28 
     | 
    
         
            +
                  uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
         
     | 
| 
      
 29 
     | 
    
         
            +
                  with:
         
     | 
| 
      
 30 
     | 
    
         
            +
                    ruby-version: ${{ matrix.ruby-version }}
         
     | 
| 
      
 31 
     | 
    
         
            +
                    bundler-cache: true # runs 'bundle install' and caches installed gems automatically
         
     | 
| 
      
 32 
     | 
    
         
            +
                - name: Run rubocop
         
     | 
| 
      
 33 
     | 
    
         
            +
                  run: bundle exec rubocop
         
     | 
| 
      
 34 
     | 
    
         
            +
                - name: Run tests
         
     | 
| 
      
 35 
     | 
    
         
            +
                  run: bundle exec rake
         
     | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.rubocop.yml
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            AllCops:
         
     | 
| 
      
 2 
     | 
    
         
            +
              NewCops: enable
         
     | 
| 
      
 3 
     | 
    
         
            +
              SuggestExtensions: false
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Style/AsciiComments:
         
     | 
| 
      
 6 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            Metrics/BlockLength:
         
     | 
| 
      
 9 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            Metrics/AbcSize:
         
     | 
| 
      
 12 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            Metrics/MethodLength:
         
     | 
| 
      
 15 
     | 
    
         
            +
              Max: 30
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            Layout/LineLength:
         
     | 
| 
      
 18 
     | 
    
         
            +
              Enabled: false
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            Metrics/ModuleLength:
         
     | 
| 
      
 21 
     | 
    
         
            +
              Max: 200
         
     | 
    
        data/.yardopts
    ADDED
    
    
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Next Release
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## 1.1.0 (07/26/2021)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            * Fix `Accept-Encoding` issue in wechat.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            ## 1.0.8 (05/26/2021)
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            * Add api `invoke_transactions_in_native` to `WechatPay::Ecommerce`
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## 1.0.7 (05/16/2021)
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            * Change `WechatPay::Ecommerce.get_certificates` to `WechatPay::Ecommerce.certificates`
         
     | 
| 
      
 15 
     | 
    
         
            +
            * Refactor code and document.
         
     | 
    
        data/Gemfile
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            source 'https://rubygems.org'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            # Declare your gem's dependencies in tenpay.gemspec.
         
     | 
| 
      
 6 
     | 
    
         
            +
            # Bundler will treat runtime dependencies like base dependencies, and
         
     | 
| 
      
 7 
     | 
    
         
            +
            # development dependencies will be added by default to the :development group.
         
     | 
| 
      
 8 
     | 
    
         
            +
            gemspec
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            # Declare any dependencies that are still in development here instead of in
         
     | 
| 
      
 11 
     | 
    
         
            +
            # your gemspec. These might include edge Rails or gems from your path or
         
     | 
| 
      
 12 
     | 
    
         
            +
            # Git. Remember to move these dependencies to your gemspec before releasing
         
     | 
| 
      
 13 
     | 
    
         
            +
            # your gem to rubygems.org.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            # To use debugger
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,92 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Wechat Pay
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            A simple Wechat pay ruby gem, without unnecessary magic or wrapper. Just a simple wrapper for api V3. Refer to [wx_pay](https://github.com/jasl/wx_pay)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Please read official document first: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/pages/index.shtml
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            If you want check the present public api, you can find them in the [Document](https://www.rubydoc.info/github/lanzhiheng/wechat-pay/master/index)。
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            Summary:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            `WechatPay::Direct` will contain the public api for direct connection merchant(直连商户)and `WechatPay::Ecommerce` will contain the public api for ecommerce(服务商,电商平台)。For more detail you can refer to the wechat document.
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            - 直连商户: https://pay.weixin.qq.com/wiki/doc/apiv3/index.shtml
         
     | 
| 
      
 14 
     | 
    
         
            +
            - 服务商: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/index.shtml
         
     | 
| 
      
 15 
     | 
    
         
            +
            - 电商平台(电商收付通): https://pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter3_3_3.shtml
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            If you find any issue in this repo, don't shy to create issues https://github.com/lanzhiheng/wechat-pay/issues
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            For more Information,you can check my posts: https://www.lanzhiheng.com/posts/preview/ruby-gem-for-wechat-pay-v3
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            # Installation
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            Add this line to your Gemfile:
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ```
         
     | 
| 
      
 26 
     | 
    
         
            +
            gem 'wechat-pay'
         
     | 
| 
      
 27 
     | 
    
         
            +
            ```
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            or development version
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            ```
         
     | 
| 
      
 32 
     | 
    
         
            +
            gem 'wechat-pay', :github => 'lanzhiheng/wechat-pay'
         
     | 
| 
      
 33 
     | 
    
         
            +
            ```
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            ```
         
     | 
| 
      
 38 
     | 
    
         
            +
            $ bundle
         
     | 
| 
      
 39 
     | 
    
         
            +
            ```
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            # Usage
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            ## Configuration
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            Create `config/initializer/wechat_pay.rb`and put following configurations into it
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            ``` ruby
         
     | 
| 
      
 48 
     | 
    
         
            +
            WechatPay.apiclient_key = File.read('apiclient_key.pem')
         
     | 
| 
      
 49 
     | 
    
         
            +
            WechatPay.platform_cert = File.read('platform_cert.pem') # You should comment this line before downloaded platform_cert.
         
     | 
| 
      
 50 
     | 
    
         
            +
            WechatPay.apiclient_cert = File.read('apiclient_cert.pem')
         
     | 
| 
      
 51 
     | 
    
         
            +
            WechatPay.app_id = 'Your App Id'
         
     | 
| 
      
 52 
     | 
    
         
            +
            WechatPay.mch_id = 'Your Mch Id'
         
     | 
| 
      
 53 
     | 
    
         
            +
            WechatPay.mch_key = 'Your Mch Key'
         
     | 
| 
      
 54 
     | 
    
         
            +
            ```
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            ## Download
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            I will provide a simple script for you to download the platform_cert
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            ``` ruby
         
     | 
| 
      
 61 
     | 
    
         
            +
            def download_certificate
         
     | 
| 
      
 62 
     | 
    
         
            +
              download_path = 'Your Download Path'
         
     | 
| 
      
 63 
     | 
    
         
            +
              raise '必须提供证书下载路径' if download_path.blank?
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              response = WechatPay::Ecommerce.certificates
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
              raise '证书下载失败' unless response.code == 200
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
              result = JSON.parse(response.body)
         
     | 
| 
      
 70 
     | 
    
         
            +
              # 需要按生效日期进行排序,获取最新的证书
         
     | 
| 
      
 71 
     | 
    
         
            +
              array = result['data'].sort_by { |item| -Time.parse(item['effective_time']).to_i }
         
     | 
| 
      
 72 
     | 
    
         
            +
              current_data = array.first
         
     | 
| 
      
 73 
     | 
    
         
            +
              encrypt_certificate = current_data['encrypt_certificate']
         
     | 
| 
      
 74 
     | 
    
         
            +
              associated_data = encrypt_certificate['associated_data']
         
     | 
| 
      
 75 
     | 
    
         
            +
              nonce = encrypt_certificate['nonce']
         
     | 
| 
      
 76 
     | 
    
         
            +
              ciphertext = encrypt_certificate['ciphertext']
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              content = WechatPay::Sign.decrypt_the_encrypt_params(
         
     | 
| 
      
 79 
     | 
    
         
            +
                associated_data: associated_data,
         
     | 
| 
      
 80 
     | 
    
         
            +
                nonce: nonce,
         
     | 
| 
      
 81 
     | 
    
         
            +
                ciphertext: ciphertext
         
     | 
| 
      
 82 
     | 
    
         
            +
              )
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              File.open(download_path, 'w') do |f|
         
     | 
| 
      
 85 
     | 
    
         
            +
                f.write(content)
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              puts '证书下载成功'
         
     | 
| 
      
 89 
     | 
    
         
            +
            end
         
     | 
| 
      
 90 
     | 
    
         
            +
            ```
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              require 'bundler/setup'
         
     | 
| 
      
 5 
     | 
    
         
            +
              require 'rspec/core/rake_task'
         
     | 
| 
      
 6 
     | 
    
         
            +
              RSpec::Core::RakeTask.new(:spec)
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              task default: :spec
         
     | 
| 
      
 9 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 10 
     | 
    
         
            +
              puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            require 'rdoc/task'
         
     | 
| 
      
 14 
     | 
    
         
            +
            Rake::RDocTask.new do |rdoc|
         
     | 
| 
      
 15 
     | 
    
         
            +
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
      
 16 
     | 
    
         
            +
              rdoc.title = "wechat-pay #{WechatPay::VERSION}"
         
     | 
| 
      
 17 
     | 
    
         
            +
              rdoc.rdoc_files.include('README*')
         
     | 
| 
      
 18 
     | 
    
         
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/wechat-pay.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # rubocop:disable Naming/FileName
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            require 'restclient'
         
     | 
| 
         @@ -8,7 +10,6 @@ require 'wechat-pay/ecommerce' # 电商平台 
     | 
|
| 
       8 
10 
     | 
    
         
             
            # # 微信支付
         
     | 
| 
       9 
11 
     | 
    
         
             
            #
         
     | 
| 
       10 
12 
     | 
    
         
             
            # 设置关键信息
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
13 
     | 
    
         
             
            module WechatPay
         
     | 
| 
       13 
14 
     | 
    
         
             
              class<< self
         
     | 
| 
       14 
15 
     | 
    
         
             
                attr_accessor :app_id, :mch_id, :mch_key
         
     | 
| 
         @@ -40,3 +41,4 @@ module WechatPay 
     | 
|
| 
       40 
41 
     | 
    
         
             
                end
         
     | 
| 
       41 
42 
     | 
    
         
             
              end
         
     | 
| 
       42 
43 
     | 
    
         
             
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
            # rubocop:enable Naming/FileName
         
     | 
    
        data/lib/wechat-pay/direct.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'json'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'wechat-pay/helper'
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
         @@ -7,183 +9,80 @@ module WechatPay 
     | 
|
| 
       7 
9 
     | 
    
         
             
              module Direct
         
     | 
| 
       8 
10 
     | 
    
         
             
                include WechatPayHelper
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                #  
     | 
| 
       12 
     | 
    
         
            -
                #
         
     | 
| 
       13 
     | 
    
         
            -
                # 
     | 
| 
       14 
     | 
    
         
            -
                #
         
     | 
| 
       15 
     | 
    
         
            -
                #
         
     | 
| 
       16 
     | 
    
         
            -
                # 
     | 
| 
       17 
     | 
    
         
            -
                #
         
     | 
| 
       18 
     | 
    
         
            -
                #  
     | 
| 
       19 
     | 
    
         
            -
                #
         
     | 
| 
       20 
     | 
    
         
            -
                #  
     | 
| 
       21 
     | 
    
         
            -
                #  
     | 
| 
       22 
     | 
    
         
            -
                # 
     | 
| 
       23 
     | 
    
         
            -
                # 
     | 
| 
       24 
     | 
    
         
            -
                #      
     | 
| 
       25 
     | 
    
         
            -
                # 
     | 
| 
       26 
     | 
    
         
            -
                # 
     | 
| 
       27 
     | 
    
         
            -
                #     {
         
     | 
| 
       28 
     | 
    
         
            -
                #        
     | 
| 
       29 
     | 
    
         
            -
                # 
     | 
| 
       30 
     | 
    
         
            -
                # 
     | 
| 
       31 
     | 
    
         
            -
                # 
     | 
| 
       32 
     | 
    
         
            -
                # 
     | 
| 
       33 
     | 
    
         
            -
                # 
     | 
| 
       34 
     | 
    
         
            -
                # 
     | 
| 
       35 
     | 
    
         
            -
                # 
     | 
| 
       36 
     | 
    
         
            -
                # 
     | 
| 
       37 
     | 
    
         
            -
                 
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                 
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                ##
         
     | 
| 
       46 
     | 
    
         
            -
                # :singleton-method: invoke_combine_transactions_in_js
         
     | 
| 
       47 
     | 
    
         
            -
                #
         
     | 
| 
       48 
     | 
    
         
            -
                # js合单
         
     | 
| 
       49 
     | 
    
         
            -
                #
         
     | 
| 
       50 
     | 
    
         
            -
                # 直连合单js下单
         
     | 
| 
       51 
     | 
    
         
            -
                #
         
     | 
| 
       52 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_3.shtml
         
     | 
| 
       53 
     | 
    
         
            -
                #
         
     | 
| 
       54 
     | 
    
         
            -
                # Example:
         
     | 
| 
       55 
     | 
    
         
            -
                #
         
     | 
| 
       56 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       57 
     | 
    
         
            -
                # params = {
         
     | 
| 
       58 
     | 
    
         
            -
                #   combine_out_trade_no: 'combine_out_trade_no',
         
     | 
| 
       59 
     | 
    
         
            -
                #   combine_payer_info: {
         
     | 
| 
       60 
     | 
    
         
            -
                #     openid: 'client open id'
         
     | 
| 
       61 
     | 
    
         
            -
                #   },
         
     | 
| 
       62 
     | 
    
         
            -
                #   sub_orders: [
         
     | 
| 
       63 
     | 
    
         
            -
                #     {
         
     | 
| 
       64 
     | 
    
         
            -
                #       mchid: 'mchid',
         
     | 
| 
       65 
     | 
    
         
            -
                #       sub_mchid: 'sub mchid',
         
     | 
| 
       66 
     | 
    
         
            -
                #       attach: 'attach',
         
     | 
| 
       67 
     | 
    
         
            -
                #       amount: {
         
     | 
| 
       68 
     | 
    
         
            -
                #         total_amount: 100,
         
     | 
| 
       69 
     | 
    
         
            -
                #         currency: 'CNY'
         
     | 
| 
       70 
     | 
    
         
            -
                #       },
         
     | 
| 
       71 
     | 
    
         
            -
                #       out_trade_no: 'out_trade_no',
         
     | 
| 
       72 
     | 
    
         
            -
                #       description: 'description'
         
     | 
| 
       73 
     | 
    
         
            -
                #     }
         
     | 
| 
       74 
     | 
    
         
            -
                #   ],
         
     | 
| 
       75 
     | 
    
         
            -
                #   notify_url: 'the_url'
         
     | 
| 
       76 
     | 
    
         
            -
                # }
         
     | 
| 
       77 
     | 
    
         
            -
                #
         
     | 
| 
       78 
     | 
    
         
            -
                # WechatPay::Direct.invoke_combine_transactions_in_js(params)
         
     | 
| 
       79 
     | 
    
         
            -
                # ```
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                ##
         
     | 
| 
       82 
     | 
    
         
            -
                # :singleton-method: invoke_combine_transactions_in_h5
         
     | 
| 
       83 
     | 
    
         
            -
                #
         
     | 
| 
       84 
     | 
    
         
            -
                # 直连合单h5下单
         
     | 
| 
       85 
     | 
    
         
            -
                #
         
     | 
| 
       86 
     | 
    
         
            -
                # TODO: 与电商平台类似,只是参数不同,稍后重构
         
     | 
| 
       87 
     | 
    
         
            -
                #
         
     | 
| 
       88 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_2.shtml
         
     | 
| 
       89 
     | 
    
         
            -
                #
         
     | 
| 
       90 
     | 
    
         
            -
                # Example:
         
     | 
| 
       91 
     | 
    
         
            -
                #
         
     | 
| 
       92 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       93 
     | 
    
         
            -
                # params = {
         
     | 
| 
       94 
     | 
    
         
            -
                #   combine_out_trade_no: 'combine_out_trade_no',
         
     | 
| 
       95 
     | 
    
         
            -
                #   sub_orders: [
         
     | 
| 
       96 
     | 
    
         
            -
                #     {
         
     | 
| 
       97 
     | 
    
         
            -
                #       mchid: 'mchid',
         
     | 
| 
       98 
     | 
    
         
            -
                #       sub_mchid: 'sub mchid',
         
     | 
| 
       99 
     | 
    
         
            -
                #       attach: 'attach',
         
     | 
| 
       100 
     | 
    
         
            -
                #       amount: {
         
     | 
| 
       101 
     | 
    
         
            -
                #         total_amount: 100,
         
     | 
| 
       102 
     | 
    
         
            -
                #         currency: 'CNY'
         
     | 
| 
       103 
     | 
    
         
            -
                #       },
         
     | 
| 
       104 
     | 
    
         
            -
                #       out_trade_no: 'out_trade_no',
         
     | 
| 
       105 
     | 
    
         
            -
                #       description: 'description'
         
     | 
| 
       106 
     | 
    
         
            -
                #     }
         
     | 
| 
       107 
     | 
    
         
            -
                #   ],
         
     | 
| 
       108 
     | 
    
         
            -
                #   notify_url: 'the_url'
         
     | 
| 
       109 
     | 
    
         
            -
                # }
         
     | 
| 
       110 
     | 
    
         
            -
                #
         
     | 
| 
       111 
     | 
    
         
            -
                # WechatPay::Direct.invoke_combine_transactions_in_h5(params)
         
     | 
| 
       112 
     | 
    
         
            -
                # ```
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                ##
         
     | 
| 
       115 
     | 
    
         
            -
                # :singleton-method: invoke_combine_transactions_in_miniprogram
         
     | 
| 
       116 
     | 
    
         
            -
                #
         
     | 
| 
       117 
     | 
    
         
            -
                # 直连合单小程序下单
         
     | 
| 
       118 
     | 
    
         
            -
                #
         
     | 
| 
       119 
     | 
    
         
            -
                #
         
     | 
| 
       120 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_4.shtml
         
     | 
| 
       121 
     | 
    
         
            -
                #
         
     | 
| 
       122 
     | 
    
         
            -
                # Example:
         
     | 
| 
       123 
     | 
    
         
            -
                #
         
     | 
| 
       124 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       125 
     | 
    
         
            -
                # params = {
         
     | 
| 
       126 
     | 
    
         
            -
                #   combine_out_trade_no: 'combine_out_trade_no',
         
     | 
| 
       127 
     | 
    
         
            -
                #   combine_payer_info: {
         
     | 
| 
       128 
     | 
    
         
            -
                #     openid: 'client open id'
         
     | 
| 
       129 
     | 
    
         
            -
                #   },
         
     | 
| 
       130 
     | 
    
         
            -
                #   sub_orders: [
         
     | 
| 
       131 
     | 
    
         
            -
                #     {
         
     | 
| 
       132 
     | 
    
         
            -
                #       mchid: 'mchid',
         
     | 
| 
       133 
     | 
    
         
            -
                #       sub_mchid: 'sub mchid',
         
     | 
| 
       134 
     | 
    
         
            -
                #       attach: 'attach',
         
     | 
| 
       135 
     | 
    
         
            -
                #       amount: {
         
     | 
| 
       136 
     | 
    
         
            -
                #         total_amount: 100,
         
     | 
| 
       137 
     | 
    
         
            -
                #         currency: 'CNY'
         
     | 
| 
       138 
     | 
    
         
            -
                #       },
         
     | 
| 
       139 
     | 
    
         
            -
                #       out_trade_no: 'out_trade_no',
         
     | 
| 
       140 
     | 
    
         
            -
                #       description: 'description'
         
     | 
| 
       141 
     | 
    
         
            -
                #     }
         
     | 
| 
       142 
     | 
    
         
            -
                #   ],
         
     | 
| 
       143 
     | 
    
         
            -
                #   notify_url: 'the_url'
         
     | 
| 
       144 
     | 
    
         
            -
                # }
         
     | 
| 
       145 
     | 
    
         
            -
                #
         
     | 
| 
       146 
     | 
    
         
            -
                # WechatPay::Direct.invoke_combine_transactions_in_miniprogram(params)
         
     | 
| 
       147 
     | 
    
         
            -
                # ```
         
     | 
| 
      
 12 
     | 
    
         
            +
                # @private
         
     | 
| 
      
 13 
     | 
    
         
            +
                # @!macro [attach] define_transaction_method
         
     | 
| 
      
 14 
     | 
    
         
            +
                #   直连$1下单
         
     | 
| 
      
 15 
     | 
    
         
            +
                #
         
     | 
| 
      
 16 
     | 
    
         
            +
                #   Document: $3
         
     | 
| 
      
 17 
     | 
    
         
            +
                #
         
     | 
| 
      
 18 
     | 
    
         
            +
                #   Example:
         
     | 
| 
      
 19 
     | 
    
         
            +
                #
         
     | 
| 
      
 20 
     | 
    
         
            +
                #   ``` ruby
         
     | 
| 
      
 21 
     | 
    
         
            +
                #   params = {
         
     | 
| 
      
 22 
     | 
    
         
            +
                #     appid: 'Your Open id',
         
     | 
| 
      
 23 
     | 
    
         
            +
                #     mchid: 'Your Mch id'',
         
     | 
| 
      
 24 
     | 
    
         
            +
                #     description: '回流',
         
     | 
| 
      
 25 
     | 
    
         
            +
                #     out_trade_no: 'Checking',
         
     | 
| 
      
 26 
     | 
    
         
            +
                #     payer: {
         
     | 
| 
      
 27 
     | 
    
         
            +
                #       openid: 'oly6s5c'
         
     | 
| 
      
 28 
     | 
    
         
            +
                #     },
         
     | 
| 
      
 29 
     | 
    
         
            +
                #     amount: {
         
     | 
| 
      
 30 
     | 
    
         
            +
                #       total: 1
         
     | 
| 
      
 31 
     | 
    
         
            +
                #     },
         
     | 
| 
      
 32 
     | 
    
         
            +
                #     notify_url: ENV['NOTIFICATION_URL']
         
     | 
| 
      
 33 
     | 
    
         
            +
                #   }
         
     | 
| 
      
 34 
     | 
    
         
            +
                #
         
     | 
| 
      
 35 
     | 
    
         
            +
                #   WechatPay::Direct.invoke_transactions_in_$1(params)
         
     | 
| 
      
 36 
     | 
    
         
            +
                #   ```
         
     | 
| 
      
 37 
     | 
    
         
            +
                #   @!method invoke_transactions_in_$1
         
     | 
| 
      
 38 
     | 
    
         
            +
                #   @!scope class
         
     | 
| 
      
 39 
     | 
    
         
            +
                def self.define_transaction_method(key, value, _document)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  const_set("INVOKE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
         
     | 
| 
      
 41 
     | 
    
         
            +
                            %i[description out_trade out_trade_no payer amount notify_url].freeze)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  define_singleton_method "invoke_transactions_in_#{key}" do |params|
         
     | 
| 
      
 43 
     | 
    
         
            +
                    direct_transactions_method_by_suffix(value, params)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
       148 
46 
     | 
    
         | 
| 
       149 
     | 
    
         
            -
                 
     | 
| 
       150 
     | 
    
         
            -
                 
     | 
| 
       151 
     | 
    
         
            -
                 
     | 
| 
       152 
     | 
    
         
            -
                 
     | 
| 
       153 
     | 
    
         
            -
                 
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                #  
     | 
| 
       156 
     | 
    
         
            -
                #
         
     | 
| 
       157 
     | 
    
         
            -
                # 
     | 
| 
       158 
     | 
    
         
            -
                #
         
     | 
| 
       159 
     | 
    
         
            -
                #  
     | 
| 
       160 
     | 
    
         
            -
                # 
     | 
| 
       161 
     | 
    
         
            -
                #    
     | 
| 
       162 
     | 
    
         
            -
                #    
     | 
| 
       163 
     | 
    
         
            -
                #      
     | 
| 
       164 
     | 
    
         
            -
                # 
     | 
| 
       165 
     | 
    
         
            -
                #        
     | 
| 
       166 
     | 
    
         
            -
                # 
     | 
| 
       167 
     | 
    
         
            -
                # 
     | 
| 
       168 
     | 
    
         
            -
                # 
     | 
| 
       169 
     | 
    
         
            -
                #          
     | 
| 
       170 
     | 
    
         
            -
                # 
     | 
| 
       171 
     | 
    
         
            -
                # 
     | 
| 
       172 
     | 
    
         
            -
                # 
     | 
| 
       173 
     | 
    
         
            -
                # 
     | 
| 
       174 
     | 
    
         
            -
                # 
     | 
| 
       175 
     | 
    
         
            -
                # 
     | 
| 
       176 
     | 
    
         
            -
                #  
     | 
| 
       177 
     | 
    
         
            -
                #
         
     | 
| 
       178 
     | 
    
         
            -
                # 
     | 
| 
       179 
     | 
    
         
            -
                # 
     | 
| 
       180 
     | 
    
         
            -
                 
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
                 
     | 
| 
      
 47 
     | 
    
         
            +
                define_transaction_method('js', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml')
         
     | 
| 
      
 48 
     | 
    
         
            +
                define_transaction_method('miniprogram', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml')
         
     | 
| 
      
 49 
     | 
    
         
            +
                define_transaction_method('app', 'app', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_1.shtml')
         
     | 
| 
      
 50 
     | 
    
         
            +
                define_transaction_method('h5', 'h5', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_1.shtml')
         
     | 
| 
      
 51 
     | 
    
         
            +
                define_transaction_method('native', 'native', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml')
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                # @private
         
     | 
| 
      
 54 
     | 
    
         
            +
                # @!macro [attach] define_combine_transaction_method
         
     | 
| 
      
 55 
     | 
    
         
            +
                #   直连合单$1下单
         
     | 
| 
      
 56 
     | 
    
         
            +
                #
         
     | 
| 
      
 57 
     | 
    
         
            +
                #   Document: $3
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                #   ``` ruby
         
     | 
| 
      
 60 
     | 
    
         
            +
                #   params = {
         
     | 
| 
      
 61 
     | 
    
         
            +
                #     combine_out_trade_no: 'combine_out_trade_no',
         
     | 
| 
      
 62 
     | 
    
         
            +
                #     combine_payer_info: {
         
     | 
| 
      
 63 
     | 
    
         
            +
                #       openid: 'client open id'
         
     | 
| 
      
 64 
     | 
    
         
            +
                #     },
         
     | 
| 
      
 65 
     | 
    
         
            +
                #     sub_orders: [
         
     | 
| 
      
 66 
     | 
    
         
            +
                #       {
         
     | 
| 
      
 67 
     | 
    
         
            +
                #         mchid: 'mchid',
         
     | 
| 
      
 68 
     | 
    
         
            +
                #         sub_mchid: 'sub mchid',
         
     | 
| 
      
 69 
     | 
    
         
            +
                #         attach: 'attach',
         
     | 
| 
      
 70 
     | 
    
         
            +
                #         amount: {
         
     | 
| 
      
 71 
     | 
    
         
            +
                #           total_amount: 100,
         
     | 
| 
      
 72 
     | 
    
         
            +
                #           currency: 'CNY'
         
     | 
| 
      
 73 
     | 
    
         
            +
                #         },
         
     | 
| 
      
 74 
     | 
    
         
            +
                #         out_trade_no: 'out_trade_no',
         
     | 
| 
      
 75 
     | 
    
         
            +
                #         description: 'description'
         
     | 
| 
      
 76 
     | 
    
         
            +
                #       }
         
     | 
| 
      
 77 
     | 
    
         
            +
                #     ],
         
     | 
| 
      
 78 
     | 
    
         
            +
                #     notify_url: 'the_url'
         
     | 
| 
      
 79 
     | 
    
         
            +
                #   }
         
     | 
| 
      
 80 
     | 
    
         
            +
                #
         
     | 
| 
      
 81 
     | 
    
         
            +
                #   WechatPay::Direct.invoke_combine_transactions_in_$1(params)
         
     | 
| 
      
 82 
     | 
    
         
            +
                #   ```
         
     | 
| 
      
 83 
     | 
    
         
            +
                #   @!method invoke_combine_transactions_in_$1
         
     | 
| 
      
 84 
     | 
    
         
            +
                #   @!scope class
         
     | 
| 
      
 85 
     | 
    
         
            +
                def self.define_combine_transaction_method(key, _value, _document)
         
     | 
| 
       187 
86 
     | 
    
         
             
                  const_set("INVOKE_COMBINE_TRANSACTIONS_IN_#{key.upcase}_FIELDS",
         
     | 
| 
       188 
87 
     | 
    
         
             
                            %i[combine_out_trade_no scene_info sub_orders notify_url].freeze)
         
     | 
| 
       189 
88 
     | 
    
         
             
                  define_singleton_method("invoke_combine_transactions_in_#{key}") do |params|
         
     | 
| 
         @@ -191,6 +90,12 @@ module WechatPay 
     | 
|
| 
       191 
90 
     | 
    
         
             
                  end
         
     | 
| 
       192 
91 
     | 
    
         
             
                end
         
     | 
| 
       193 
92 
     | 
    
         | 
| 
      
 93 
     | 
    
         
            +
                define_combine_transaction_method('app', 'app', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_1.shtml')
         
     | 
| 
      
 94 
     | 
    
         
            +
                define_combine_transaction_method('js', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_3.shtml')
         
     | 
| 
      
 95 
     | 
    
         
            +
                define_combine_transaction_method('h5', 'h5', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_2.shtml')
         
     | 
| 
      
 96 
     | 
    
         
            +
                define_combine_transaction_method('miniprogram', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_4.shtml')
         
     | 
| 
      
 97 
     | 
    
         
            +
                define_combine_transaction_method('native', 'native', 'https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_5.shtml')
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
       194 
99 
     | 
    
         
             
                QUERY_COMBINE_ORDER_FIELDS = %i[combine_out_trade_no].freeze # :nodoc:
         
     | 
| 
       195 
100 
     | 
    
         
             
                #
         
     | 
| 
       196 
101 
     | 
    
         
             
                # 合单查询
         
     | 
| 
         @@ -251,153 +156,6 @@ module WechatPay 
     | 
|
| 
       251 
156 
     | 
    
         
             
                  )
         
     | 
| 
       252 
157 
     | 
    
         
             
                end
         
     | 
| 
       253 
158 
     | 
    
         | 
| 
       254 
     | 
    
         
            -
                ##
         
     | 
| 
       255 
     | 
    
         
            -
                # :singleton-method: invoke_transactions_in_js
         
     | 
| 
       256 
     | 
    
         
            -
                #
         
     | 
| 
       257 
     | 
    
         
            -
                # 直连js下单
         
     | 
| 
       258 
     | 
    
         
            -
                #
         
     | 
| 
       259 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
         
     | 
| 
       260 
     | 
    
         
            -
                #
         
     | 
| 
       261 
     | 
    
         
            -
                # Example:
         
     | 
| 
       262 
     | 
    
         
            -
                #
         
     | 
| 
       263 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       264 
     | 
    
         
            -
                # params = {
         
     | 
| 
       265 
     | 
    
         
            -
                #   appid: 'Your Open id',
         
     | 
| 
       266 
     | 
    
         
            -
                #   mchid: 'Your Mch id'',
         
     | 
| 
       267 
     | 
    
         
            -
                #   description: '回流',
         
     | 
| 
       268 
     | 
    
         
            -
                #   out_trade_no: 'Checking',
         
     | 
| 
       269 
     | 
    
         
            -
                #   payer: {
         
     | 
| 
       270 
     | 
    
         
            -
                #     openid: 'oly6s5c'
         
     | 
| 
       271 
     | 
    
         
            -
                #   },
         
     | 
| 
       272 
     | 
    
         
            -
                #   amount: {
         
     | 
| 
       273 
     | 
    
         
            -
                #     total: 1
         
     | 
| 
       274 
     | 
    
         
            -
                #   },
         
     | 
| 
       275 
     | 
    
         
            -
                #   notify_url: ENV['NOTIFICATION_URL']
         
     | 
| 
       276 
     | 
    
         
            -
                # }
         
     | 
| 
       277 
     | 
    
         
            -
                #
         
     | 
| 
       278 
     | 
    
         
            -
                # WechatPay::Direct.invoke_transactions_in_js(params)
         
     | 
| 
       279 
     | 
    
         
            -
                # ```
         
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
                ##
         
     | 
| 
       282 
     | 
    
         
            -
                # :singleton-method: invoke_transactions_in_miniprogram
         
     | 
| 
       283 
     | 
    
         
            -
                #
         
     | 
| 
       284 
     | 
    
         
            -
                # 直连小程序下单
         
     | 
| 
       285 
     | 
    
         
            -
                #
         
     | 
| 
       286 
     | 
    
         
            -
                # Document:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_1.shtml
         
     | 
| 
       287 
     | 
    
         
            -
                #
         
     | 
| 
       288 
     | 
    
         
            -
                # Example:
         
     | 
| 
       289 
     | 
    
         
            -
                #
         
     | 
| 
       290 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       291 
     | 
    
         
            -
                # params = {
         
     | 
| 
       292 
     | 
    
         
            -
                #   appid: 'Your Open id',
         
     | 
| 
       293 
     | 
    
         
            -
                #   mchid: 'Your Mch id'',
         
     | 
| 
       294 
     | 
    
         
            -
                #   description: '回流',
         
     | 
| 
       295 
     | 
    
         
            -
                #   out_trade_no: 'Checking',
         
     | 
| 
       296 
     | 
    
         
            -
                #   payer: {
         
     | 
| 
       297 
     | 
    
         
            -
                #     openid: 'oly6s5c'
         
     | 
| 
       298 
     | 
    
         
            -
                #   },
         
     | 
| 
       299 
     | 
    
         
            -
                #   amount: {
         
     | 
| 
       300 
     | 
    
         
            -
                #     total: 1
         
     | 
| 
       301 
     | 
    
         
            -
                #   },
         
     | 
| 
       302 
     | 
    
         
            -
                #   notify_url: ENV['NOTIFICATION_URL']
         
     | 
| 
       303 
     | 
    
         
            -
                # }
         
     | 
| 
       304 
     | 
    
         
            -
                #
         
     | 
| 
       305 
     | 
    
         
            -
                # WechatPay::Direct.invoke_transactions_in_miniprogram(params)
         
     | 
| 
       306 
     | 
    
         
            -
                # ```
         
     | 
| 
       307 
     | 
    
         
            -
             
     | 
| 
       308 
     | 
    
         
            -
                ##
         
     | 
| 
       309 
     | 
    
         
            -
                # :singleton-method: invoke_transactions_in_app
         
     | 
| 
       310 
     | 
    
         
            -
                #
         
     | 
| 
       311 
     | 
    
         
            -
                # 直连APP下单
         
     | 
| 
       312 
     | 
    
         
            -
                #
         
     | 
| 
       313 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_2_1.shtml
         
     | 
| 
       314 
     | 
    
         
            -
                #
         
     | 
| 
       315 
     | 
    
         
            -
                # Example:
         
     | 
| 
       316 
     | 
    
         
            -
                #
         
     | 
| 
       317 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       318 
     | 
    
         
            -
                # params = {
         
     | 
| 
       319 
     | 
    
         
            -
                #   appid: 'Your Open id',
         
     | 
| 
       320 
     | 
    
         
            -
                #   mchid: 'Your Mch id'',
         
     | 
| 
       321 
     | 
    
         
            -
                #   description: '回流',
         
     | 
| 
       322 
     | 
    
         
            -
                #   out_trade_no: 'Checking',
         
     | 
| 
       323 
     | 
    
         
            -
                #   payer: {
         
     | 
| 
       324 
     | 
    
         
            -
                #     openid: 'oly6s5c'
         
     | 
| 
       325 
     | 
    
         
            -
                #   },
         
     | 
| 
       326 
     | 
    
         
            -
                #   amount: {
         
     | 
| 
       327 
     | 
    
         
            -
                #     total: 1
         
     | 
| 
       328 
     | 
    
         
            -
                #   },
         
     | 
| 
       329 
     | 
    
         
            -
                #   notify_url: ENV['NOTIFICATION_URL']
         
     | 
| 
       330 
     | 
    
         
            -
                # }
         
     | 
| 
       331 
     | 
    
         
            -
                #
         
     | 
| 
       332 
     | 
    
         
            -
                # WechatPay::Direct.invoke_transactions_in_app(params)
         
     | 
| 
       333 
     | 
    
         
            -
                # ```
         
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
                ##
         
     | 
| 
       336 
     | 
    
         
            -
                # :singleton-method: invoke_transactions_in_h5
         
     | 
| 
       337 
     | 
    
         
            -
                #
         
     | 
| 
       338 
     | 
    
         
            -
                # 直连h5下单
         
     | 
| 
       339 
     | 
    
         
            -
                #
         
     | 
| 
       340 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_1.shtml
         
     | 
| 
       341 
     | 
    
         
            -
                #
         
     | 
| 
       342 
     | 
    
         
            -
                # Example:
         
     | 
| 
       343 
     | 
    
         
            -
                #
         
     | 
| 
       344 
     | 
    
         
            -
                # ```
         
     | 
| 
       345 
     | 
    
         
            -
                # params = {
         
     | 
| 
       346 
     | 
    
         
            -
                #   appid: 'Your Open id',
         
     | 
| 
       347 
     | 
    
         
            -
                #   mchid: 'Your Mch id'',
         
     | 
| 
       348 
     | 
    
         
            -
                #   description: '回流',
         
     | 
| 
       349 
     | 
    
         
            -
                #   out_trade_no: 'Checking',
         
     | 
| 
       350 
     | 
    
         
            -
                #   payer: {
         
     | 
| 
       351 
     | 
    
         
            -
                #     openid: 'oly6s5c'
         
     | 
| 
       352 
     | 
    
         
            -
                #   },
         
     | 
| 
       353 
     | 
    
         
            -
                #   amount: {
         
     | 
| 
       354 
     | 
    
         
            -
                #     total: 1
         
     | 
| 
       355 
     | 
    
         
            -
                #   },
         
     | 
| 
       356 
     | 
    
         
            -
                #   notify_url: ENV['NOTIFICATION_URL']
         
     | 
| 
       357 
     | 
    
         
            -
                # }
         
     | 
| 
       358 
     | 
    
         
            -
                #
         
     | 
| 
       359 
     | 
    
         
            -
                # WechatPay::Direct.invoke_transactions_in_h5(params)
         
     | 
| 
       360 
     | 
    
         
            -
                # ```
         
     | 
| 
       361 
     | 
    
         
            -
             
     | 
| 
       362 
     | 
    
         
            -
                ##
         
     | 
| 
       363 
     | 
    
         
            -
                # :singleton-method: invoke_transactions_in_native
         
     | 
| 
       364 
     | 
    
         
            -
                #
         
     | 
| 
       365 
     | 
    
         
            -
                # 直连native下单
         
     | 
| 
       366 
     | 
    
         
            -
                #
         
     | 
| 
       367 
     | 
    
         
            -
                # Document: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
         
     | 
| 
       368 
     | 
    
         
            -
                #
         
     | 
| 
       369 
     | 
    
         
            -
                # Example:
         
     | 
| 
       370 
     | 
    
         
            -
                #
         
     | 
| 
       371 
     | 
    
         
            -
                # ``` ruby
         
     | 
| 
       372 
     | 
    
         
            -
                # params = {
         
     | 
| 
       373 
     | 
    
         
            -
                #   appid: 'Your Open id',
         
     | 
| 
       374 
     | 
    
         
            -
                #   mchid: 'Your Mch id'',
         
     | 
| 
       375 
     | 
    
         
            -
                #   description: '回流',
         
     | 
| 
       376 
     | 
    
         
            -
                #   out_trade_no: 'Checking',
         
     | 
| 
       377 
     | 
    
         
            -
                #   payer: {
         
     | 
| 
       378 
     | 
    
         
            -
                #     openid: 'oly6s5c'
         
     | 
| 
       379 
     | 
    
         
            -
                #   },
         
     | 
| 
       380 
     | 
    
         
            -
                #   amount: {
         
     | 
| 
       381 
     | 
    
         
            -
                #     total: 1
         
     | 
| 
       382 
     | 
    
         
            -
                #   },
         
     | 
| 
       383 
     | 
    
         
            -
                #   notify_url: ENV['NOTIFICATION_URL']
         
     | 
| 
       384 
     | 
    
         
            -
                # }
         
     | 
| 
       385 
     | 
    
         
            -
                #
         
     | 
| 
       386 
     | 
    
         
            -
                # WechatPay::Direct.invoke_transactions_in_native(params)
         
     | 
| 
       387 
     | 
    
         
            -
                # ```
         
     | 
| 
       388 
     | 
    
         
            -
                {
         
     | 
| 
       389 
     | 
    
         
            -
                  js: 'jsapi',
         
     | 
| 
       390 
     | 
    
         
            -
                  app: 'app',
         
     | 
| 
       391 
     | 
    
         
            -
                  h5: 'h5',
         
     | 
| 
       392 
     | 
    
         
            -
                  miniprogram: 'jsapi',
         
     | 
| 
       393 
     | 
    
         
            -
                  native: 'native'
         
     | 
| 
       394 
     | 
    
         
            -
                }.each do |key, value|
         
     | 
| 
       395 
     | 
    
         
            -
                  const_set("INVOKE_TRANSACTIONS_IN_#{key.upcase}_FIELDS", %i[description out_trade out_trade_no payer amount notify_url].freeze)
         
     | 
| 
       396 
     | 
    
         
            -
                  define_singleton_method "invoke_transactions_in_#{key}" do |params|
         
     | 
| 
       397 
     | 
    
         
            -
                    direct_transactions_method_by_suffix(value, params)
         
     | 
| 
       398 
     | 
    
         
            -
                  end
         
     | 
| 
       399 
     | 
    
         
            -
                end
         
     | 
| 
       400 
     | 
    
         
            -
             
     | 
| 
       401 
159 
     | 
    
         
             
                QUERY_ORDER_FIELDS = %i[out_trade_no transaction_id].freeze # :nodoc:
         
     | 
| 
       402 
160 
     | 
    
         
             
                #
         
     | 
| 
       403 
161 
     | 
    
         
             
                # 直连订单查询
         
     |