fwartner / printful
此包已被弃用且不再维护。未建议替代包。
Printful 的 Laravel API 包装器
dev-master
2015-09-06 12:59 UTC
This package is not auto-updated.
Last update: 2019-01-18 21:03:56 UTC
README
Printful 的 Laravel API 包装器
如何安装
首先,您需要将包安装到您的应用程序中
composer require fwartner/printful
接下来,您需要注册 Service Provider 和 Facade
Fwartner\Printful\PrintfulServiceProvider
'Printful' => Fwartner\Printful\Facades\PrintfulFacade::class,
如何使用
假设,您想获取商店信息
$sore = $pf->get('store');
获取产品列表
$products = $pf->get('products');
获取产品 10 的变体
$variants = $pf->get('products/10');
获取变体 1007 的信息
$data = $pf->get('products/variant/1007');
选择最近的 10 个订单
$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;
选择 ID 为 12345 的订单(用您的订单 ID 替换)
$order = $pf->get('orders/12345');
选择外部 ID 为 9900999 的订单(用您的订单外部 ID 替换)
$order = $pf->get(orders/@9900999');
取消 ID 为 12345 的订单(用您的订单 ID 替换)
$order = $pf->delete('orders/12345');
创建订单
$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
)
)
)
)
));
创建订单并立即确认
$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)
);
计算订单的运费
$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
)
));
异常
有两种异常类:PrintfulApiException
和 PintfulException
。
示例
API 响应状态码不成功
catch(PrintfulApiException $e){
echo 'Printful API Exception: '.$e->getCode().' '.$e->getMessage();
}
API 调用失败
catch(PrintfulException $e){
echo 'Printful Exception: '.$e->getMessage();
var_export($pf->getLastResponseRaw());
}