{"id":19706748,"url":"https://github.com/unisharp/cart","last_synced_at":"2025-11-22T16:01:35.651Z","repository":{"id":57075602,"uuid":"125465168","full_name":"UniSharp/cart","owner":"UniSharp","description":"Shopping Cart for unisharp buyable","archived":false,"fork":false,"pushed_at":"2018-09-26T06:42:08.000Z","size":122,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-27T18:07:52.383Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/UniSharp.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":"2018-03-16T04:51:31.000Z","updated_at":"2018-09-26T06:42:10.000Z","dependencies_parsed_at":"2022-08-24T14:55:44.956Z","dependency_job_id":null,"html_url":"https://github.com/UniSharp/cart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/UniSharp/cart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Fcart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Fcart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Fcart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Fcart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UniSharp","download_url":"https://codeload.github.com/UniSharp/cart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UniSharp%2Fcart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285817006,"owners_count":27236561,"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","status":"online","status_checked_at":"2025-11-22T02:00:05.934Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T21:36:51.901Z","updated_at":"2025-11-22T16:01:35.631Z","avatar_url":"https://github.com/UniSharp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UniSharp Cart\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nLet buyable item can add to cart,\nand make order with cart's items,\nand also provide payment feature.\n\nThis package depends on:\n\n- [unisharp/buyable](https://github.com/UniSharp/buyable)\n- [unisharp/pricing](https://github.com/UniSharp/pricing)\n- [voicetube/taiwan-payment-gateway](https://github.com/voicetube/Taiwan-Payment-Gateway)\n- [unisharp/payment](https://github.com/UniSharp/unisharp-payment)\n\n## Installation\n\n```composer require unisharp/cart dev-master```\n\n## Cart Usages\n\n### Use Api\n\nInclude api into ```api.php```\n\n```php\nRoute::group(['prefix' =\u003e 'v1'], function () {\n    CartManager::route();\n});\n```\n\nroute lists:\n\n| Method | Uri                        | Comment                                  |\n|:-------|:---------------------------|:-----------------------------------------|\n| POST   | api/v1/carts               | Create the cart                          |\n| DELETE | api/v1/carts/{cart}        | Delete the cart and cart's items         |\n| GET    | api/v1/carts/{cart}        | Get the cart and cart's items            |\n| PUT    | api/v1/carts/{cart}        | Add item(s) to the cart                  |\n| POST   | api/v1/carts/{cart}        | Refresh cart and add item(s) to the cart |\n| DELETE | api/v1/carts/{cart}/{item} | Remove a item from the cart              |\n\n### Use CartManager\n\nCreate a new cart\n\n```php\n$cart = CartManager::make();\n```\n\nGet a exist cart\n\n```php\n$cart = CartManager::make($cart);\n```\n\nAdd item to the cart\n\n```php\n$item = new Item([\n    'id' =\u003e 1,\n    '$quantity' =\u003e 10,\n    'extra' =\u003e [\n        'comment' =\u003e '...'\n    ]\n]);\n\n$cart-\u003eadd($item-\u003eid, $item-\u003equantity, $item-\u003eextra)-\u003esave();\n```\n\nGet cart's items\n\n```php\n$cart-\u003egetCartInstance()-\u003egetItems();\n```\n\nRemove item from the cart\n\n```php\n$cart-\u003eremove($item)-\u003esave();\n```\n\nClean cart's items\n\n```php\n$cart-\u003eclean();\n```\n\nDestroy the cart\n\n```php\n$cart-\u003edelete();\n```\n\n## Order Usages\n\n### Use Api\n\nInclude api into ```api.php```\n\n```php\nRoute::group(['prefix' =\u003e 'v1'], function () {\n    OrderManager::route();\n});\n```\n\nroute lists:\n\n| Method | Uri                          | Comment                                              |\n|:-------|:-----------------------------|:-----------------------------------------------------|\n| POST   | api/v1/orders                | Create an order                                      |\n| GET    | api/v1/orders                | List all orders                                      |\n| DELETE | api/v1/orders/{order}        | Delete the order                                     |\n| PUT    | api/v1/orders/{order}        | Update the order's status, price and shipping_status |\n| GET    | api/v1/orders/{order}        | Get the order                                        |\n| DELETE | api/v1/orders/{order}/{item} | Remove a item from the order                         |\n| GET    | api/v1/user/me/order-items   | Get current user's orders                            |\n\n### Use OrderManager\n\nCreate an order manager\n\n```php\n// Get order manager\n$order = OrderManager::make();\n\n// Assign operator\n$order-\u003eassign(auth()-\u003euser());\n\n// Checkout cart's items and buyer and receiver's information\n$items = CartManager::make($cart)-\u003egetItems();\n$information = [\n    'buyer' =\u003e [],\n    'receiver' =\u003e [],\n    'payment' =\u003e 'credit'\n];\n$order-\u003echeckout(items, informations)\n```\n\nGet an exist order\n\n```php\n$order = OrderManager::make($order)-\u003egetOrderInstance();\n```\n\n# Pricing Usages\n\nBoth of CartManager and OrderManager already have trait\n\n```php\nclass CartManager\n{\n    use CanPricing;\n    ...\n}\n```\n\nCustomize pricing module\n\n```php\nuse UniSharp\\Pricing\\Pricing;\nuse UniSharp\\Pricing\\ModuleContract;\n\nclass CustomPricingModule implements ModuleContract\n{\n    public function handle(Pricing $pricing, Closure $next)\n    {\n        ...\n        return $next($pricing);\n    }\n\n    public function finish(Pricing $pricing)\n    {\n        ...\n    }\n}\n```\n\nSet Custom pricing module in `config/pricing.php`\n\n```php\nreturn [\n    'modules' =\u003e [\n        CustomPricingModule::class\n    ],\n];\n```\n\nGet pricing\n\n```php\n// get original price\n$cart-\u003egetOriginalPrice();\n\n// get total price\n$cart-\u003egetPrice();\n\n// get fee\n$cart-\u003egetFee();\n```\n\nMore details on [unisharp/pricing](https://github.com/UniSharp/pricing)\n\n## Payment Usages\n\nSet payment gateway config\n\n```php\nreturn [\n    'payment' =\u003e [\n        'driver'         =\u003e 'EcPay',\n        'merchantId'     =\u003e '2000132',\n        'hashKey'        =\u003e '5294y06JbISpM5x9',\n        'hashIV'         =\u003e 'v77hoKGq4kWxNNIS',\n        'actionUrl'      =\u003e 'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/',\n        'returnUrl'      =\u003e 'https://localhost/payment/confirm',\n        'notifyUrl'      =\u003e 'https://localhost/payment/notify',\n        'clientBackUrl'  =\u003e 'https://localhost/payment/return',\n        'paymentInfoUrl' =\u003e 'https://localhost/payment/information' \n    ],\n]\n```\n\nSet api into ```api.php```\n\n```php\n// Include payment api\nRoute::group(['prefix' =\u003e 'v1'], function () {\n    OrderManager::route();\n});\n\n// Implement payment response url\nRoute::group(['prefix' =\u003e 'v1/payment'], function () {\n    Route::get('confirm', function () {...});\n    Route::get('notify', function () {...});\n    Route::get('return', function () {...});\n    Route::get('information', function () {...});\n});\n```\n\n| Method | Uri                          | Comment                 |\n|:-------|:-----------------------------|:------------------------|\n| GET    | api/v1/orders/{order}/pay    | Call payment            |\n| GET    | api/v1/payment/confirm       | Payment completed url   |\n| GET    | api/v1/payment/notify        | Notify url              |\n| GET    | api/v1/payment/return        | Client back url         |\n| GET    | api/v1/payment/information   | Payment Information url |\n\n[ico-version]: https://img.shields.io/packagist/v/UniSharp/cart.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/UniSharp/cart/master.svg?style=flat-square\n[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/UniSharp/cart.svg?style=flat-square\n[ico-code-quality]: https://img.shields.io/scrutinizer/g/UniSharp/cart.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/UniSharp/cart.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/unisharp/cart\n[link-travis]: https://travis-ci.org/UniSharp/cart\n[link-scrutinizer]: https://scrutinizer-ci.com/g/UniSharp/cart/code-structure\n[link-code-quality]: https://scrutinizer-ci.com/g/UniSharp/cart\n[link-downloads]: https://packagist.org/packages/UniSharp/cart\n[link-author]: https://github.com/UniSharp\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funisharp%2Fcart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funisharp%2Fcart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funisharp%2Fcart/lists"}