fwartner / printful
Laravel API-Wrapper for Printful
Installs: 458
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
This package is not auto-updated.
Last update: 2019-01-18 21:03:56 UTC
README
Laravel API-Wrapper for Printful
How to install
First of all, you need to install the package in your application:
composer require fwartner/printful
The next thing you need to do, is registering the Service Provider and the Facade:
Fwartner\Printful\PrintfulServiceProvider
'Printful' => Fwartner\Printful\Facades\PrintfulFacade::class,
How to use
Let´ say, you want to get store-information:
$sore = $pf->get('store');
To get the product list:
$products = $pf->get('products');
To get the variants for product 10:
$variants = $pf->get('products/10');
To get the information about Variant 1007:
$data = $pf->get('products/variant/1007');
Select 10 latest orders:
$orders = $pf->get('orders',array('limit'=>10));
var_export($orders);
$items = $pf->getgetItemCount(); //Get total number of items available from the previous request
echo "Total orders ". $items;
Select order with ID 12345 (Replace with your order's ID):
$order = $pf->get('orders/12345');
Select order with External ID 9900999 (Replace with your order's External ID):
$order = $pf->get(orders/@9900999');
Cancel order with ID 12345 (Replace with your order's ID):
$order = $pf->delete('orders/12345');
Create an order:
$order = $pf->post('orders',array(
'recipient' => array(
'name' => 'John Doe',
'address1' => '172 W Providencia Ave #105',
'city' => 'Burbank',
'state_code' => 'CA',
'country_code' => 'US',
'zip' => '91502'
),
'items' => array(
array(
'variant_id' => 1,//Small poster
'name' => 'Niagara Falls poster', //Display name
'retail_price' => '19.99', //Retail price for packing slip
'quantity' => 1,
'files' => array(
array(
'url' => 'http://example.com/files/posters/poster_1.jpg'
)
)
),
array(
'variant_id' => 1118,
'quantity' => 2,
'name' => 'Grand Canyon T-Shirt', //Display name
'retail_price' => '29.99', //Retail price for packing slip
'files' => array(
array(//Front print
'url' => 'http://example.com/files/tshirts/shirt_front.ai'
),
array(//Back print
'type' => 'back',
'url' => 'http://example.com/files/tshirts/shirt_back.ai'
),
array(//Mockup image
'type' => 'preview',
'url' => 'http://example.com/files/tshirts/shirt_mockup.jpg'
)
),
'options' => array(//Additional options
array(
'id' => 'remove_labels',
'value' => true
)
)
)
)
));
Create an order and confirm immediately:
$order = $pf->post('orders',
array(
'recipient' => array(
'name' => 'John Doe',
'address1' => '172 W Providencia Ave #105',
'city' => 'Burbank',
'state_code' => 'CA',
'country_code' => 'US',
'zip' => '91502'
),
'items' => array(
array(
'variant_id' => 1,//Small poster
'name' => 'Niagara Falls poster', //Display name
'retail_price' => '19.99', //Retail price for packing slip
'quantity' => 1,
'files' => array(
array(
'url' => 'http://example.com/files/posters/poster_1.jpg'
)
)
)
)
),
array('confirm'=>1)
);
Calculate shipping rates for an order:
$rates = $pf->post('shipping/rates',array(
'recipient' => array(
'country_code'=>'US',
'state_code' => 'CA'
),
'items'=> array(
array('variant_id'=>1,'quantity'=>1), //Small poster
array('variant_id'=>1118,'quantity'=>2) //Alternative T-Shirt
)
));
Exceptions
There are two Exception-Classes: PrintfulApiException
and PintfulException
.
Example:
API response status code was not successful:
catch(PrintfulApiException $e){
echo 'Printful API Exception: '.$e->getCode().' '.$e->getMessage();
}
API Call failed:
catch(PrintfulException $e){
echo 'Printful Exception: '.$e->getMessage();
var_export($pf->getLastResponseRaw());
}