unisharp / cart
let buyable item can add to cart
Installs: 1 739
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 12
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- askedio/laravel-soft-cascade: >5.5.0
- illuminate/config: >5.5.0
- illuminate/database: >5.5.0
- illuminate/support: >5.5.0
- konekt/enum-eloquent: ^1.1
- unisharp/buyable: dev-master
- unisharp/payment: dev-master
- unisharp/pricing: dev-master
- voicetube/taiwan-payment-gateway: dev-master
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.6.0
- mockery/mockery: ^0.9.4
- orchestra/database: ~3.6.0
- orchestra/testbench: ~3.6.0
- phpunit/phpunit: ^7.0
- sebastian/diff: ^3.0.0
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-11-06 19:52:50 UTC
README
Let buyable item can add to cart, and make order with cart's items, and also provide payment feature.
This package depends on:
Installation
composer require unisharp/cart dev-master
Cart Usages
Use Api
Include api into api.php
Route::group(['prefix' => 'v1'], function () { CartManager::route(); });
route lists:
Use CartManager
Create a new cart
$cart = CartManager::make();
Get a exist cart
$cart = CartManager::make($cart);
Add item to the cart
$item = new Item([ 'id' => 1, '$quantity' => 10, 'extra' => [ 'comment' => '...' ] ]); $cart->add($item->id, $item->quantity, $item->extra)->save();
Get cart's items
$cart->getCartInstance()->getItems();
Remove item from the cart
$cart->remove($item)->save();
Clean cart's items
$cart->clean();
Destroy the cart
$cart->delete();
Order Usages
Use Api
Include api into api.php
Route::group(['prefix' => 'v1'], function () { OrderManager::route(); });
route lists:
Use OrderManager
Create an order manager
// Get order manager $order = OrderManager::make(); // Assign operator $order->assign(auth()->user()); // Checkout cart's items and buyer and receiver's information $items = CartManager::make($cart)->getItems(); $information = [ 'buyer' => [], 'receiver' => [], 'payment' => 'credit' ]; $order->checkout(items, informations)
Get an exist order
$order = OrderManager::make($order)->getOrderInstance();
Pricing Usages
Both of CartManager and OrderManager already have trait
class CartManager { use CanPricing; ... }
Customize pricing module
use UniSharp\Pricing\Pricing; use UniSharp\Pricing\ModuleContract; class CustomPricingModule implements ModuleContract { public function handle(Pricing $pricing, Closure $next) { ... return $next($pricing); } public function finish(Pricing $pricing) { ... } }
Set Custom pricing module in config/pricing.php
return [ 'modules' => [ CustomPricingModule::class ], ];
Get pricing
// get original price $cart->getOriginalPrice(); // get total price $cart->getPrice(); // get fee $cart->getFee();
More details on unisharp/pricing
Payment Usages
Set payment gateway config
return [ 'payment' => [ 'driver' => 'EcPay', 'merchantId' => '2000132', 'hashKey' => '5294y06JbISpM5x9', 'hashIV' => 'v77hoKGq4kWxNNIS', 'actionUrl' => 'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/', 'returnUrl' => 'https://localhost/payment/confirm', 'notifyUrl' => 'https://localhost/payment/notify', 'clientBackUrl' => 'https://localhost/payment/return', 'paymentInfoUrl' => 'https://localhost/payment/information' ], ]
Set api into api.php
// Include payment api Route::group(['prefix' => 'v1'], function () { OrderManager::route(); }); // Implement payment response url Route::group(['prefix' => 'v1/payment'], function () { Route::get('confirm', function () {...}); Route::get('notify', function () {...}); Route::get('return', function () {...}); Route::get('information', function () {...}); });