rob-lester-jr04 / laravel-sendle
A Laravel wrapper for the Sendle shipping API
Fund package maintenance!
roblesterjr04
Requires
- php: ^8.1 || ^8.2
- fakerphp/faker: ^1.23
- guzzlehttp/guzzle: ^6.0 || ^7.0
- laravel/framework: ^9.0 || ^10.0
- league/flysystem-sftp-v3: ^3.16
Requires (Dev)
- phpunit/phpunit: >=6.0 || >=9.0 || >=10.0
README
A simple API wrapper for the Sendle shipping APIs
Installation
Install via composer
composer require rob-lester-jr04/laravel-sendle
Basic Usage
This package has a Facade for being used Standalone, in addition to Models that can be instantiated.
Create an order in Sendle
<?php use Sendle\Models\Order; $order = new Order([ 'receiver' => [ 'contact' => [ 'name' => 'John Smith', 'email' => 'john@example.com', ], 'address' => [ 'address_line1' => '123 Main Street', 'suburb' => 'New York', 'postcode' => '10010', 'state_name' => 'NY', 'country' => 'US' ], 'instructions' => 'Leave it on the step', ], 'description' => 'test package', 'product_code' => 'STANDARD-PICKUP', 'weight' => [ 'value' => 14, 'units' => 'oz', ] ]); $order->create(); // OR.... Order::create([ ... ]);
Retrieve Order
<?php use Sendle\Models\Order; Order::find('####');
Get Product Catelog
<?php use Sendle\Models\Product; use Sendle\Models\Entity; $receiver = new Entity([ 'contact' => [ 'name' => 'John Smith', 'email' => 'john@example.com', ], 'address' => [ 'address_line1' => '123 Main Street', 'suburb' => 'New York', 'postcode' => '10010', 'state_name' => 'NY', 'country' => 'US' ], 'instructions' => 'Leave it on the step', ]); $weight = 26.0; $products = Product::get($weight, $receiver);
Packages Trait
You can include the SendsPackages
trait on your models, such as a Client
model or User
model
<?php namespace App\Models; use Sendle\Traits\SendsPackages; class User extends Model { use SendsPackages; protected $sendleOrderCreate = [ // Map your users address fields to sendle. sendle=>model 'address_line1' => 'street_address', 'suburb' => 'city', 'state_name' => 'state', ]; //... } //.........// $user = User::find(4); $user->sendleOrderCreate('grandmas china', 36.0); //.........// $reciever = new Entity([ 'contact' => [ /** */], 'address' => [ /** */ ], ]); $user->sendleOrderCreate('grandmas china', 42, $receiver);
License
Laravel Sendle is open-sourced software licensed under the MIT license.