ruby_payler 0.1.9 → 0.2.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/.gitignore +1 -0
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +15 -0
- data/README.md +41 -10
- data/Rakefile +5 -5
- data/lib/ruby_payler.rb +4 -4
- data/lib/ruby_payler/connection.rb +23 -0
- data/lib/ruby_payler/errors.rb +51 -15
- data/lib/ruby_payler/payler.rb +60 -59
- data/lib/ruby_payler/version.rb +1 -1
- data/ruby_payler.gemspec +35 -24
- metadata +34 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fd74e6abd4a02a3fa184ac90ee1ab9a1c690ed1f
         | 
| 4 | 
            +
              data.tar.gz: 6804de07e127c5a70b15dad88465e8660c81aa6a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ba25bcae20d0f735c7f90d0be20200874d3cfcd0b73620e9d82081b01db42d38eee6de390415d40af3dfa22d08f7fac8a0e0e8bdeb3d57fa35e70837fd6ee622
         | 
| 7 | 
            +
              data.tar.gz: 0ae104a89f812dbbeddb24758822c5a09b8c14ada7b13dc10a255aeaa33c4ef0193ec69d81b4e56318a31fcd3bf4f90074f73bc73723c78f804825174eb980b6
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rubocop.yml
    ADDED
    
    | @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            AllCops:
         | 
| 2 | 
            +
              TargetRubyVersion: 2.3
         | 
| 3 | 
            +
              DisplayCopNames: true
         | 
| 4 | 
            +
              DisplayStyleGuide: true
         | 
| 5 | 
            +
              Exclude:
         | 
| 6 | 
            +
                - 'bin/*'
         | 
| 7 | 
            +
                - 'config/**/*'
         | 
| 8 | 
            +
                - 'db/**/*'
         | 
| 9 | 
            +
                - 'Guardfile'
         | 
| 10 | 
            +
                - 'Gemfile'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            Metrics/MethodLength:
         | 
| 13 | 
            +
              Max: 20
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Metrics/LineLength:
         | 
| 16 | 
            +
              Max: 100
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Style/TrailingCommaInLiteral:
         | 
| 19 | 
            +
              EnforcedStyleForMultiline: comma
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Style/TrailingCommaInArguments:
         | 
| 22 | 
            +
              EnforcedStyleForMultiline: comma
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            Style/AlignParameters:
         | 
| 25 | 
            +
              EnforcedStyle: with_fixed_indentation
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            Style/MultilineMethodCallBraceLayout:
         | 
| 28 | 
            +
              EnforcedStyle: new_line
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            Style/FrozenStringLiteralComment:
         | 
| 31 | 
            +
              Enabled: false
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Metrics/AbcSize:
         | 
| 34 | 
            +
              Enabled: false
         | 
    
        data/CHANGELOG.md
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # RubyPayler Changelog
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## v0.2.0
         | 
| 4 | 
            +
            * Major update: implement 100% of methods
         | 
| 5 | 
            +
            * Achieve 100% test coverage
         | 
| 6 | 
            +
            * Change config file format
         | 
| 7 | 
            +
            * Change commands to run tests
         | 
| 8 | 
            +
            * Add command to build coverage report
         | 
| 9 | 
            +
            * Add some development dependencies
         | 
| 10 | 
            +
            * Update Readme
         | 
| 11 | 
            +
            * Add Changelog
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## v0.1.9
         | 
| 14 | 
            +
            * Implement all necessary methods for Busfor usage
         | 
| 15 | 
            +
             | 
    
        data/README.md
    CHANGED
    
    | @@ -1,12 +1,20 @@ | |
| 1 1 | 
             
            # RubyPayler
         | 
| 2 | 
            -
            Ruby wrapper for payler.com API
         | 
| 2 | 
            +
            Ruby wrapper for payler.com Gate API v1.11
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 4 | 
            +
            _This is not Merchant API_
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 6 | 
            +
             | 
