{"id":15726347,"url":"https://github.com/mrexox/commissioner","last_synced_at":"2026-05-03T04:34:14.446Z","repository":{"id":59152287,"uuid":"320853282","full_name":"mrexox/commissioner","owner":"mrexox","description":"Ruby gem for calculating commissions and exchanging amounts easily","archived":false,"fork":false,"pushed_at":"2020-12-13T17:12:41.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-26T15:43:28.483Z","etag":null,"topics":["commission","exchange","gem","money","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrexox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-12T14:47:59.000Z","updated_at":"2021-12-17T09:17:52.000Z","dependencies_parsed_at":"2022-09-13T11:00:59.244Z","dependency_job_id":null,"html_url":"https://github.com/mrexox/commissioner","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexox%2Fcommissioner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexox%2Fcommissioner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexox%2Fcommissioner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrexox%2Fcommissioner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrexox","download_url":"https://codeload.github.com/mrexox/commissioner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246403593,"owners_count":20771500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commission","exchange","gem","money","ruby"],"created_at":"2024-10-03T22:26:54.137Z","updated_at":"2026-05-03T04:34:14.393Z","avatar_url":"https://github.com/mrexox.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Commissioner Guy\n\n[![Build Status](https://travis-ci.org/mrexox/commissioner.svg?branch=main)](https://travis-ci.org/mrexox/commissioner)\n[![Gem Version](https://badge.fury.io/rb/commissioner-guy.svg)](https://badge.fury.io/rb/commissioner-guy)\n\nCalculates charged and received amounts based on provided one. Calls your exchanger if needed. Applies commissions in order that you define.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'commissioner-guy', require: 'commissioner'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install commissioner-guy\n\n## Usage\n\n### First, configure the gem\n\n```ruby\nrequire 'commissioner'\n\nCommissioner.configure do |config|\n  # If you exchange money provider the lambda that receives\n  #   from   - string\n  #   to     - string\n  #   amount - Money instance\n  # 'amount' might be in 'from' or 'to' currency\n  # Must return either just exchanged amount or [amount, exchanged_rate]\n  config.exchanger = -\u003e(from, to, amount) { ... }\n\n  # When applying commission the amount might be rounded. This setting\n  # defined the rounding mode. Available modes are:\n  # - :up\n  # - :down\n  # - :half_up\n  # - :half_even\n  # See BigDecimal rounding modes for more\n  config.rouding_mode = :up\nend\n```\n\n### Explicit call\n\n```ruby\ncalculation = Commissioner.calculate(\n  charged_amount: 100,\n  charged_currency: 'EUR',\n  received_currency: 'USD',\n  commission: 10, # %\n  exchange_commission: 15 # %\n)\n\ncalculation.charged_amount # #\u003cMoney fractional:10000 currency:EUR\u003e\ncalculation.received_amount # #\u003cMoney fractional:7650 currency:USD\u003e\ncalculation.fee # #\u003cMoney fractional:1000 currency:EUR\u003e\ncalculation.exchange_fee # \u003cMoney fractional:1350 currency:USD\u003e\ncalculation.exchange_rate # 1 (only if config.exchanger returns it)\n```\n\n### As a mixin\n\n```ruby\nclass MyCalculator\n  include Commissiner::Mixin\n\n  def call(params)\n    calculate(params)\n  end\nend\n```\n\n#### Specify order\n\nYou can specify in which order calculation will be applied. The steps are:\n\n- exchange\n- commission\n- exchange_commission\n\n`exchange` - calls exchanger if currencies of received and charged amounts differ\n`commission` - applies typical commission operation\n`exchange_commission` - applies commission for exchange (in charged currency if ordered before `exchange` or in received currency if ordered after `exchange`)\n\n```ruby\nclass MyCalculator\n  include Commissioner::Mixin\n\n  # Default order is:\n  # - :commission\n  # - :exchange\n  # - :exchange_commission\n\n  Order[\n    :commission,\n    :exchange_commission,\n    :exchange\n  ]\nend\n\nMyCalculator.new.calculate(\n  received_amount: 100,\n  received_currency: 'EUR',\n  charged_currency: 'USD',\n  commission: 10,\n  exchange_commission: 15\n).to_h\n# =\u003e\n#   {\n#     :received_amount =\u003e #\u003cMoney fractional:10000 currency:EUR\u003e,\n#     :charged_amount =\u003e #\u003cMoney fractional:13072 currency:USD\u003e,\n#     :fee =\u003e #\u003cMoney fractional:1307 currency:USD\u003e,\n#     :exchange_fee =\u003e #\u003cMoney fractional:1765 currency:USD\u003e,\n#     :exchange_rate =\u003e 1\n#    }\n\n# Changing the order\nclass MyCalculator\n  Order[\n    :exchange_commission,\n    :exchange,\n    :commission\n  ]\nend\n\nMyCalculator.new.calculate(\n  received_amount: 100,\n  received_currency: 'EUR',\n  charged_currency: 'USD',\n  commission: 10,\n  exchange_commission: 15\n).to_h\n# =\u003e\n#   {\n#     :received_amount =\u003e #\u003cMoney fractional:10000 currency:EUR\u003e,\n#     :charged_amount =\u003e #\u003cMoney fractional:13072 currency:USD\u003e,\n#     :fee =\u003e #\u003cMoney fractional:1111 currency:EUR\u003e,\n#     :exchange_fee =\u003e #\u003cMoney fractional:1961 currency:USD\u003e,\n#     :exchange_rate =\u003e 1\n#    }\n```\n\n## Development\n\n- [x] Custom exchanger\n  - [x] If exchanging is not needed, it is not executed\n- [x] Commission for operation\n- [x] Commission for exchange\n- [x] No matter whether received or charged amount is provided, the calculation result is the same\n- [x] User-defined order of commissions aplying and exchanging\n- [ ] Custom commissions and exchanges in order\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/mrexox/commissioner.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrexox%2Fcommissioner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrexox%2Fcommissioner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrexox%2Fcommissioner/lists"}