rhysnhall / etsy-php-sdk

PHP SDK for Etsy API v3.
MIT License
47 stars 36 forks source link

use createShipment #33

Closed dinhbang closed 2 months ago

dinhbang commented 2 months ago

Hi All,

I want to use createShipment in src/Resources/Receipt.php But, I don't see any function init Receipt resource in src/Etsy.php

Could you tell me how to use createShipment ?

Regards, Bang.

rhysnhall commented 2 months ago

Hello,

You can get a receipt via the Etsy\Resources\Shop resource in the older package version. See this link.

However having to get the Shop first is pointless at times. For this reason I suggest upgrading to the latest version of the package.

dinhbang commented 2 months ago

Hello,

Thank you for your support. Your reference "See this link" is get list orders. But, I need to create shipment for one order. My business: I sync orders from Etsy via getReceipts function ( I did). My printer partner will to process ( may be in one or two day), They print and shipping to buyer. Next step I want to create shipment for printing order. @rhysnhall I ready update the latest version. I have tried code below: getShop(SHOP_ID)->getReceipt(RECEIPT_ID)->createShipment($dataShipping)

It is error: Call to undefined method Etsy\Resources\Receipt::createResource()

Best regards, Bang T.

rhysnhall commented 2 months ago

@dinhbang can you check your composer.json file and let me know what version you are using? I'll then be able to provide the correct advice.

dinhbang commented 2 months ago

@rhysnhall . Please look:

"rhysnhall/etsy-php-sdk": "^0.4.0",

rhysnhall commented 2 months ago

Thanks for that. The previous link will give you all you need. But here is a quickstart:

For v0.4.0

$etsy = new Etsy\Etsy($api_key, $access_token);
$shop = $user->getShop();
$receipt = $shop->getReceipt($receipt_id);

// Create the shipment
$shipment = $receipt->createShipment($data);

OR

Manual approach

use Etsy\Etsy;

new Etsy($api_key, $access_token);
$response = Etsy::$client->post("/application/shops/{$shop_id}/receipts/{$receipt_id}/tracking", $data);
$shipment = Etsy::getResource($response, "Shipment");

Recommended

For v1.0

new Etsy\Etsy($apiKey, $accessToken);
$shipment = Etsy\Resources\Shipment::create($shop_id, $receipt_id, $data);

As suggested, you should upgrade to 1.0 if possible. Having to fetch the Shop and then the Receipt before being able to create a Shipment is redundant.