| 7 | 
            +
            Documentation for API is here: [pdf](http://payler.com/download/docs/%D0%9E%D0%BF%D0%B8%D1%81%D0%B0%D0%BD%D0%B8%D0%B5%20Payler%20Gate%20API.pdf) and here: http://payler.com/docs/acquiring.html
         | 
| 7 8 |  | 
| 8 9 | 
             
            Documentation for this gem: http://www.rubydoc.info/gems/ruby_payler/
         | 
| 9 10 |  | 
| 11 | 
            +
            ## Highlights
         | 
| 12 | 
            +
            - 100% of API methods implemented
         | 
| 13 | 
            +
            - 100% test coverage
         | 
| 14 | 
            +
            - tests perform real interactions with Payler API via Capybara and PhantomJs
         | 
| 15 | 
            +
            - tests work fast and offline with VCR cassettes
         | 
| 16 | 
            +
            - battle-tested at [busfor.ru](https://busfor.ru), more than 200000 payments processed
         | 
| 17 | 
            +
             | 
| 10 18 | 
             
            ## Installation
         | 
| 11 19 |  | 
| 12 20 | 
             
            Add this line to your application's Gemfile:
         | 
| @@ -76,11 +84,17 @@ See tests for more usage examples | |
| 76 84 |  | 
| 77 85 | 
             
            ## Errors
         | 
| 78 86 | 
             
            In case of any error RubyPayler `raises` RubyPayler::Error.
         | 
| 79 | 
            -
            There are  | 
| 80 | 
            -
            -  | 
| 81 | 
            -
            -  | 
| 87 | 
            +
            There are three child types of Errors:
         | 
| 88 | 
            +
            - ResponseError - for responses with error in body
         | 
| 89 | 
            +
            - NetworkError - for failed network request
         | 
| 90 | 
            +
            - UnexpectedResponseError - for responses with status != 200 but without error in body
         | 
| 91 | 
            +
             | 
| 92 | 
            +
            All RubyPayler errors have methods _code_, _message_ and _to_s_
         | 
| 82 93 |  | 
| 83 | 
            -
             | 
| 94 | 
            +
            Examples of errors `to_s`:
         | 
| 95 | 
            +
            - ResponseError: `Payler responded with error: Invalid amount of the transaction., code 1`
         | 
| 96 | 
            +
            - NetworkError: `NetworkError occured while performing request to Payler: #<Faraday::Error: Faraday::Error>`
         | 
| 97 | 
            +
            - UnexpectedResponseError: `Unexpected response: code - 503, body - `
         | 
| 84 98 |  | 
| 85 99 | 
             
            ## Tests
         | 
| 86 100 | 
             
            *Tests make real calls to Payler.com web API.*
         | 
| @@ -89,7 +103,19 @@ Cool, because it really test workflows of interaction with payler equiring via r | |
| 89 103 |  | 
| 90 104 | 
             
            Payment step in tests is automated with Capybara and PhantomJS (cool as well).
         | 
| 91 105 |  | 
| 92 | 
            -
            You can switch to make Payment step by hand via  | 
| 106 | 
            +
            You can also switch to make Payment step by hand via ENV variable.
         | 
| 107 | 
            +
             | 
| 108 | 
            +
            ```bash
         | 
| 109 | 
            +
            REFRESH_CAPYBARA=1 rake test # Regenerate VCR-cassettes using capybara to pay
         | 
| 110 | 
            +
            REFRESH_BY_HAND=1 rake test # Regenerate VCR-cassettes paying by hand
         | 
| 111 | 
            +
            ```
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            After VCR-cassettes are saved launch `rake test` for fast test run
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            ## Coverage
         | 
| 116 | 
            +
            **Current test coverage is 100%**
         | 
| 117 | 
            +
             | 
| 118 | 
            +
            To rebuild coverage report use `COVERAGE=1 rake test` command
         | 
| 93 119 |  | 
| 94 120 | 
             
            ## Config
         | 
| 95 121 | 
             
            Make file config.yml by copying config_example.yml
         | 
| @@ -98,7 +124,10 @@ Fill in your Payler key, password, host | |
| 98 124 |  | 
| 99 125 | 
             
            Fill test card number, vaild_till, code, name for automated payment by capybara
         | 
| 100 126 |  | 
| 101 | 
            -
             | 
| 127 | 
            +
            ## Note on Pay method
         | 
| 128 | 
            +
            This gem has methods `pay_page_url` instead of `pay` method, mentioned in Payler docs.
         | 
| 129 | 
            +
             | 
| 130 | 
            +
            This is due to a fact that `pay` method does in fact return payment page url, and does not do any paying.
         | 
| 102 131 |  | 
| 103 132 | 
             
            ## Development
         | 
| 104 133 | 
             
            To run automated tests with capybara install PhantomJS (_brew install phantomjs on MacOS_)
         | 
| @@ -110,10 +139,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run | |
| 110 139 | 
             
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 111 140 |  | 
| 112 141 | 
             
            ## Contributing
         | 
| 113 | 
            -
             | 
| 114 142 | 
             
            Bug reports and pull requests are welcome on GitHub at https://github.com/busfor/ruby_payler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
         | 
| 115 143 |  | 
| 116 144 |  | 
| 145 | 
            +
            ## Changelog
         | 
| 146 | 
            +
            [Changelog](CHANGELOG.md)
         | 
| 147 | 
            +
             | 
| 117 148 | 
             
            ## License
         | 
| 118 149 |  | 
| 119 150 | 
             
            The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,10 +1,10 @@ | |
| 1 | 
            -
            require  | 
| 2 | 
            -
            require  | 
| 1 | 
            +
            require 'bundler/gem_tasks'
         | 
| 2 | 
            +
            require 'rake/testtask'
         | 
| 3 3 |  | 
| 4 4 | 
             
            Rake::TestTask.new(:test) do |t|
         | 
| 5 | 
            -
              t.libs <<  | 
| 6 | 
            -
              t.libs <<  | 
| 5 | 
            +
              t.libs << 'test'
         | 
| 6 | 
            +
              t.libs << 'lib'
         | 
| 7 7 | 
             
              t.test_files = FileList['test/**/*_test.rb']
         | 
| 8 8 | 
             
            end
         | 
| 9 9 |  | 
| 10 | 
            -
            task : | 
| 10 | 
            +
            task default: :test
         | 
    
        data/lib/ruby_payler.rb
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            require  | 
| 2 | 
            -
            require  | 
| 3 | 
            -
            require  | 
| 4 | 
            -
            require  | 
| 1 | 
            +
            require 'ruby_payler/version'
         | 
| 2 | 
            +
            require 'ruby_payler/payler'
         | 
| 3 | 
            +
            require 'ruby_payler/errors'
         | 
| 4 | 
            +
            require 'ruby_payler/constants'
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            require 'faraday'
         | 
| 2 | 
            +
            require 'faraday_middleware'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module RubyPayler
         | 
| 5 | 
            +
              # Network connection to Payler
         | 
| 6 | 
            +
              class Connection
         | 
| 7 | 
            +
                def initialize(url:, key:, debug: false)
         | 
| 8 | 
            +
                  @driver = Faraday.new(url: url, params: { key: key }) do |f|
         | 
| 9 | 
            +
                    f.request :url_encoded # form-encode POST params
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    f.response :mashify          # 3. mashify parsed JSON
         | 
| 12 | 
            +
                    f.response :json             # 2. parse JSON
         | 
| 13 | 
            +
                    f.response :logger if debug  # 1. log requests to STDOUT
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    f.adapter Faraday.default_adapter # make requests with Net::HTTP
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def post(endpoint, params)
         | 
| 20 | 
            +
                  @driver.post(endpoint, params)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
    
        data/lib/ruby_payler/errors.rb
    CHANGED
    
    | @@ -1,43 +1,79 @@ | |
| 1 1 | 
             
            module RubyPayler
         | 
| 2 | 
            +
              # Base error class for all RubyPayler errors
         | 
| 3 | 
            +
              # Every RubyPayler Error Class must have code, message and to_s methods!
         | 
| 2 4 | 
             
              class Error < RuntimeError
         | 
| 5 | 
            +
              end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              # Response.body contains error
         | 
| 8 | 
            +
              class ResponseError < Error
         | 
| 9 | 
            +
                attr_reader :response
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def initialize(response)
         | 
| 12 | 
            +
                  @response = response
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                # Payler error code
         | 
| 3 16 | 
             
                def code
         | 
| 4 | 
            -
                   | 
| 17 | 
            +
                  response_error.code
         | 
| 5 18 | 
             
                end
         | 
| 6 19 |  | 
| 20 | 
            +
                # Payler error description
         | 
| 7 21 | 
             
                def message
         | 
| 8 | 
            -
                   | 
| 22 | 
            +
                  response_error.message
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def to_s
         | 
| 26 | 
            +
                  "Payler responded with error: #{message}, code #{code}"
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                private
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def response_error
         | 
| 32 | 
            +
                  @response_error ||= response.body.error
         | 
| 9 33 | 
             
                end
         | 
| 10 34 | 
             
              end
         | 
| 11 35 |  | 
| 12 | 
            -
              #  | 
| 13 | 
            -
              class  | 
| 36 | 
            +
              # Unexpected response
         | 
| 37 | 
            +
              class UnexpectedResponseError < Error
         | 
| 38 | 
            +
                attr_reader :response
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def initialize(response)
         | 
| 41 | 
            +
                  @response = response
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 14 44 | 
             
                def code
         | 
| 15 | 
            -
                   | 
| 45 | 
            +
                  @code ||= response.status
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def body
         | 
| 49 | 
            +
                  @body ||= response.body
         | 
| 16 50 | 
             
                end
         | 
| 17 51 |  | 
| 18 52 | 
             
                def message
         | 
| 19 | 
            -
                   | 
| 53 | 
            +
                  "Unexpected response: code - #{code}, body - #{body}"
         | 
| 20 54 | 
             
                end
         | 
| 21 | 
            -
              end
         | 
| 22 55 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
                 | 
| 56 | 
            +
                def to_s
         | 
| 57 | 
            +
                  message
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 26 60 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 61 | 
            +
              # Network Error (Faraday exception)
         | 
| 62 | 
            +
              class NetworkError < Error
         | 
| 63 | 
            +
                def initialize(faraday_error)
         | 
| 64 | 
            +
                  @faraday_error = faraday_error
         | 
| 29 65 | 
             
                end
         | 
| 30 66 |  | 
| 31 67 | 
             
                def code
         | 
| 32 | 
            -
                   | 
| 68 | 
            +
                  'NetworkError'
         | 
| 33 69 | 
             
                end
         | 
| 34 70 |  | 
| 35 71 | 
             
                def message
         | 
| 36 | 
            -
                   | 
| 72 | 
            +
                  @faraday_error.inspect
         | 
| 37 73 | 
             
                end
         | 
| 38 74 |  | 
| 39 75 | 
             
                def to_s
         | 
| 40 | 
            -
                  "#{ | 
| 76 | 
            +
                  "NetworkError occured while performing request to Payler: #{message}"
         | 
| 41 77 | 
             
                end
         | 
| 42 78 | 
             
              end
         | 
| 43 79 | 
             
            end
         | 
    
        data/lib/ruby_payler/payler.rb
    CHANGED
    
    | @@ -1,122 +1,123 @@ | |
| 1 | 
            -
            require ' | 
| 2 | 
            -
            require 'faraday_middleware'
         | 
| 1 | 
            +
            require 'ruby_payler/connection'
         | 
| 3 2 |  | 
| 4 3 | 
             
            module RubyPayler
         | 
| 4 | 
            +
              # Wrapper for payler gate api
         | 
| 5 5 | 
             
              class Payler
         | 
| 6 | 
            -
                attr_reader :host, :key, :password
         | 
| 6 | 
            +
                attr_reader :host, :key, :password, :debug, :payler_url
         | 
| 7 7 |  | 
| 8 8 | 
             
                def initialize(host:, key:, password:, debug: false)
         | 
| 9 9 | 
             
                  @host = host
         | 
| 10 10 | 
             
                  @key = key
         | 
| 11 11 | 
             
                  @password = password
         | 
| 12 | 
            +
                  @debug = debug
         | 
| 12 13 |  | 
| 13 | 
            -
                  @ | 
| 14 | 
            -
                    url: "https://#{host}.payler.com",
         | 
| 15 | 
            -
                    params: { key: @key },
         | 
| 16 | 
            -
                  ) do |f|
         | 
| 17 | 
            -
                    f.request  :url_encoded # form-encode POST params
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                    f.params
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                    f.response :mashify          # 3. mashify parsed JSON
         | 
| 22 | 
            -
                    f.response :json             # 2. parse JSON
         | 
| 23 | 
            -
                    f.response :logger if debug  # 1. log requests to STDOUT
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                    f.adapter  Faraday.default_adapter  # make requests with Net::HTTP
         | 
| 26 | 
            -
                  end
         | 
| 14 | 
            +
                  @payler_url = "https://#{host}.payler.com/gapi/"
         | 
| 27 15 | 
             
                end
         | 
| 28 16 |  | 
| 29 17 | 
             
                def start_session(
         | 
| 30 | 
            -
                  order_id:,
         | 
| 31 18 | 
             
                  type:,
         | 
| 19 | 
            +
                  order_id:,
         | 
| 32 20 | 
             
                  cents:,
         | 
| 33 | 
            -
                   | 
| 34 | 
            -
                  lang:,
         | 
| 35 | 
            -
                  product: nil,
         | 
| 36 | 
            -
                  userdata: nil
         | 
| 21 | 
            +
                  **other_session_params
         | 
| 37 22 | 
             
                )
         | 
| 38 | 
            -
                   | 
| 39 | 
            -
                  call_payler_api('gapi/StartSession', {
         | 
| 40 | 
            -
                    key: key,
         | 
| 23 | 
            +
                  call_payler_api('StartSession',
         | 
| 41 24 | 
             
                    type: type,
         | 
| 42 25 | 
             
                    order_id: order_id,
         | 
| 43 | 
            -
                    currency: currency,
         | 
| 44 26 | 
             
                    amount: cents,
         | 
| 45 | 
            -
                     | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 27 | 
            +
                    **other_session_params,
         | 
| 28 | 
            +
                  )
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def find_session(order_id)
         | 
| 32 | 
            +
                  call_payler_api('FindSession', order_id: order_id)
         | 
| 49 33 | 
             
                end
         | 
| 50 34 |  | 
| 51 35 | 
             
                def pay_page_url(session_id)
         | 
| 52 | 
            -
                  "#{ | 
| 36 | 
            +
                  "#{payler_url}Pay?key=#{key}&session_id=#{session_id}"
         | 
| 53 37 | 
             
                end
         | 
| 54 38 |  | 
| 55 39 | 
             
                def get_status(order_id)
         | 
| 56 | 
            -
                  call_payler_api(' | 
| 57 | 
            -
                    key: key,
         | 
| 58 | 
            -
                    order_id: order_id,
         | 
| 59 | 
            -
                  })
         | 
| 40 | 
            +
                  call_payler_api('GetStatus', order_id: order_id)
         | 
| 60 41 | 
             
                end
         | 
| 61 42 |  | 
| 62 43 | 
             
                def get_advanced_status(order_id)
         | 
| 63 | 
            -
                  call_payler_api(' | 
| 64 | 
            -
                    key: key,
         | 
| 65 | 
            -
                    order_id: order_id,
         | 
| 66 | 
            -
                  })
         | 
| 44 | 
            +
                  call_payler_api('GetAdvancedStatus', order_id: order_id)
         | 
| 67 45 | 
             
                end
         | 
| 68 46 |  | 
| 69 47 | 
             
                def charge(order_id, amount)
         | 
| 70 | 
            -
                  call_payler_api(' | 
| 71 | 
            -
                    key: key,
         | 
| 48 | 
            +
                  call_payler_api('Charge',
         | 
| 72 49 | 
             
                    password: password,
         | 
| 73 50 | 
             
                    order_id: order_id,
         | 
| 74 51 | 
             
                    amount: amount,
         | 
| 75 | 
            -
                   | 
| 52 | 
            +
                  )
         | 
| 76 53 | 
             
                end
         | 
| 77 54 |  | 
| 78 55 | 
             
                def retrieve(order_id, amount)
         | 
| 79 | 
            -
                  call_payler_api(' | 
| 80 | 
            -
                    key: key,
         | 
| 56 | 
            +
                  call_payler_api('Retrieve',
         | 
| 81 57 | 
             
                    password: password,
         | 
| 82 58 | 
             
                    order_id: order_id,
         | 
| 83 59 | 
             
                    amount: amount,
         | 
| 84 | 
            -
                   | 
| 60 | 
            +
                  )
         | 
| 85 61 | 
             
                end
         | 
| 86 62 |  | 
| 87 63 | 
             
                def refund(order_id, amount)
         | 
| 88 | 
            -
                  call_payler_api(' | 
| 89 | 
            -
                    key: key,
         | 
| 64 | 
            +
                  call_payler_api('Refund',
         | 
| 90 65 | 
             
                    password: password,
         | 
| 91 66 | 
             
                    order_id: order_id,
         | 
| 92 67 | 
             
                    amount: amount,
         | 
| 93 | 
            -
                   | 
| 68 | 
            +
                  )
         | 
| 94 69 | 
             
                end
         | 
| 95 70 |  | 
| 96 | 
            -
                 | 
| 71 | 
            +
                def get_template(recurrent_template_id)
         | 
| 72 | 
            +
                  call_payler_api('GetTemplate',
         | 
| 73 | 
            +
                    recurrent_template_id: recurrent_template_id,
         | 
| 74 | 
            +
                  )
         | 
| 75 | 
            +
                end
         | 
| 97 76 |  | 
| 98 | 
            -
                def  | 
| 99 | 
            -
                   | 
| 77 | 
            +
                def activate_template(recurrent_template_id, active)
         | 
| 78 | 
            +
                  call_payler_api('ActivateTemplate',
         | 
| 79 | 
            +
                    recurrent_template_id: recurrent_template_id,
         | 
| 80 | 
            +
                    active: active,
         | 
| 81 | 
            +
                  )
         | 
| 100 82 | 
             
                end
         | 
| 101 83 |  | 
| 102 | 
            -
                def  | 
| 103 | 
            -
                   | 
| 84 | 
            +
                def repeat_pay(order_id:, amount:, recurrent_template_id:)
         | 
| 85 | 
            +
                  call_payler_api('RepeatPay',
         | 
| 86 | 
            +
                    order_id: order_id,
         | 
| 87 | 
            +
                    amount: amount,
         | 
| 88 | 
            +
                    recurrent_template_id: recurrent_template_id,
         | 
| 89 | 
            +
                  )
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                private
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                def connection
         | 
| 95 | 
            +
                  @connection ||= Connection.new(url: payler_url, key: key, debug: debug)
         | 
| 104 96 | 
             
                end
         | 
| 105 97 |  | 
| 106 98 | 
             
                def call_payler_api(endpoint, params)
         | 
| 107 99 | 
             
                  remove_nils_from_params!(params)
         | 
| 100 | 
            +
                  params[:key] = key
         | 
| 108 101 |  | 
| 109 102 | 
             
                  begin
         | 
| 110 103 | 
             
                    response = connection.post(endpoint, params)
         | 
| 111 | 
            -
                  rescue Faraday::Error =>  | 
| 112 | 
            -
                    raise  | 
| 104 | 
            +
                  rescue Faraday::Error => faraday_error
         | 
| 105 | 
            +
                    raise RubyPayler::NetworkError, faraday_error
         | 
| 113 106 | 
             
                  end
         | 
| 114 107 |  | 
| 115 | 
            -
                   | 
| 116 | 
            -
                  if  | 
| 117 | 
            -
             | 
| 108 | 
            +
                  response_body = response.body
         | 
| 109 | 
            +
                  if (response_body.class != Hashie::Mash) ||
         | 
| 110 | 
            +
                     (response.status != 200 && !response_body.include?(:error))
         | 
| 111 | 
            +
                    raise RubyPayler::UnexpectedResponseError, response
         | 
| 118 112 | 
             
                  end
         | 
| 119 | 
            -
             | 
| 113 | 
            +
             | 
| 114 | 
            +
                  raise RubyPayler::ResponseError, response if response_body.error
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                  response_body
         | 
| 117 | 
            +
                end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                def remove_nils_from_params!(params)
         | 
| 120 | 
            +
                  params.delete_if { |_key, value| value.nil? }
         | 
| 120 121 | 
             
                end
         | 
| 121 122 | 
             
              end # class Payler
         | 
| 122 123 | 
             
            end # module RubyPayler
         | 
    
        data/lib/ruby_payler/version.rb
    CHANGED
    
    
    
        data/ruby_payler.gemspec
    CHANGED
    
    | @@ -3,34 +3,45 @@ lib = File.expand_path('../lib', __FILE__) | |
| 3 3 | 
             
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 4 | 
             
            require 'ruby_payler/version'
         | 
| 5 5 |  | 
| 6 | 
            +
            def add_production_dependencies(spec)
         | 
| 7 | 
            +
              spec.add_dependency 'faraday', '~> 0.9.2'
         | 
| 8 | 
            +
              spec.add_dependency 'faraday_middleware', '~> 0.10.0'
         | 
| 9 | 
            +
              spec.add_dependency 'hashie', '~> 3.4', '>= 3.4.4'
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            def add_development_dependencies(spec)
         | 
| 13 | 
            +
              spec.add_development_dependency 'bundler', '~> 1.12'
         | 
| 14 | 
            +
              spec.add_development_dependency 'rake', '~> 10.0'
         | 
| 15 | 
            +
              spec.add_development_dependency 'minitest', '~> 5.0'
         | 
| 16 | 
            +
              spec.add_development_dependency 'pry-byebug', '~> 3.4'
         | 
| 17 | 
            +
              spec.add_development_dependency 'guard', '~> 2.14'
         | 
| 18 | 
            +
              spec.add_development_dependency 'guard-minitest', '~> 2.4', '>= 2.4.5'
         | 
| 19 | 
            +
              spec.add_development_dependency 'terminal-notifier-guard', '~> 1.6.1'
         | 
| 20 | 
            +
              spec.add_development_dependency 'capybara', '~> 2.6', '>= 2.6.2'
         | 
| 21 | 
            +
              spec.add_development_dependency 'poltergeist', '~> 1.10'
         | 
| 22 | 
            +
              spec.add_development_dependency 'mocha', '>= 1.2.1'
         | 
| 23 | 
            +
              spec.add_development_dependency 'vcr'
         | 
| 24 | 
            +
              spec.add_development_dependency 'simplecov'
         | 
| 25 | 
            +
            end
         | 
| 26 | 
            +
             | 
| 6 27 | 
             
            Gem::Specification.new do |spec|
         | 
| 7 | 
            -
              spec.name          =  | 
| 28 | 
            +
              spec.name          = 'ruby_payler'
         | 
| 8 29 | 
             
              spec.version       = RubyPayler::VERSION
         | 
| 9 | 
            -
              spec.authors       = [ | 
| 10 | 
            -
              spec.email         = [ | 
| 30 | 
            +
              spec.authors       = ['Alexey Vasilyev']
         | 
| 31 | 
            +
              spec.email         = ['bestspajic@gmail.com']
         | 
| 11 32 |  | 
| 12 | 
            -
              spec.summary       =  | 
| 13 | 
            -
              spec.description   =  | 
| 14 | 
            -
              spec.homepage      =  | 
| 15 | 
            -
              spec.license       =  | 
| 33 | 
            +
              spec.summary       = 'Ruby wrapper for Payler Gate API.'
         | 
| 34 | 
            +
              spec.description   = 'Ruby wrapper for Payler.com Gate API.'
         | 
| 35 | 
            +
              spec.homepage      = 'https://github.com/busfor/ruby_payler'
         | 
| 36 | 
            +
              spec.license       = 'MIT'
         | 
| 16 37 |  | 
| 17 | 
            -
              spec.files         = `git ls-files -z`.split("\x0").reject  | 
| 18 | 
            -
             | 
| 38 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject do |f|
         | 
| 39 | 
            +
                f.match(%r{^(test|spec|features)/})
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
              spec.bindir        = 'exe'
         | 
| 19 42 | 
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 20 | 
            -
              spec.require_paths = [ | 
| 21 | 
            -
             | 
| 22 | 
            -
              spec.add_dependency "faraday", "~> 0.9.2"
         | 
| 23 | 
            -
              spec.add_dependency "faraday_middleware", "~> 0.10.0"
         | 
| 24 | 
            -
              spec.add_dependency "hashie", "~> 3.4", ">= 3.4.4"
         | 
| 43 | 
            +
              spec.require_paths = ['lib']
         | 
| 25 44 |  | 
| 26 | 
            -
              spec | 
| 27 | 
            -
              spec | 
| 28 | 
            -
              spec.add_development_dependency "minitest", "~> 5.0"
         | 
| 29 | 
            -
              spec.add_development_dependency "pry-byebug", "~> 3.4"
         | 
| 30 | 
            -
              spec.add_development_dependency "guard", "~> 2.14"
         | 
| 31 | 
            -
              spec.add_development_dependency "guard-minitest", "~> 2.4", ">= 2.4.5"
         | 
| 32 | 
            -
              spec.add_development_dependency "terminal-notifier-guard", "~> 1.6.1"
         | 
| 33 | 
            -
              spec.add_development_dependency "capybara", "~> 2.6", ">= 2.6.2"
         | 
| 34 | 
            -
              spec.add_development_dependency "poltergeist", "~> 1.10"
         | 
| 35 | 
            -
              spec.add_development_dependency "mocha", ">= 1.2.1"
         | 
| 45 | 
            +
              add_production_dependencies(spec)
         | 
| 46 | 
            +
              add_development_dependencies(spec)
         | 
| 36 47 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ruby_payler
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Alexey Vasilyev
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-10-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         | 
| @@ -210,6 +210,34 @@ dependencies: | |
| 210 210 | 
             
                - - ">="
         | 
| 211 211 | 
             
                  - !ruby/object:Gem::Version
         | 
| 212 212 | 
             
                    version: 1.2.1
         | 
| 213 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 214 | 
            +
              name: vcr
         | 
| 215 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 216 | 
            +
                requirements:
         | 
| 217 | 
            +
                - - ">="
         | 
| 218 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 219 | 
            +
                    version: '0'
         | 
| 220 | 
            +
              type: :development
         | 
| 221 | 
            +
              prerelease: false
         | 
| 222 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 223 | 
            +
                requirements:
         | 
| 224 | 
            +
                - - ">="
         | 
| 225 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 226 | 
            +
                    version: '0'
         | 
| 227 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 228 | 
            +
              name: simplecov
         | 
| 229 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 230 | 
            +
                requirements:
         | 
| 231 | 
            +
                - - ">="
         | 
| 232 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 233 | 
            +
                    version: '0'
         | 
| 234 | 
            +
              type: :development
         | 
| 235 | 
            +
              prerelease: false
         | 
| 236 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 237 | 
            +
                requirements:
         | 
| 238 | 
            +
                - - ">="
         | 
| 239 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 240 | 
            +
                    version: '0'
         | 
| 213 241 | 
             
            description: Ruby wrapper for Payler.com Gate API.
         | 
| 214 242 | 
             
            email:
         | 
| 215 243 | 
             
            - bestspajic@gmail.com
         | 
| @@ -218,7 +246,9 @@ extensions: [] | |
| 218 246 | 
             
            extra_rdoc_files: []
         | 
| 219 247 | 
             
            files:
         | 
| 220 248 | 
             
            - ".gitignore"
         | 
| 249 | 
            +
            - ".rubocop.yml"
         | 
| 221 250 | 
             
            - ".travis.yml"
         | 
| 251 | 
            +
            - CHANGELOG.md
         | 
| 222 252 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 223 253 | 
             
            - Gemfile
         | 
| 224 254 | 
             
            - Guardfile
         | 
| @@ -228,6 +258,7 @@ files: | |
| 228 258 | 
             
            - bin/console
         | 
| 229 259 | 
             
            - bin/setup
         | 
| 230 260 | 
             
            - lib/ruby_payler.rb
         | 
| 261 | 
            +
            - lib/ruby_payler/connection.rb
         | 
| 231 262 | 
             
            - lib/ruby_payler/constants.rb
         | 
| 232 263 | 
             
            - lib/ruby_payler/errors.rb
         | 
| 233 264 | 
             
            - lib/ruby_payler/payler.rb
         | 
| @@ -253,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 253 284 | 
             
                  version: '0'
         | 
| 254 285 | 
             
            requirements: []
         | 
| 255 286 | 
             
            rubyforge_project: 
         | 
| 256 | 
            -
            rubygems_version: 2.5. | 
| 287 | 
            +
            rubygems_version: 2.5.2
         | 
| 257 288 | 
             
            signing_key: 
         | 
| 258 289 | 
             
            specification_version: 4
         | 
| 259 290 | 
             
            summary: Ruby wrapper for Payler Gate API.
         |