{"id":21901200,"url":"https://github.com/moltin/currency","last_synced_at":"2025-04-06T11:08:10.077Z","repository":{"id":8017796,"uuid":"9426605","full_name":"moltin/currency","owner":"moltin","description":"Handles currency calculations, storage etc","archived":false,"fork":false,"pushed_at":"2020-09-16T10:36:20.000Z","size":121,"stargazers_count":106,"open_issues_count":1,"forks_count":20,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-30T09:09:24.383Z","etag":null,"topics":["api","currencies","currency","exchange","moltin"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moltin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-14T08:45:37.000Z","updated_at":"2025-02-20T21:44:13.000Z","dependencies_parsed_at":"2022-09-13T10:40:14.110Z","dependency_job_id":null,"html_url":"https://github.com/moltin/currency","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcurrency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcurrency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcurrency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moltin%2Fcurrency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moltin","download_url":"https://codeload.github.com/moltin/currency/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471519,"owners_count":20944158,"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":["api","currencies","currency","exchange","moltin"],"created_at":"2024-11-28T15:12:41.175Z","updated_at":"2025-04-06T11:08:10.052Z","avatar_url":"https://github.com/moltin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Currency Package\n\n[![Build Status](https://secure.travis-ci.org/moltin/currency.png)](http://travis-ci.org/moltin/currency)\n\n* [Website](http://molt.in)\n* [License](https://github.com/moltin/currency/blob/master/LICENSE)\n* Version: dev\n\nThe Moltin currency composer package makes it easy to implement multi-currency pricing into your application and\nstore the exchange data using one of the numerous data stores provided. You can also inject your own data store if you\nwould like your data to be stored elsewhere.\n\n## Installation\nDownload and install composer from `http://www.getcomposer.org/download`\n\nAdd the following to your project `composer.json` file\n```\n{\n    \"require\": {\n        \"moltin/currency\": \"~1.0.0\"\n    }\n}\n```\nWhen you're done just run `php composer.phar install` and the package is ready to be used.\n\n## Usage\nBelow is a basic usage guide for this package.\n\n### Instantiating currency\nBefore you begin, you will need to know which storage, currencies and exchange method you are going to use. The exchange method\ndefines where your exchange rates are retrieved from. The currencies method is used to retrieve your supported currencies\nfor the current application.\n\nIn this example we're going to use the currencies file, exchange file and session for storage.\n\n```php\nuse Moltin\\Currency\\Currency as Currency;\nuse Moltin\\Currency\\Format\\Runtime as RuntimeFormat;\nuse Moltin\\Currency\\Exchange\\OpenExchangeRates as OpenExchange;\n\n$currency = new Currency(new OpenExchange($app_id), new RuntimeFormat);\n```\n\n### Setting the value\nNow that you have Currency instantiated, you will now need to tell it what value you would like to convert.\nYou can do this using the following method.\n\n```php\n$currency-\u003econvert(9.33)-\u003efrom('GBP');\n```\n\n### Getting the value\nThe most basic action you can perform is retrieve the original value back from the method.\n\n```php\n// Returns 9.33\n$value = $currency-\u003evalue();\n```\n\n### Formatting as a currency\nBy default the currency is set to GBP so calling currency will format the value to a string with £ and correct\ndecimal and thousand seperators.\n\n```php\n// Returns £9.33\n$value = $currency-\u003eformat();\n```\n\n### Rounding to common values\nThere are a number of common pricing formats built in to make \"nice\" prices easy to implement. These\nformats changes the default value and return the object to allow for chaining.\n\n```php\n// Sets value to 10.00\n$currency-\u003ezeros();\n\n// Sets value to 9.99\n$currency-\u003enines();\n\n// Sets value to 9.50\n$currency-\u003efifty();\n\n// Returns £9.50\n$value = $currency-\u003efifty()-\u003eformat();\n```\n\n### Currency Exchange\nThe package makes it as easy as possible to quickly switch between currencies. Before each exchange the value\nis reset to default to ensure the correct price is assigned.\n\n```php\n// Returns ~$14.47\n$value = $currency-\u003econvert(9.33)-\u003efrom('GBP')-\u003eto('USD')-\u003eformat();\n\n// Returns ~14.50\n$value = $currency-\u003econvert(9.33)-\u003efrom('GBP')-\u003eto('USD')-\u003efifty()-\u003evalue();\n```\n\n### Resetting the value\nAfter using exchange or any of the rounding functions to retrieve the default value you must call reset.\n\n```php\n// Returns 10.00\n$value = $currency-\u003ezeros()-\u003evalue();\n\n// Returns 9.33\n$value = $currency-\u003ereset()-\u003evalue();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoltin%2Fcurrency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoltin%2Fcurrency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoltin%2Fcurrency/lists"}