From c5121206ccbc34b71d6fb9081a21f554ae4d0076 Mon Sep 17 00:00:00 2001 From: Saiful Islam Date: Thu, 16 Apr 2020 15:31:54 +0600 Subject: [PATCH 01/71] remove extra Parentheses --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 34ad31c..28bee4a 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ $shopify->Order($orderID)->put($updateInfo); ```php $webHookID = 453487303; -$shopify->Webhook($webHookID)->delete()); +$shopify->Webhook($webHookID)->delete(); ``` From 6eaa205a93362d9a2adcae5cb7b378b83dc9bf88 Mon Sep 17 00:00:00 2001 From: Steffen Persch Date: Tue, 5 May 2020 12:28:31 +0200 Subject: [PATCH 02/71] price rule endpoint supports count --- lib/PriceRule.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/PriceRule.php b/lib/PriceRule.php index de08014..ab77a4e 100644 --- a/lib/PriceRule.php +++ b/lib/PriceRule.php @@ -26,11 +26,6 @@ class PriceRule extends ShopifyResource */ public $resourceKey = 'price_rule'; - /** - * @inheritDoc - */ - public $countEnabled = false; - /** * @inheritDoc */ From 989d7b35788c3d4a1f70e9d5f77b167ce2d88c42 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 14 May 2020 10:08:23 +0200 Subject: [PATCH 03/71] Update ShopifySDK.php Add missing @property-read and @method helpers. --- lib/ShopifySDK.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index e6e66f5..1d9276d 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -68,6 +68,7 @@ /** * @property-read AbandonedCheckout $AbandonedCheckout + * @property-read ApplicationCharge $ApplicationCharge * @property-read Blog $Blog * @property-read CarrierService $CarrierService * @property-read Collect $Collect @@ -81,7 +82,6 @@ * @property-read Discount $Discount * @property-read DiscountCode $DiscountCode * @property-read DraftOrder $DraftOrder - * @property-read PriceRule $PriceRule * @property-read Event $Event * @property-read FulfillmentService $FulfillmentService * @property-read GiftCard $GiftCard @@ -96,8 +96,10 @@ * @property-read Product $Product * @property-read ProductListing $ProductListing * @property-read ProductVariant $ProductVariant + * @property-read PriceRule $PriceRule * @property-read RecurringApplicationCharge $RecurringApplicationCharge * @property-read Redirect $Redirect + * @property-read Report $Report * @property-read ScriptTag $ScriptTag * @property-read ShippingZone $ShippingZone * @property-read Shop $Shop @@ -108,6 +110,7 @@ * @property-read GraphQL $GraphQL * * @method AbandonedCheckout AbandonedCheckout(integer $id = null) + * @method ApplicationCharge ApplicationCharge(integer $id = null) * @method Blog Blog(integer $id = null) * @method CarrierService CarrierService(integer $id = null) * @method Collect Collect(integer $id = null) @@ -121,7 +124,6 @@ * @method Discount Discount(integer $id = null) * @method DraftOrder DraftOrder(integer $id = null) * @method DiscountCode DiscountCode(integer $id = null) - * @method PriceRule PriceRule(integer $id = null) * @method Event Event(integer $id = null) * @method FulfillmentService FulfillmentService(integer $id = null) * @method GiftCard GiftCard(integer $id = null) @@ -136,8 +138,10 @@ * @method Product Product(integer $id = null) * @method ProductListing ProductListing(integer $id = null) * @method ProductVariant ProductVariant(integer $id = null) + * @method PriceRule PriceRule(integer $id = null) * @method RecurringApplicationCharge RecurringApplicationCharge(integer $id = null) * @method Redirect Redirect(integer $id = null) + * @method Report Report(integer $id = null) * @method ScriptTag ScriptTag(integer $id = null) * @method ShippingZone ShippingZone(integer $id = null) * @method Shop Shop(integer $id = null) From 270b7dd1d62c9fce3d64ad339913d8ec6311574b Mon Sep 17 00:00:00 2001 From: Victor Kislichenko Date: Mon, 1 Jun 2020 22:35:17 +0300 Subject: [PATCH 04/71] added ShopifyPayment Dispute resource --- README.md | 2 ++ lib/Dispute.php | 30 ++++++++++++++++++++++++++++++ lib/ShopifyPayment.php | 35 +++++++++++++++++++++++++++++++++++ lib/ShopifyResource.php | 2 +- lib/ShopifySDK.php | 2 ++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/Dispute.php create mode 100644 lib/ShopifyPayment.php diff --git a/README.md b/README.md index a507d8a..a48fd44 100644 --- a/README.md +++ b/README.md @@ -359,6 +359,8 @@ Some resources are available directly, some resources are only available through - [Shop](https://help.shopify.com/api/reference/shop) _(read only)_ - [SmartCollection](https://help.shopify.com/api/reference/smartcollection) - SmartCollection -> [Event](https://help.shopify.com/api/reference/event/) +- [ShopifyPayment](https://shopify.dev/docs/admin-api/rest/reference/shopify_payments/) +- ShopifyPayment -> [Dispute](https://shopify.dev/docs/admin-api/rest/reference/shopify_payments/dispute/) _(read only)_ - [Theme](https://help.shopify.com/api/reference/theme) - Theme -> [Asset](https://help.shopify.com/api/reference/asset/) - [User](https://help.shopify.com/api/reference/user) _(read only, Shopify Plus Only)_ diff --git a/lib/Dispute.php b/lib/Dispute.php new file mode 100644 index 0000000..e769872 --- /dev/null +++ b/lib/Dispute.php @@ -0,0 +1,30 @@ + + * Created at 01/06/2020 16:45 AM UTC+03:00 + * + * @see https://shopify.dev/docs/admin-api/rest/reference/shopify_payments/dispute Shopify API Reference for Dispute + */ + +namespace PHPShopify; + + +/** + * -------------------------------------------------------------------------- + * ShopifyPayment -> Child Resources + * -------------------------------------------------------------------------- + * @property-read ShopifyResource $DiscountCode + * + * @method ShopifyResource DiscountCode(integer $id = null) + * + */ +class Dispute extends ShopifyResource +{ + /** + * @inheritDoc + */ + public $resourceKey = 'dispute'; + + +} \ No newline at end of file diff --git a/lib/ShopifyPayment.php b/lib/ShopifyPayment.php new file mode 100644 index 0000000..a6da406 --- /dev/null +++ b/lib/ShopifyPayment.php @@ -0,0 +1,35 @@ + + * Created at 01/06/2020 16:45 AM UTC+03:00 + * + * @see https://shopify.dev/docs/admin-api/rest/reference/shopify_payments Shopify API Reference for ShopifyPayment + */ + +namespace PHPShopify; + + +/** + * -------------------------------------------------------------------------- + * ShopifyPayment -> Child Resources + * -------------------------------------------------------------------------- + * @property-read ShopifyResource $Dispute + * + * @method ShopifyResource Dispute(integer $id = null) + * + */ +class ShopifyPayment extends ShopifyResource +{ + /** + * @inheritDoc + */ + public $resourceKey = 'shopify_payment'; + + /** + * @inheritDoc + */ + protected $childResource = array( + 'Dispute' + ); +} \ No newline at end of file diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 66ce2b7..5e4ca00 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -530,7 +530,7 @@ public function processResponse($responseArray, $dataKey = null) $httpCode = CurlRequest::$lastHttpCode; if ($httpCode != null && $httpCode != $httpOK && $httpCode != $httpCreated && $httpCode != $httpDeleted) { - throw new Exception\CurlException("Request failed with HTTP Code $httpCode."); + throw new Exception\CurlException("Request failed with HTTP Code $httpCode.", $httpCode); } } diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 1d9276d..94dbe81 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -104,6 +104,7 @@ * @property-read ShippingZone $ShippingZone * @property-read Shop $Shop * @property-read SmartCollection $SmartCollection + * @property-read ShopifyPayment $ShopifyPayment * @property-read Theme $Theme * @property-read User $User * @property-read Webhook $Webhook @@ -196,6 +197,7 @@ class ShopifySDK 'ShippingZone', 'Shop', 'SmartCollection', + 'ShopifyPayment', 'Theme', 'User', 'Webhook', From d4c9467587a401815d668e6cea3d113921d25667 Mon Sep 17 00:00:00 2001 From: wissem Date: Wed, 17 Jun 2020 18:47:33 +0200 Subject: [PATCH 05/71] Add Shopify API headers as a config to the SDK --- README.md | 9 +++++++++ lib/ShopifyResource.php | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index a48fd44..80d02fe 100644 --- a/README.md +++ b/README.md @@ -485,6 +485,15 @@ The custom methods are specific to some resources which may not be available for - [current()](https://help.shopify.com/api/reference/user#current) Get the current logged-in user +### Shopify API features headers +To send `X-Shopify-Api-Features` headers while using the SDK, you can use the following: + +``` +$config['ShopifyApiFeatures'] = ['include-presentment-prices']; +$shopify = new PHPShopify\ShopifySDK($config); +``` + + ## Reference - [Shopify API Reference](https://help.shopify.com/api/reference/) diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 5e4ca00..f1942ff 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -149,6 +149,12 @@ public function __construct($id = null, $parentResourceUrl = '') } elseif (!isset($config['ApiKey']) || !isset($config['Password'])) { throw new SdkException("Either AccessToken or ApiKey+Password Combination (in case of private API) is required to access the resources. Please check SDK configuration!"); } + + if (isset($config['ShopifyApiFeatures'])) { + foreach($config['ShopifyApiFeatures'] as $apiFeature) { + $this->httpHeaders['X-Shopify-Api-Features'] = $apiFeature; + } + } } /** From dfeee2b1e3b56b2a17f22c91d5c4282ed1fb3166 Mon Sep 17 00:00:00 2001 From: Matthew Crigger Date: Tue, 14 Jul 2020 13:41:55 -0400 Subject: [PATCH 06/71] Initial Commit Initial commit based on code from rjacobso --- lib/Balance.php | 44 ++++++++++++++++++++++++++++++++++++++++++ lib/Payouts.php | 25 ++++++++++++++++++++++++ lib/ShopifyPayment.php | 11 ++++++++++- lib/ShopifySDK.php | 5 +++++ lib/Transactions.php | 19 ++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 lib/Balance.php create mode 100644 lib/Payouts.php create mode 100644 lib/Transactions.php diff --git a/lib/Balance.php b/lib/Balance.php new file mode 100644 index 0000000..112e250 --- /dev/null +++ b/lib/Balance.php @@ -0,0 +1,44 @@ + Child Resources + * -------------------------------------------------------------------------- + * + * + */ +class Balance extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'balance'; + + /** + * Get the pluralized version of the resource key + * + * Normally its the same as $resourceKey appended with 's', when it's different, the specific resource class will override this function + * + * @return string + */ + protected function pluralizeKey() + { + return $this->resourceKey; + } + + /** + * If the resource is read only. (No POST / PUT / DELETE actions) + * + * @var boolean + */ + public $readOnly = true; + + /** + * @inheritDoc + */ + protected $childResource = array( + 'Transactions' + ); +} \ No newline at end of file diff --git a/lib/Payouts.php b/lib/Payouts.php new file mode 100644 index 0000000..0cd2ec6 --- /dev/null +++ b/lib/Payouts.php @@ -0,0 +1,25 @@ + + * Created at 11/11/19 12:26 PM UTC-05:00 + * + * @see https://help.shopify.com/en/api/reference/shopify_payments/payout Shopify API Reference for Shopify Payment Payouts + */ + +namespace PHPShopify; + +/** + * -------------------------------------------------------------------------- + * ShopifyPayment -> Child Resources + * -------------------------------------------------------------------------- + * + * + */ +class Payouts extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'payout'; +} \ No newline at end of file diff --git a/lib/ShopifyPayment.php b/lib/ShopifyPayment.php index a6da406..5577499 100644 --- a/lib/ShopifyPayment.php +++ b/lib/ShopifyPayment.php @@ -26,10 +26,19 @@ class ShopifyPayment extends ShopifyResource */ public $resourceKey = 'shopify_payment'; + /** + * If the resource is read only. (No POST / PUT / DELETE actions) + * + * @var boolean + */ + public $readOnly = true; + /** * @inheritDoc */ protected $childResource = array( - 'Dispute' + 'Balance', + 'Dispute', + 'Payouts', ); } \ No newline at end of file diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 94dbe81..9000e84 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -146,6 +146,7 @@ * @method ScriptTag ScriptTag(integer $id = null) * @method ShippingZone ShippingZone(integer $id = null) * @method Shop Shop(integer $id = null) + * @method ShopifyPayment ShopifyPayment() * @method SmartCollection SmartCollection(integer $id = null) * @method Theme Theme(int $id = null) * @method User User(integer $id = null) @@ -235,16 +236,20 @@ class ShopifySDK protected $childResources = array( 'Article' => 'Blog', 'Asset' => 'Theme', + 'Balance' => 'ShopifyPayment', 'CustomerAddress' => 'Customer', + 'Dispute' => 'ShopifyPayment', 'Fulfillment' => 'Order', 'FulfillmentEvent' => 'Fulfillment', 'OrderRisk' => 'Order', + 'Payouts' => 'ShopifyPayment', 'ProductImage' => 'Product', 'ProductVariant' => 'Product', 'DiscountCode' => 'PriceRule', 'Province' => 'Country', 'Refund' => 'Order', 'Transaction' => 'Order', + 'Transactions' => 'Balance', 'UsageCharge' => 'RecurringApplicationCharge', ); diff --git a/lib/Transactions.php b/lib/Transactions.php new file mode 100644 index 0000000..792f8b4 --- /dev/null +++ b/lib/Transactions.php @@ -0,0 +1,19 @@ + Date: Fri, 17 Jul 2020 12:30:42 -0400 Subject: [PATCH 07/71] Update ShopifyPayment.php Added property / method lines for balance and payouts. --- lib/ShopifyPayment.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ShopifyPayment.php b/lib/ShopifyPayment.php index 5577499..54fc6b3 100644 --- a/lib/ShopifyPayment.php +++ b/lib/ShopifyPayment.php @@ -18,6 +18,15 @@ * * @method ShopifyResource Dispute(integer $id = null) * + * @property-read ShopifyResource $Balance + * + * @method ShopifyResource Balance(integer $id = null) + * + * @property-read ShopifyResource $Payouts + * + * @method ShopifyResource Payouts(integer $id = null) + * + */ class ShopifyPayment extends ShopifyResource { From 6a114af6763217d0b32920c09b4a4a55663dca08 Mon Sep 17 00:00:00 2001 From: Matthew Crigger Date: Fri, 17 Jul 2020 12:43:33 -0400 Subject: [PATCH 08/71] Author and Links Updated authoring and help links. --- lib/Balance.php | 7 +++++++ lib/Payouts.php | 2 +- lib/Transactions.php | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Balance.php b/lib/Balance.php index 112e250..4144c5c 100644 --- a/lib/Balance.php +++ b/lib/Balance.php @@ -1,4 +1,11 @@ + * @author Matthew Crigger + * + * @see https://help.shopify.com/en/api/reference/shopify_payments/balance Shopify API Reference for Shopify Payment Balance + */ namespace PHPShopify; diff --git a/lib/Payouts.php b/lib/Payouts.php index 0cd2ec6..e43245b 100644 --- a/lib/Payouts.php +++ b/lib/Payouts.php @@ -2,7 +2,7 @@ /** * Created by PhpStorm. * @author Robert Jacobson - * Created at 11/11/19 12:26 PM UTC-05:00 + * @author Matthew Crigger * * @see https://help.shopify.com/en/api/reference/shopify_payments/payout Shopify API Reference for Shopify Payment Payouts */ diff --git a/lib/Transactions.php b/lib/Transactions.php index 792f8b4..0b45020 100644 --- a/lib/Transactions.php +++ b/lib/Transactions.php @@ -1,4 +1,11 @@ + * @author Matthew Crigger + * + * @see https://help.shopify.com/en/api/reference/shopify_payments/transaction Shopify API Reference for Shopify Payment Transactions + */ namespace PHPShopify; From 279d5214312d4f8afe7ca24b59327364ce724fd2 Mon Sep 17 00:00:00 2001 From: Erdal G Date: Sun, 23 Aug 2020 13:29:35 +0200 Subject: [PATCH 09/71] Update Customer.php Customer search takes (a very useful) query string parameter: https://shopify.dev/docs/admin-api/rest/reference/customers/customer#search-2020-07 --- lib/Customer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Customer.php b/lib/Customer.php index a058624..3c3a675 100644 --- a/lib/Customer.php +++ b/lib/Customer.php @@ -22,7 +22,7 @@ * -------------------------------------------------------------------------- * Customer -> Custom actions * -------------------------------------------------------------------------- - * @method array search() Search for customers matching supplied query + * @method array search(string $query = '') Search for customers matching supplied query */ class Customer extends ShopifyResource { @@ -60,4 +60,4 @@ public function send_invite($customer_invite = array()) return $this->post($dataArray, $url, false); } -} \ No newline at end of file +} From d0e7fe7e9e046af71966ca55b9597d3790ed580c Mon Sep 17 00:00:00 2001 From: Saumil Nagariya Date: Mon, 24 Aug 2020 20:55:30 +0530 Subject: [PATCH 10/71] Created function to generate account_activation_link for a specific customer --- lib/Customer.php | 17 +++++++++++++++++ lib/ShopifyResource.php | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/lib/Customer.php b/lib/Customer.php index a058624..de5dbe4 100644 --- a/lib/Customer.php +++ b/lib/Customer.php @@ -60,4 +60,21 @@ public function send_invite($customer_invite = array()) return $this->post($dataArray, $url, false); } + + /** + * Create account_activation_link for customer. + * + * @param array $customer_id + * + * @return array + */ + public function account_activation_url($customer_id = 0) + { + if (!(int)$customer_id > 0) { + return false; + } + + $url = $this->generateUrl(array(), $customer_id.'/account_activation_url'); + return $this->post(array(), $url, false); + } } \ No newline at end of file diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 5e4ca00..0e07fe5 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -540,6 +540,11 @@ public function processResponse($responseArray, $dataKey = null) if (isset($responseArray['errors'])) { $message = $this->castString($responseArray['errors']); + //check account already enabled or not + if($message=='account already enabled'){ + return array('account_activation_url'=>false); + } + throw new ApiException($message, CurlRequest::$lastHttpCode); } From da9cc984e968d71978a1c5f611d4cb12b0d025b5 Mon Sep 17 00:00:00 2001 From: andyexeter Date: Mon, 12 Oct 2020 17:41:31 +0100 Subject: [PATCH 11/71] Fix bug introduced by #143 by lowercasing key in getHeader --- lib/CurlResponse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/CurlResponse.php b/lib/CurlResponse.php index 02a9eec..b6922e9 100644 --- a/lib/CurlResponse.php +++ b/lib/CurlResponse.php @@ -53,6 +53,7 @@ public function getHeaders() */ public function getHeader($key) { + $key = strtolower($key); return isset($this->headers[$key]) ? $this->headers[$key] : null; } From f6fb33955b63bdf17431e5cfafe51408b19a1141 Mon Sep 17 00:00:00 2001 From: andyexeter Date: Mon, 12 Oct 2020 17:51:22 +0100 Subject: [PATCH 12/71] Use Retry-After header as value to sleep for before retrying request --- lib/CurlRequest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index 73567e1..25df584 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -166,7 +166,13 @@ protected static function processRequest($ch) throw new ResourceRateLimitException($response->getBody()); } - usleep(500000); + $retryAfter = $response->getHeader('Retry-After'); + + if ($retryAfter === null) { + break; + } + + sleep((float)$retryAfter); } if (curl_errno($ch)) { From 473a3fca21f96074f9aebd38332f1d923587a372 Mon Sep 17 00:00:00 2001 From: Steffen Persch Date: Sun, 25 Oct 2020 18:04:22 +0100 Subject: [PATCH 13/71] Support DiscountCode batch Action --- lib/Batch.php | 33 +++++++++++++++++++++++++++++++++ lib/PriceRule.php | 6 ++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 lib/Batch.php diff --git a/lib/Batch.php b/lib/Batch.php new file mode 100644 index 0000000..49e125b --- /dev/null +++ b/lib/Batch.php @@ -0,0 +1,33 @@ + Batch action + * -------------------------------------------------------------------------- + * + */ + +class Batch extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'batch'; + + protected function getResourcePath() + { + return $this->resourceKey; + } + + protected function wrapData($dataArray, $dataKey = null) + { + return ['discount_codes' => $dataArray]; + } + +} diff --git a/lib/PriceRule.php b/lib/PriceRule.php index ab77a4e..15c77a9 100644 --- a/lib/PriceRule.php +++ b/lib/PriceRule.php @@ -17,6 +17,7 @@ * @property-read ShopifyResource $DiscountCode * * @method ShopifyResource DiscountCode(integer $id = null) + * @method ShopifyResource Batch() * */ class PriceRule extends ShopifyResource @@ -30,6 +31,7 @@ class PriceRule extends ShopifyResource * @inheritDoc */ protected $childResource = array( - 'DiscountCode' + 'DiscountCode', + 'Batch', ); -} \ No newline at end of file +} From 478382a57e5e981f299fd1b4fb6a129d3da56420 Mon Sep 17 00:00:00 2001 From: Howard Chung Date: Tue, 17 Nov 2020 15:13:43 -0500 Subject: [PATCH 14/71] Fix Issue No. 189 --- lib/Refund.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Refund.php b/lib/Refund.php index c91edbe..43460db 100644 --- a/lib/Refund.php +++ b/lib/Refund.php @@ -14,7 +14,7 @@ * -------------------------------------------------------------------------- * Refund -> Custom actions * -------------------------------------------------------------------------- - * @method array calculate() Calculate a Refund. + * @method array calculate(array $config) Calculate a Refund. * */ class Refund extends ShopifyResource From 9f47fb1a77c38acd27c46e45f8b2439bf881a470 Mon Sep 17 00:00:00 2001 From: Tony DeStefano Date: Thu, 19 Nov 2020 11:11:24 -0800 Subject: [PATCH 15/71] calculate() takes an optional array as a parameter. When I pass in the array, I get a warning in my IDE since it's not defined in this class. So I updated the definition. --- lib/Refund.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Refund.php b/lib/Refund.php index c91edbe..2fe6e50 100644 --- a/lib/Refund.php +++ b/lib/Refund.php @@ -14,7 +14,7 @@ * -------------------------------------------------------------------------- * Refund -> Custom actions * -------------------------------------------------------------------------- - * @method array calculate() Calculate a Refund. + * @method array calculate(array $calculation = null) Calculate a Refund. * */ class Refund extends ShopifyResource @@ -30,4 +30,4 @@ class Refund extends ShopifyResource protected $customPostActions = array ( 'calculate', ); -} \ No newline at end of file +} From b182f7a02c770b0747f75bce383fade45c1840d4 Mon Sep 17 00:00:00 2001 From: Lee Hilton Date: Wed, 16 Dec 2020 17:55:10 -0800 Subject: [PATCH 16/71] Resolves #198, Missing TenderTransaction endpoint --- lib/ShopifySDK.php | 3 +++ lib/TenderTransaction.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 lib/TenderTransaction.php diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 9000e84..765a663 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -105,6 +105,7 @@ * @property-read Shop $Shop * @property-read SmartCollection $SmartCollection * @property-read ShopifyPayment $ShopifyPayment + * @property-read TenderTransaction $TenderTransaction * @property-read Theme $Theme * @property-read User $User * @property-read Webhook $Webhook @@ -148,6 +149,7 @@ * @method Shop Shop(integer $id = null) * @method ShopifyPayment ShopifyPayment() * @method SmartCollection SmartCollection(integer $id = null) + * @method TenderTransaction TenderTransaction() * @method Theme Theme(int $id = null) * @method User User(integer $id = null) * @method Webhook Webhook(integer $id = null) @@ -199,6 +201,7 @@ class ShopifySDK 'Shop', 'SmartCollection', 'ShopifyPayment', + 'TenderTransaction', 'Theme', 'User', 'Webhook', diff --git a/lib/TenderTransaction.php b/lib/TenderTransaction.php new file mode 100644 index 0000000..4265c41 --- /dev/null +++ b/lib/TenderTransaction.php @@ -0,0 +1,18 @@ + Date: Tue, 19 Jan 2021 15:48:26 -0700 Subject: [PATCH 17/71] Added the Cart Resource The Cart resource is read only, where you would provide the cart_token to retrieve the cart object. Example: `$shopify->Cart('ea4a55031cbbcd5621918d3a893869b0')->get()` You can retrieve the cart token on your website by using the following javascript snippet `var cart_token = document.cookie.match('(^|; )cart=([^;]*)');` --- README.md | 3 ++- lib/Cart.php | 24 ++++++++++++++++++++++++ lib/ShopifySDK.php | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/Cart.php diff --git a/README.md b/README.md index 80d02fe..07bea6e 100644 --- a/README.md +++ b/README.md @@ -302,7 +302,8 @@ Some resources are available directly, some resources are only available through - Blog -> Article -> [Metafield](https://help.shopify.com/api/reference/metafield) - Blog -> [Event](https://help.shopify.com/api/reference/event/) - Blog -> [Metafield](https://help.shopify.com/api/reference/metafield) -- [CarrierService](https://help.shopify.com/api/reference/carrierservice/) +- [CarrierService](https://help.shopify.com/api/reference/carrierservice/)- +- [Cart](https://shopify.dev/docs/themes/ajax-api/reference/cart) (read only) - [Collect](https://help.shopify.com/api/reference/collect/) - [Comment](https://help.shopify.com/api/reference/comment/) - Comment -> [Event](https://help.shopify.com/api/reference/event/) diff --git a/lib/Cart.php b/lib/Cart.php new file mode 100644 index 0000000..15ad000 --- /dev/null +++ b/lib/Cart.php @@ -0,0 +1,24 @@ + Date: Sun, 21 Mar 2021 21:08:30 +0600 Subject: [PATCH 18/71] Update Default API Version --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 765a663..52f101a 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -221,7 +221,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2020-01'; + public static $defaultApiVersion = '2021-01'; /** * Shop / API configurations From 05eb12398828545071711eb9c746f9d4d7095980 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Sun, 21 Mar 2021 21:18:24 +0600 Subject: [PATCH 19/71] Update CountryTest.php --- tests/CountryTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CountryTest.php b/tests/CountryTest.php index 1a0ddc2..1637cde 100644 --- a/tests/CountryTest.php +++ b/tests/CountryTest.php @@ -22,7 +22,7 @@ class CountryTest extends TestSimpleResource * @inheritDoc */ public $putArray = array( - "tax" => 0.01, + "tax" => 0.15, ); /** @@ -32,4 +32,4 @@ class CountryTest extends TestSimpleResource public function testGet() { $this->assertEquals(1, 1); } -} \ No newline at end of file +} From 90c329d1c434379230a3d35bf0f67e0369788554 Mon Sep 17 00:00:00 2001 From: Liam Cooper Date: Wed, 14 Apr 2021 09:48:12 +0100 Subject: [PATCH 20/71] Throw an exception if the request failed (bad auth code, invalid shop) --- lib/AuthHelper.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index e879964..265989e 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -170,6 +170,10 @@ public static function getAccessToken() $response = HttpRequestJson::post($config['AdminUrl'] . 'oauth/access_token', $data); + if (CurlRequest::$lastHttpCode >= 400) { + throw new SdkException("Invalid request. The shop domain is incorrect or the authorization code has already been used."); + } + return isset($response['access_token']) ? $response['access_token'] : null; } else { throw new SdkException("This request is not initiated from a valid shopify shop!"); From c70bd52324a54c5e7dac157d30deb853a8a07359 Mon Sep 17 00:00:00 2001 From: Liam Cooper Date: Wed, 14 Apr 2021 09:54:47 +0100 Subject: [PATCH 21/71] Slight change in vocabulary --- lib/AuthHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index 265989e..d6461e5 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -171,7 +171,7 @@ public static function getAccessToken() $response = HttpRequestJson::post($config['AdminUrl'] . 'oauth/access_token', $data); if (CurlRequest::$lastHttpCode >= 400) { - throw new SdkException("Invalid request. The shop domain is incorrect or the authorization code has already been used."); + throw new SdkException('The shop is invalid or the authorization code has already been used.'); } return isset($response['access_token']) ? $response['access_token'] : null; From fe7e971bf894d6936c0ba136f651617d64e08bf7 Mon Sep 17 00:00:00 2001 From: Liam Cooper Date: Wed, 14 Apr 2021 10:03:12 +0100 Subject: [PATCH 22/71] Follow string quote convention --- lib/AuthHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index d6461e5..617f542 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -171,7 +171,7 @@ public static function getAccessToken() $response = HttpRequestJson::post($config['AdminUrl'] . 'oauth/access_token', $data); if (CurlRequest::$lastHttpCode >= 400) { - throw new SdkException('The shop is invalid or the authorization code has already been used.'); + throw new SdkException("The shop is invalid or the authorization code has already been used."); } return isset($response['access_token']) ? $response['access_token'] : null; From c2e14416f47309bd94bb583e67d8bacbb5733a67 Mon Sep 17 00:00:00 2001 From: Liam Cooper Date: Tue, 20 Apr 2021 14:02:01 +0100 Subject: [PATCH 23/71] Return location header as array if response is 303 --- lib/ShopifyResource.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 4c2262d..463958f 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -531,10 +531,15 @@ public function processResponse($responseArray, $dataKey = null) $httpOK = 200; //Request Successful, OK. $httpCreated = 201; //Create Successful. $httpDeleted = 204; //Delete Successful + $httpOther = 303; //See other (headers). //should be null if any other library used for http calls $httpCode = CurlRequest::$lastHttpCode; + if ($httpCode == $httpOther && array_key_exists('location', self::$lastHttpResponseHeaders)) { + return ['location' => self::$lastHttpResponseHeaders['location']]; + } + if ($httpCode != null && $httpCode != $httpOK && $httpCode != $httpCreated && $httpCode != $httpDeleted) { throw new Exception\CurlException("Request failed with HTTP Code $httpCode.", $httpCode); } From 96cfdc3d572f79efba92a7b0dccc5e4fdcab08ff Mon Sep 17 00:00:00 2001 From: Denis Waleev Date: Thu, 13 May 2021 15:00:09 +0500 Subject: [PATCH 24/71] Remove query params from current url --- lib/AuthHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/AuthHelper.php b/lib/AuthHelper.php index e879964..d0c5ede 100644 --- a/lib/AuthHelper.php +++ b/lib/AuthHelper.php @@ -28,8 +28,11 @@ public static function getCurrentUrl() else { $protocol = 'http'; } + + $url = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $url = false !== ($qsPos = strpos($url, '?')) ? substr($url, 0, $qsPos) : $url; // remove query params - return "$protocol://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + return $url; } /** From ccbe6e783eb3495b2b9fdc3950451c91247507b8 Mon Sep 17 00:00:00 2001 From: marxolly Date: Fri, 21 May 2021 12:09:38 +1000 Subject: [PATCH 25/71] Adding Fulfillment Order --- lib/FulfillmentOrder.php | 46 ++++++++++++++++++++++++++++++++++++++++ lib/Order.php | 1 + 2 files changed, 47 insertions(+) create mode 100644 lib/FulfillmentOrder.php diff --git a/lib/FulfillmentOrder.php b/lib/FulfillmentOrder.php new file mode 100644 index 0000000..6fb4f0c --- /dev/null +++ b/lib/FulfillmentOrder.php @@ -0,0 +1,46 @@ + + * Created at 5/21/21 11:27 AM UTC+10:00 + * + * @see https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillmentorder Shopify API Reference for Fulfillment Order + */ + +namespace PHPShopify; + + +/** + * -------------------------------------------------------------------------- + * FulfillmentOrder -> Child Resources + * -------------------------------------------------------------------------- + * + * -------------------------------------------------------------------------- + * Fulfillment -> Custom actions + * -------------------------------------------------------------------------- + * @method array cancel() Cancel a fulfillment order + * @method array open() Open a fulfillment order + * @method array close() Close a fulfillment order + * @method array move() Move a fulfilment order to a new location + * @method array reschedule() Reschedule fulfill_at_time of a scheduled fulfillment order + * + */ +class FulfillmentOrder extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'fulfillment_order'; + + + /** + * @inheritDoc + */ + protected $customPostActions = array( + 'close', + 'open', + 'cancel', + 'move', + 'reschedule' + ); +} \ No newline at end of file diff --git a/lib/Order.php b/lib/Order.php index 98efd2a..2a26fab 100644 --- a/lib/Order.php +++ b/lib/Order.php @@ -49,6 +49,7 @@ class Order extends ShopifyResource */ protected $childResource = array ( 'Fulfillment', + 'FulfillmentOrder', 'OrderRisk' => 'Risk', 'Refund', 'Transaction', From 19693b0db0fae40e1c4c29da383e6a7f0f24b8ad Mon Sep 17 00:00:00 2001 From: Yorkii Date: Fri, 27 Aug 2021 13:32:30 +0200 Subject: [PATCH 26/71] Add additional curl configuration --- README.md | 14 ++++++++++++++ lib/CurlRequest.php | 21 +++++++++++++++++++++ lib/ShopifySDK.php | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/README.md b/README.md index 07bea6e..946e03e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,20 @@ composer require phpclassic/php-shopify PHPShopify uses curl extension for handling http calls. So you need to have the curl extension installed and enabled with PHP. >However if you prefer to use any other available package library for handling HTTP calls, you can easily do so by modifying 1 line in each of the `get()`, `post()`, `put()`, `delete()` methods in `PHPShopify\HttpRequestJson` class. +You can pass additional curl configuration to `ShopifySDK` +```php +$config = array( + 'ShopUrl' => 'yourshop.myshopify.com', + 'ApiKey' => '***YOUR-PRIVATE-API-KEY***', + 'Password' => '***YOUR-PRIVATE-API-PASSWORD***', + 'Curl' => array( + CURLOPT_TIMEOUT => 10, + CURLOPT_FOLLOWLOCATION => true + ) +); + +PHPShopify\ShopifySDK::config($config); +``` ## Usage You can use PHPShopify in a pretty simple object oriented way. diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index 25df584..f9d3c93 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -35,6 +35,13 @@ class CurlRequest */ public static $lastHttpResponseHeaders = array(); + /** + * Curl additional configuration + * + * @var array + */ + protected static $config = array(); + /** * Initialize the curl resource * @@ -57,6 +64,10 @@ protected static function init($url, $httpHeaders = array()) curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'PHPClassic/PHPShopify'); + foreach (self::$config as $option => $value) { + curl_setopt($ch, $option, $value); + } + $headers = array(); foreach ($httpHeaders as $key => $value) { $headers[] = "$key: $value"; @@ -139,6 +150,16 @@ public static function delete($url, $httpHeaders = array()) return self::processRequest($ch); } + /** + * Set curl additional configuration + * + * @param array $config + */ + public static function config($config = array()) + { + self::$config = $config; + } + /** * Execute a request, release the resource and return output * diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 0b2c056..02cf6c5 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -351,6 +351,10 @@ public static function config($config) static::$timeAllowedForEachApiCall = $config['AllowedTimePerCall']; } + if (isset($config['Curl']) && is_array($config['Curl'])) { + CurlRequest::config($config['Curl']); + } + return new ShopifySDK; } From 74ec175cf2e8c5c2ace90d7a73cd494af491d220 Mon Sep 17 00:00:00 2001 From: Fabio Date: Tue, 14 Sep 2021 17:30:05 +0200 Subject: [PATCH 27/71] add retry request callback --- lib/HttpRequestGraphQL.php | 6 +-- lib/HttpRequestJson.php | 105 +++++++++++++++++++++++++++++++------ lib/ShopifyResource.php | 19 ------- 3 files changed, 92 insertions(+), 38 deletions(-) diff --git a/lib/HttpRequestGraphQL.php b/lib/HttpRequestGraphQL.php index 8aef907..708f334 100644 --- a/lib/HttpRequestGraphQL.php +++ b/lib/HttpRequestGraphQL.php @@ -68,8 +68,8 @@ public static function post($url, $data, $httpHeaders = array(), $variables = nu { self::prepareRequest($httpHeaders, $data, $variables); - $response = CurlRequest::post($url, self::$postDataGraphQL, self::$httpHeaders); + self::$postDataJSON = self::$postDataGraphQL; - return self::processResponse($response); + return self::processRequest('POST', $url); } -} \ No newline at end of file +} diff --git a/lib/HttpRequestJson.php b/lib/HttpRequestJson.php index ceab78f..c325b74 100644 --- a/lib/HttpRequestJson.php +++ b/lib/HttpRequestJson.php @@ -19,7 +19,6 @@ */ class HttpRequestJson { - /** * HTTP request headers * @@ -32,7 +31,7 @@ class HttpRequestJson * * @var string */ - private static $postDataJSON; + protected static $postDataJSON; /** @@ -68,9 +67,7 @@ public static function get($url, $httpHeaders = array()) { self::prepareRequest($httpHeaders); - $response = CurlRequest::get($url, self::$httpHeaders); - - return self::processResponse($response); + return self::processRequest('GET', $url); } /** @@ -86,9 +83,7 @@ public static function post($url, $dataArray, $httpHeaders = array()) { self::prepareRequest($httpHeaders, $dataArray); - $response = CurlRequest::post($url, self::$postDataJSON, self::$httpHeaders); - - return self::processResponse($response); + return self::processRequest('POST', $url); } /** @@ -104,9 +99,7 @@ public static function put($url, $dataArray, $httpHeaders = array()) { self::prepareRequest($httpHeaders, $dataArray); - $response = CurlRequest::put($url, self::$postDataJSON, self::$httpHeaders); - - return self::processResponse($response); + return self::processRequest('PUT', $url); } /** @@ -121,9 +114,68 @@ public static function delete($url, $httpHeaders = array()) { self::prepareRequest($httpHeaders); - $response = CurlRequest::delete($url, self::$httpHeaders); + return self::processRequest('DELETE', $url); + } + + /** + * Process a curl request and return decoded JSON response + * + * @param string $method Request http method ('GET', 'POST', 'PUT' or 'DELETE') + * @param string $url Request URL + * + * @throws CurlException if response received with unexpected HTTP code. + * + * @return array + */ + public static function processRequest($method, $url) { + $retry = 0; + $raw = null; + + while(true) { + try { + switch($method) { + case 'GET': + $raw = CurlRequest::get($url, self::$httpHeaders); + break; + case 'POST': + $raw = CurlRequest::post($url, self::$postDataJSON, self::$httpHeaders); + break; + case 'PUT': + $raw = CurlRequest::put($url, self::$postDataJSON, self::$httpHeaders); + break; + case 'DELETE': + $raw = CurlRequest::delete($url, self::$httpHeaders); + break; + default: + throw new \Exception("unexpected request method '$method'"); + } + + return self::processResponse($raw); + } catch(\Exception $e) { + if (!self::shouldRetry($raw, $e, $retry++)) { + throw $e; + } + } + } + } + + /** + * Evaluate if send again a request + * + * @param string $response Raw request response + * @param exception $error the request error occured + * @param integer $retry the current number of retry + * + * @return bool + */ + public static function shouldRetry($response, $error, $retry) { + $config = ShopifySDK::$config; + + if (isset($config['RequestRetryCallback'])) { + return $config['RequestRetryCallback']($response, $error, $retry); + } - return self::processResponse($response); + return false; } /** @@ -135,8 +187,29 @@ public static function delete($url, $httpHeaders = array()) */ protected static function processResponse($response) { + $responseArray = json_decode($response, true); - return json_decode($response, true); - } + if ($responseArray === null) { + //Something went wrong, Checking HTTP Codes + $httpOK = 200; //Request Successful, OK. + $httpCreated = 201; //Create Successful. + $httpDeleted = 204; //Delete Successful + $httpOther = 303; //See other (headers). + + $lastHttpResponseHeaders = CurlRequest::$lastHttpResponseHeaders; + + //should be null if any other library used for http calls + $httpCode = CurlRequest::$lastHttpCode; + + if ($httpCode == $httpOther && array_key_exists('location', $lastHttpResponseHeaders)) { + return ['location' => $lastHttpResponseHeaders['location']]; + } -} \ No newline at end of file + if ($httpCode != null && $httpCode != $httpOK && $httpCode != $httpCreated && $httpCode != $httpDeleted) { + throw new Exception\CurlException("Request failed with HTTP Code $httpCode.", $httpCode); + } + } + + return $responseArray; + } +} diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index 463958f..dd3b2cb 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -526,25 +526,6 @@ public function processResponse($responseArray, $dataKey = null) { self::$lastHttpResponseHeaders = CurlRequest::$lastHttpResponseHeaders; - if ($responseArray === null) { - //Something went wrong, Checking HTTP Codes - $httpOK = 200; //Request Successful, OK. - $httpCreated = 201; //Create Successful. - $httpDeleted = 204; //Delete Successful - $httpOther = 303; //See other (headers). - - //should be null if any other library used for http calls - $httpCode = CurlRequest::$lastHttpCode; - - if ($httpCode == $httpOther && array_key_exists('location', self::$lastHttpResponseHeaders)) { - return ['location' => self::$lastHttpResponseHeaders['location']]; - } - - if ($httpCode != null && $httpCode != $httpOK && $httpCode != $httpCreated && $httpCode != $httpDeleted) { - throw new Exception\CurlException("Request failed with HTTP Code $httpCode.", $httpCode); - } - } - $lastResponseHeaders = CurlRequest::$lastHttpResponseHeaders; $this->getLinks($lastResponseHeaders); From ae81bdf9d5a0de668bcc2f1028a9b9e42efa8e91 Mon Sep 17 00:00:00 2001 From: Yorkii Date: Tue, 12 Oct 2021 19:38:35 +0200 Subject: [PATCH 28/71] FulfillmentOrder hold and relase_hold methods --- lib/FulfillmentOrder.php | 7 +++++-- lib/ShopifySDK.php | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/FulfillmentOrder.php b/lib/FulfillmentOrder.php index 6fb4f0c..45de89a 100644 --- a/lib/FulfillmentOrder.php +++ b/lib/FulfillmentOrder.php @@ -23,7 +23,8 @@ * @method array close() Close a fulfillment order * @method array move() Move a fulfilment order to a new location * @method array reschedule() Reschedule fulfill_at_time of a scheduled fulfillment order - * + * @method array hold(array $data) Hold a fulfillment order + * @method array release_hold() Release hold on a fulfillment order */ class FulfillmentOrder extends ShopifyResource { @@ -41,6 +42,8 @@ class FulfillmentOrder extends ShopifyResource 'open', 'cancel', 'move', - 'reschedule' + 'reschedule', + 'hold', + 'release_hold' ); } \ No newline at end of file diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 02cf6c5..1ee6a8a 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -130,6 +130,7 @@ * @method DiscountCode DiscountCode(integer $id = null) * @method Event Event(integer $id = null) * @method FulfillmentService FulfillmentService(integer $id = null) + * @method FulfillmentOrder FulfillmentOrder(integer $id = null) * @method GiftCard GiftCard(integer $id = null) * @method InventoryItem InventoryItem(integer $id = null) * @method InventoryLevel InventoryLevel(integer $id = null) @@ -183,6 +184,7 @@ class ShopifySDK 'DraftOrder', 'Event', 'FulfillmentService', + 'FulfillmentOrder', 'GiftCard', 'InventoryItem', 'InventoryLevel', From 0f421109143d131905390c327b4c8f6d7d7f5b9d Mon Sep 17 00:00:00 2001 From: seka1 <2714877+seka19@users.noreply.github.com> Date: Sun, 17 Oct 2021 02:27:05 +0200 Subject: [PATCH 29/71] feat: AccessScope resource --- lib/AccessScope.php | 36 ++++++++++++++++++++++++++++++++++++ lib/ShopifySDK.php | 3 +++ 2 files changed, 39 insertions(+) create mode 100644 lib/AccessScope.php diff --git a/lib/AccessScope.php b/lib/AccessScope.php new file mode 100644 index 0000000..0ce0c97 --- /dev/null +++ b/lib/AccessScope.php @@ -0,0 +1,36 @@ +getResourcePath() . '.json'; + } +} diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 02cf6c5..dfe364a 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -68,6 +68,7 @@ /** * @property-read AbandonedCheckout $AbandonedCheckout + * @property-read AccessScope $AccessScope * @property-read ApplicationCharge $ApplicationCharge * @property-read Blog $Blog * @property-read CarrierService $CarrierService @@ -113,6 +114,7 @@ * @property-read GraphQL $GraphQL * * @method AbandonedCheckout AbandonedCheckout(integer $id = null) + * @method AccessScope AccessScope() * @method ApplicationCharge ApplicationCharge(integer $id = null) * @method Blog Blog(integer $id = null) * @method CarrierService CarrierService(integer $id = null) @@ -166,6 +168,7 @@ class ShopifySDK */ protected $resources = array( 'AbandonedCheckout', + 'AccessScope', 'ApplicationCharge', 'Blog', 'CarrierService', From 32ec82af1bad7c1cf52363b4711fcc3a820abfbc Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Sat, 18 Dec 2021 17:23:03 +0600 Subject: [PATCH 30/71] [Fixes #251] Update Default API Version to 2021-10 --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index e35455f..c6f9a51 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -229,7 +229,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2021-01'; + public static $defaultApiVersion = '2021-10'; /** * Shop / API configurations From 7233f962dd1f70957739acd3670938b8286094ef Mon Sep 17 00:00:00 2001 From: Anik Ghosh Date: Tue, 21 Dec 2021 16:15:27 +0600 Subject: [PATCH 31/71] $config updated(added AccessToken for running graphql test) --- tests/TestResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/TestResource.php b/tests/TestResource.php index 1c9a268..3fd3b2d 100644 --- a/tests/TestResource.php +++ b/tests/TestResource.php @@ -23,6 +23,7 @@ public static function setUpBeforeClass() 'ShopUrl' => getenv('SHOPIFY_SHOP_URL'), //Your shop URL 'ApiKey' => getenv('SHOPIFY_API_KEY'), //Your Private API Key 'Password' => getenv('SHOPIFY_API_PASSWORD'), //Your Private API Password + 'AccessToken' => getenv('SHOPIFY_API_PASSWORD'), //Your Access Token(Private API Password) ); self::$shopify = ShopifySDK::config($config); From 65f64f19d388de2a304c20582996b4b3fb9f80f1 Mon Sep 17 00:00:00 2001 From: Anik Ghosh Date: Tue, 21 Dec 2021 16:16:42 +0600 Subject: [PATCH 32/71] test case added for GraphQL Query --- tests/GraphQLTest.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/GraphQLTest.php diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php new file mode 100644 index 0000000..fcc12c4 --- /dev/null +++ b/tests/GraphQLTest.php @@ -0,0 +1,39 @@ +GraphQL->post($graphQL); + + $this->assertNotEmpty($return['data']['shop']); + } + + +} From fa79086695985a6bd90638e4271091aeee7afe65 Mon Sep 17 00:00:00 2001 From: Anik Ghosh Date: Tue, 4 Jan 2022 00:09:33 +0600 Subject: [PATCH 33/71] config array updated - for private api --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 946e03e..6ad6895 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ $config = array( 'ShopUrl' => 'yourshop.myshopify.com', 'ApiKey' => '***YOUR-PRIVATE-API-KEY***', 'Password' => '***YOUR-PRIVATE-API-PASSWORD***', + 'AccessToken' => '***YOUR-PRIVATE-API-PASSWORD***', // optional but needed if you want to use graphql ); PHPShopify\ShopifySDK::config($config); From 034a88db2ffa93119a489c07189b77e97a1d1413 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Wed, 23 Feb 2022 12:26:58 +0600 Subject: [PATCH 34/71] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6ad6895..3b634a8 100644 --- a/README.md +++ b/README.md @@ -33,20 +33,20 @@ PHPShopify\ShopifySDK::config($config); You can use PHPShopify in a pretty simple object oriented way. #### Configure ShopifySDK -If you are using your own private API, provide the ApiKey and Password. +If you are using your own private API (except GraphQL), provide the ApiKey and Password. ```php $config = array( 'ShopUrl' => 'yourshop.myshopify.com', 'ApiKey' => '***YOUR-PRIVATE-API-KEY***', 'Password' => '***YOUR-PRIVATE-API-PASSWORD***', - 'AccessToken' => '***YOUR-PRIVATE-API-PASSWORD***', // optional but needed if you want to use graphql ); PHPShopify\ShopifySDK::config($config); ``` -For Third party apps, use the permanent access token. +For Third party apps, use the permanent access token. +> For GraphQL, AccessToken is required. If you are using private API for GraphQL, use your password as AccessToken here. ```php $config = array( From 59e6f8c7e8e7264e5512b13a803f186d0d916a6b Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Wed, 23 Feb 2022 12:32:49 +0600 Subject: [PATCH 35/71] Update API Version --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index c6f9a51..f5383bb 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -229,7 +229,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2021-10'; + public static $defaultApiVersion = '2022-01'; /** * Shop / API configurations From 75cdc9cc6dc3ad27ed3edb689efbf2d49e61d6c8 Mon Sep 17 00:00:00 2001 From: Anik Ghosh Date: Wed, 23 Feb 2022 15:25:00 +0600 Subject: [PATCH 36/71] Migrating from value_type to type --- tests/MetafieldTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/MetafieldTest.php b/tests/MetafieldTest.php index 5038381..b58877a 100644 --- a/tests/MetafieldTest.php +++ b/tests/MetafieldTest.php @@ -17,7 +17,7 @@ class MetafieldTest extends TestSimpleResource "namespace" => "inventory", "key" => "warehouse", "value" => 25, - "value_type" => "integer", + "type" => "integer", ); /** @@ -25,6 +25,6 @@ class MetafieldTest extends TestSimpleResource */ public $putArray = array( "value" => "something new", - "value_type" => "string", + "type" => "string", ); } \ No newline at end of file From 5bc3d3affeb4fcb0c5d7a1233ff58d1b503bad80 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Thu, 14 Jul 2022 21:39:59 +0600 Subject: [PATCH 37/71] Update API Version --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index f5383bb..4c63665 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -229,7 +229,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2022-01'; + public static $defaultApiVersion = '2022-07'; /** * Shop / API configurations From 5e63d9705c2a925fc648b42d493996a49b1fa188 Mon Sep 17 00:00:00 2001 From: Rick Guyer Date: Mon, 18 Jul 2022 15:24:04 -0500 Subject: [PATCH 38/71] Add Metafield property and method to docblock SmartCollection has Metafield support, but static analysis will complain unless it is described in the docblock. --- lib/SmartCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/SmartCollection.php b/lib/SmartCollection.php index d39925c..2d7a347 100644 --- a/lib/SmartCollection.php +++ b/lib/SmartCollection.php @@ -15,8 +15,10 @@ * SmartCollection -> Child Resources * -------------------------------------------------------------------------- * @property-read Event $Event + * @property-read Metafield $Metafield * * @method Event Event(integer $id = null) + * @method Metafield Metafield(integer $id = null) * * -------------------------------------------------------------------------- * SmartCollection -> Custom actions From 9c5a5281aec28efc8a6ef02ed11dbac0a26722ce Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Thu, 29 Sep 2022 12:33:23 +0600 Subject: [PATCH 39/71] Rollback API Version (Breaking changes) --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 4c63665..f5383bb 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -229,7 +229,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2022-07'; + public static $defaultApiVersion = '2022-01'; /** * Shop / API configurations From 81e6cc838043fd45863f916fd5bc08a4f4c6fb63 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Thu, 29 Sep 2022 12:35:29 +0600 Subject: [PATCH 40/71] Update API Version to 2022-07 --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index f5383bb..4c63665 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -229,7 +229,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2022-01'; + public static $defaultApiVersion = '2022-07'; /** * Shop / API configurations From 3b6b0231dedf511722e1f846e0dad4e957c8a272 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Thu, 29 Sep 2022 12:59:43 +0600 Subject: [PATCH 41/71] Custom API Version in $config --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 3b634a8..6a69c9f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,17 @@ $config = array( 'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***', ); +PHPShopify\ShopifySDK::config($config); +``` +You can use specific Shopify API Version by adding in the config array + +```php +$config = array( + 'ShopUrl' => 'yourshop.myshopify.com', + 'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***', + 'ApiVersion' => '2022-07', +); + PHPShopify\ShopifySDK::config($config); ``` ##### How to get the permanent access token for a shop? From 1816de456de3b36c9ecebbbd12ab36581e2bdacf Mon Sep 17 00:00:00 2001 From: Jin Date: Mon, 3 Oct 2022 21:01:43 +0700 Subject: [PATCH 42/71] Metafield as a child resource of Collection & DraftOrder --- lib/Collection.php | 5 ++++- lib/DraftOrder.php | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Collection.php b/lib/Collection.php index 1d2c84a..0c21a40 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -8,8 +8,10 @@ * -------------------------------------------------------------------------- * * @property-read Product $Product + * @property-read Metafield $Metafield * * @method Product Product(integer $id = null) + * @method Metafield Metafield(integer $id = null) * * @see https://shopify.dev/docs/admin-api/rest/reference/products/collection * @@ -31,5 +33,6 @@ class Collection extends ShopifyResource */ protected $childResource = array( 'Product', + 'Metafield', ); -} \ No newline at end of file +} diff --git a/lib/DraftOrder.php b/lib/DraftOrder.php index 902cee5..9e3be91 100644 --- a/lib/DraftOrder.php +++ b/lib/DraftOrder.php @@ -12,6 +12,14 @@ /** + * -------------------------------------------------------------------------- + * DraftOrder -> Child Resources + * -------------------------------------------------------------------------- + * + * @property-read Metafield $Metafield + * + * @method Metafield Metafield(integer $id = null) + * * -------------------------------------------------------------------------- * DraftOrder -> Custom actions * -------------------------------------------------------------------------- @@ -39,4 +47,11 @@ class DraftOrder extends ShopifyResource protected $customPutActions = array( 'complete', ); -} \ No newline at end of file + + /** + * @inheritDoc + */ + protected $childResource = array( + 'Metafield', + ); +} From 8b2c2a09e6bed833f7b73eed2e4b6107fcbd0f4a Mon Sep 17 00:00:00 2001 From: Jin Date: Thu, 6 Oct 2022 22:50:59 +0700 Subject: [PATCH 43/71] added fulfillment update_tracking action --- lib/Fulfillment.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Fulfillment.php b/lib/Fulfillment.php index 18138d2..ec9cd75 100644 --- a/lib/Fulfillment.php +++ b/lib/Fulfillment.php @@ -24,6 +24,7 @@ * @method array complete() Complete a fulfillment * @method array open() Open a pending fulfillment * @method array cancel() Cancel a fulfillment + * @method array update_tracking(array $data) Updates the tracking information for a fulfillment. * */ class Fulfillment extends ShopifyResource @@ -47,5 +48,6 @@ class Fulfillment extends ShopifyResource 'complete', 'open', 'cancel', + 'update_tracking', ); -} \ No newline at end of file +} From 4d49e3bdfaaea01c5234285391bb0e0c23f3ad91 Mon Sep 17 00:00:00 2001 From: Jin Date: Thu, 6 Oct 2022 23:02:13 +0700 Subject: [PATCH 44/71] make fulfillment api as parent resource --- lib/ShopifySDK.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 4c63665..7dffb55 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -85,6 +85,7 @@ * @property-read DiscountCode $DiscountCode * @property-read DraftOrder $DraftOrder * @property-read Event $Event + * @property-read Fulfillment $Fulfillment * @property-read FulfillmentService $FulfillmentService * @property-read GiftCard $GiftCard * @property-read InventoryItem $InventoryItem @@ -131,6 +132,7 @@ * @method DraftOrder DraftOrder(integer $id = null) * @method DiscountCode DiscountCode(integer $id = null) * @method Event Event(integer $id = null) + * @method Fulfillment Fulfillment(integer $id = null) * @method FulfillmentService FulfillmentService(integer $id = null) * @method FulfillmentOrder FulfillmentOrder(integer $id = null) * @method GiftCard GiftCard(integer $id = null) @@ -186,6 +188,7 @@ class ShopifySDK 'DiscountCode', 'DraftOrder', 'Event', + 'Fulfillment', 'FulfillmentService', 'FulfillmentOrder', 'GiftCard', From 44dadde3133ee9d89f1f7ffedaf2eb9b3ed3c7e8 Mon Sep 17 00:00:00 2001 From: Rex Bengil Date: Sat, 22 Oct 2022 07:19:34 +0800 Subject: [PATCH 45/71] #266 - PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated --- lib/CurlRequest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index f9d3c93..648296d 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -181,12 +181,15 @@ protected static function processRequest($ch) break; } - $limitHeader = explode('/', $response->getHeader('X-Shopify-Shop-Api-Call-Limit'), 2); + $apiCallLimit = $response->getHeader('X-Shopify-Shop-Api-Call-Limit'); - if (isset($limitHeader[1]) && $limitHeader[0] < $limitHeader[1]) { - throw new ResourceRateLimitException($response->getBody()); + if (!empty($apiCallLimit)) { + $limitHeader = explode('/', $apiCallLimit, 2); + if (isset($limitHeader[1]) && $limitHeader[0] < $limitHeader[1]) { + throw new ResourceRateLimitException($response->getBody()); + } } - + $retryAfter = $response->getHeader('Retry-After'); if ($retryAfter === null) { From aa35f44b470c8176bebb17accfcf1adedec2ec46 Mon Sep 17 00:00:00 2001 From: Jeroen de Lau Date: Thu, 17 Nov 2022 16:33:53 +0100 Subject: [PATCH 46/71] add support for Order()->FulfillmentOrder and FulfillmentRequests --- lib/FulfillmentOrder.php | 7 ++++++ lib/FulfillmentRequest.php | 47 ++++++++++++++++++++++++++++++++++++++ lib/Order.php | 1 + 3 files changed, 55 insertions(+) create mode 100644 lib/FulfillmentRequest.php diff --git a/lib/FulfillmentOrder.php b/lib/FulfillmentOrder.php index 45de89a..d2abc04 100644 --- a/lib/FulfillmentOrder.php +++ b/lib/FulfillmentOrder.php @@ -14,6 +14,7 @@ * -------------------------------------------------------------------------- * FulfillmentOrder -> Child Resources * -------------------------------------------------------------------------- + * @property-read FulfillmentRequest $FulfillmentRequest * * -------------------------------------------------------------------------- * Fulfillment -> Custom actions @@ -33,6 +34,12 @@ class FulfillmentOrder extends ShopifyResource */ protected $resourceKey = 'fulfillment_order'; + /** + * @inheritDoc + */ + protected $childResource = array ( + 'FulfillmentRequest' + ); /** * @inheritDoc diff --git a/lib/FulfillmentRequest.php b/lib/FulfillmentRequest.php new file mode 100644 index 0000000..e887c73 --- /dev/null +++ b/lib/FulfillmentRequest.php @@ -0,0 +1,47 @@ + + * Created at 8/19/16 5:28 PM UTC+06:00 + * + * @see https://help.shopify.com/api/reference/fulfillmentservice Shopify API Reference for FulfillmentService + */ + +namespace PHPShopify; + +/** + * -------------------------------------------------------------------------- + * FulfillmentRequest -> Child Resources + * -------------------------------------------------------------------------- + * + * -------------------------------------------------------------------------- + * FulfillmentRequest -> Custom actions + * -------------------------------------------------------------------------- + * @method array accept() Accept a fulfilment order + * @method array reject() Rejects a fulfillment order + */ +class FulfillmentRequest extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'fulfillment_request'; + + /** + * @inheritDoc + */ + public $countEnabled = false; + + /** + * @inheritDoc + */ + protected $customPostActions = array( + 'accept', + 'reject' + ); + + protected function pluralizeKey() + { + return $this->resourceKey; + } +} \ No newline at end of file diff --git a/lib/Order.php b/lib/Order.php index 2a26fab..5ae5f5e 100644 --- a/lib/Order.php +++ b/lib/Order.php @@ -15,6 +15,7 @@ * -------------------------------------------------------------------------- * Order -> Child Resources * -------------------------------------------------------------------------- + * @property-read FulfillmentOrder $FulfillmentOrder * @property-read Fulfillment $Fulfillment * @property-read OrderRisk $Risk * @property-read Refund $Refund From 958c35c0f67aab96b379e5727b8f7acded5c7a3d Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Tue, 13 Dec 2022 12:36:23 -0700 Subject: [PATCH 47/71] Removed the CurlCallback feature from the the API Deprecations Query --- lib/ApiDeprecations.php | 39 +++++++++++++++++++++++++++++++++++++++ lib/ShopifySDK.php | 3 +++ 2 files changed, 42 insertions(+) create mode 100644 lib/ApiDeprecations.php diff --git a/lib/ApiDeprecations.php b/lib/ApiDeprecations.php new file mode 100644 index 0000000..8d1b698 --- /dev/null +++ b/lib/ApiDeprecations.php @@ -0,0 +1,39 @@ + + * @author Steve Barbera + * Created at 8/18/16 3:39 PM UTC+06:00 + * + * @see https://shopify.dev/api/admin-rest/2022-04/resources/deprecated-api-calls#get-deprecated-api-calls Shopify API Reference for API Deprecations + */ + +namespace PHPShopify; + + +class ApiDeprecations extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'deprecated_api_calls'; + + /** + * @inheritDoc + */ + public $readOnly = true; + + /** + * @inheritDoc + */ + public $countEnabled = false; + + /** + * @inheritDoc + */ + public function pluralizeKey() + { + //Only api deprecations, so no pluralize + return 'deprecated_api_calls'; + } +} diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 7dffb55..429f1ea 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -69,6 +69,7 @@ /** * @property-read AbandonedCheckout $AbandonedCheckout * @property-read AccessScope $AccessScope + * @property-read ApiDeprecations $ApiDeprecations * @property-read ApplicationCharge $ApplicationCharge * @property-read Blog $Blog * @property-read CarrierService $CarrierService @@ -116,6 +117,7 @@ * * @method AbandonedCheckout AbandonedCheckout(integer $id = null) * @method AccessScope AccessScope() + * @method ApiDeprecations ApiDeprecations() * @method ApplicationCharge ApplicationCharge(integer $id = null) * @method Blog Blog(integer $id = null) * @method CarrierService CarrierService(integer $id = null) @@ -172,6 +174,7 @@ class ShopifySDK protected $resources = array( 'AbandonedCheckout', 'AccessScope', + 'ApiDeprecations', 'ApplicationCharge', 'Blog', 'CarrierService', From 676aaaf7b88a7125711f793a2a475df27d78ebf5 Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Tue, 13 Dec 2022 12:45:34 -0700 Subject: [PATCH 48/71] Added API Deprecations documentation to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6a69c9f..96a9486 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,7 @@ Some resources are available directly, some resources are only available through > Use the resources only by listed resource map. Trying to get a resource directly which is only available through parent resource may end up with errors. - [AbandonedCheckout](https://help.shopify.com/api/reference/abandoned_checkouts) +- [ApiDeprecations](https://shopify.dev/api/admin-rest/2022-04/resources/deprecated-api-calls#get-deprecated-api-calls) - [ApplicationCharge](https://help.shopify.com/api/reference/applicationcharge) - [Blog](https://help.shopify.com/api/reference/blog/) - Blog -> [Article](https://help.shopify.com/api/reference/article/) From b2c298dc41c6a7754f1d61c89fdb49af98e9aba8 Mon Sep 17 00:00:00 2001 From: Jeroen de Lau Date: Wed, 11 Jan 2023 11:03:56 +0100 Subject: [PATCH 49/71] add Fulfillment as child resource of FulfillmentOrder --- lib/FulfillmentOrder.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/FulfillmentOrder.php b/lib/FulfillmentOrder.php index d2abc04..8d20011 100644 --- a/lib/FulfillmentOrder.php +++ b/lib/FulfillmentOrder.php @@ -1,8 +1,5 @@ - * Created at 5/21/21 11:27 AM UTC+10:00 * * @see https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillmentorder Shopify API Reference for Fulfillment Order */ @@ -15,6 +12,7 @@ * FulfillmentOrder -> Child Resources * -------------------------------------------------------------------------- * @property-read FulfillmentRequest $FulfillmentRequest + * @property-read Fulfillment $Fulfillment * * -------------------------------------------------------------------------- * Fulfillment -> Custom actions @@ -38,7 +36,8 @@ class FulfillmentOrder extends ShopifyResource * @inheritDoc */ protected $childResource = array ( - 'FulfillmentRequest' + 'FulfillmentRequest', + 'Fulfillment' ); /** From 69b30571d9713bee57e8e4f35237821ed1d126a8 Mon Sep 17 00:00:00 2001 From: Jeroen de Lau Date: Wed, 11 Jan 2023 11:08:29 +0100 Subject: [PATCH 50/71] updated README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a69c9f..1766417 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,10 @@ Some resources are available directly, some resources are only available through - [DiscountCode](https://help.shopify.com/en/api/reference/discounts/discountcode) - [Event](https://help.shopify.com/api/reference/event/) - [FulfillmentService](https://help.shopify.com/api/reference/fulfillmentservice) +- [Fulfillment](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillment) +- [FulfillmentOrder](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillmentorder) +- FulfillmentOrder -> [FulfillmentRequest](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillmentrequest) +- FulfillmentOrder -> [Fulfillment](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillment) - [GiftCard](https://help.shopify.com/api/reference/gift_card) _(Shopify Plus Only)_ - [InventoryItem](https://help.shopify.com/api/reference/inventoryitem) - [InventoryLevel](https://help.shopify.com/api/reference/inventorylevel) @@ -358,8 +362,7 @@ Some resources are available directly, some resources are only available through - [Metafield](https://help.shopify.com/api/reference/metafield) - [Multipass](https://help.shopify.com/api/reference/multipass) _(Shopify Plus Only, API not available yet)_ - [Order](https://help.shopify.com/api/reference/order) -- Order -> [Fulfillment](https://help.shopify.com/api/reference/fulfillment) -- Order -> Fulfillment -> [Event](https://help.shopify.com/api/reference/fulfillmentevent) +- Order -> [FulfillmentOrder](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillmentorder) - Order -> [Risk](https://help.shopify.com/api/reference/order_risks) - Order -> [Refund](https://help.shopify.com/api/reference/refund) - Order -> [Transaction](https://help.shopify.com/api/reference/transaction) From 6df94536df2d08e89132af4cd0153716c3942607 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Mon, 13 Feb 2023 09:35:25 +0600 Subject: [PATCH 51/71] Update Default API Version Number --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 429f1ea..67aa0e5 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -235,7 +235,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2022-07'; + public static $defaultApiVersion = '2023-01'; /** * Shop / API configurations From 1d05bc9c662b01e804b12ab6049cf707a43d4285 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Mon, 13 Feb 2023 09:51:33 +0600 Subject: [PATCH 52/71] Update README.md --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 308b408..628f035 100644 --- a/README.md +++ b/README.md @@ -515,6 +515,26 @@ The custom methods are specific to some resources which may not be available for - User -> - [current()](https://help.shopify.com/api/reference/user#current) Get the current logged-in user + +### FulfillmentRequest Resource - including actions +- Mapped FulfillmentOrder->FulfillmentRequest +- Mapped Order(id)->FulfillmentOrder + +``` +// Requesting the FulfilmentOrder for a given order +$fo = $client->Order("1234567890")->FulfillmentOrder()->get(); + +// Creating a FulfilmentRequest +// Follow instructions to get partial fulfilments +$fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->post([]); + +// Accepting \ Rejecting a FulfilmentRequest +$fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->accept(); +$fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->reject(); + +// Communicating fulfillment +$client->Fulfillment->post($body) +``` ### Shopify API features headers To send `X-Shopify-Api-Features` headers while using the SDK, you can use the following: From 7d8f4641795a32dde67f3623aa4950a126eddd01 Mon Sep 17 00:00:00 2001 From: Roberto Romolini Date: Wed, 15 Mar 2023 14:13:05 +0100 Subject: [PATCH 53/71] Add total time spent in sleep during multiple requests --- lib/CurlRequest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/CurlRequest.php b/lib/CurlRequest.php index 648296d..b4517e4 100644 --- a/lib/CurlRequest.php +++ b/lib/CurlRequest.php @@ -35,6 +35,13 @@ class CurlRequest */ public static $lastHttpResponseHeaders = array(); + /** + * Total time spent in sleep during multiple requests (in seconds) + * + * @var int + */ + public static $totalRetrySleepTime = 0; + /** * Curl additional configuration * @@ -196,6 +203,7 @@ protected static function processRequest($ch) break; } + self::$totalRetrySleepTime += (float)$retryAfter; sleep((float)$retryAfter); } @@ -210,5 +218,4 @@ protected static function processRequest($ch) return $response->getBody(); } - } From b25533dd4efd88b945afdd90c2408477503ba339 Mon Sep 17 00:00:00 2001 From: Spot Allen Date: Mon, 29 May 2023 02:24:23 +0000 Subject: [PATCH 54/71] Add support the AssignedFulfillmentOrder resource --- README.md | 6 +++++- lib/AssignedFulfillmentOrder.php | 16 ++++++++++++++++ lib/ShopifySDK.php | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/AssignedFulfillmentOrder.php diff --git a/README.md b/README.md index 628f035..4f5dc34 100644 --- a/README.md +++ b/README.md @@ -323,6 +323,7 @@ Some resources are available directly, some resources are only available through - [AbandonedCheckout](https://help.shopify.com/api/reference/abandoned_checkouts) - [ApiDeprecations](https://shopify.dev/api/admin-rest/2022-04/resources/deprecated-api-calls#get-deprecated-api-calls) - [ApplicationCharge](https://help.shopify.com/api/reference/applicationcharge) +- [AssignedFulfillmentOrder](https://shopify.dev/docs/api/admin-rest/2023-04/resources/assignedfulfillmentorder#get-assigned-fulfillment-orders) - [Blog](https://help.shopify.com/api/reference/blog/) - Blog -> [Article](https://help.shopify.com/api/reference/article/) - Blog -> Article -> [Event](https://help.shopify.com/api/reference/event/) @@ -520,10 +521,13 @@ The custom methods are specific to some resources which may not be available for - Mapped FulfillmentOrder->FulfillmentRequest - Mapped Order(id)->FulfillmentOrder -``` +```php // Requesting the FulfilmentOrder for a given order $fo = $client->Order("1234567890")->FulfillmentOrder()->get(); +// Requesting assigned fulfillment orders (with status fulfillment_requested) +$shopify->AssignedFulfillmentOrder()->get(["assignment_status" => "fulfillment_requested"]); + // Creating a FulfilmentRequest // Follow instructions to get partial fulfilments $fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->post([]); diff --git a/lib/AssignedFulfillmentOrder.php b/lib/AssignedFulfillmentOrder.php new file mode 100644 index 0000000..108983d --- /dev/null +++ b/lib/AssignedFulfillmentOrder.php @@ -0,0 +1,16 @@ + Date: Mon, 29 May 2023 02:46:45 +0000 Subject: [PATCH 55/71] Fix: Typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f5dc34..e823a6c 100644 --- a/README.md +++ b/README.md @@ -323,7 +323,7 @@ Some resources are available directly, some resources are only available through - [AbandonedCheckout](https://help.shopify.com/api/reference/abandoned_checkouts) - [ApiDeprecations](https://shopify.dev/api/admin-rest/2022-04/resources/deprecated-api-calls#get-deprecated-api-calls) - [ApplicationCharge](https://help.shopify.com/api/reference/applicationcharge) -- [AssignedFulfillmentOrder](https://shopify.dev/docs/api/admin-rest/2023-04/resources/assignedfulfillmentorder#get-assigned-fulfillment-orders) +- [AssignedFulfillmentOrder](https://shopify.dev/docs/api/admin-rest/2023-04/resources/assignedfulfillmentorder) - [Blog](https://help.shopify.com/api/reference/blog/) - Blog -> [Article](https://help.shopify.com/api/reference/article/) - Blog -> Article -> [Event](https://help.shopify.com/api/reference/event/) From b33ceb1ae55c795da15840050b1f688cbadec136 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 1 Jun 2023 14:55:11 +0200 Subject: [PATCH 56/71] Add "FulfillmentOrder" and alfabetize properties --- lib/ShopifySDK.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index f10caea..f9639cb 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -68,10 +68,10 @@ /** * @property-read AbandonedCheckout $AbandonedCheckout - * @property-read AssignedFulfillmentOrder $AssignedFulfillmentOrder * @property-read AccessScope $AccessScope * @property-read ApiDeprecations $ApiDeprecations * @property-read ApplicationCharge $ApplicationCharge + * @property-read AssignedFulfillmentOrder $AssignedFulfillmentOrder * @property-read Blog $Blog * @property-read CarrierService $CarrierService * @property-read Cart $Cart @@ -88,6 +88,7 @@ * @property-read DraftOrder $DraftOrder * @property-read Event $Event * @property-read Fulfillment $Fulfillment + * @property-read FulfillmentOrder $FulfillmentOrder * @property-read FulfillmentService $FulfillmentService * @property-read GiftCard $GiftCard * @property-read InventoryItem $InventoryItem @@ -98,18 +99,18 @@ * @property-read Order $Order * @property-read Page $Page * @property-read Policy $Policy + * @property-read PriceRule $PriceRule * @property-read Product $Product * @property-read ProductListing $ProductListing * @property-read ProductVariant $ProductVariant - * @property-read PriceRule $PriceRule * @property-read RecurringApplicationCharge $RecurringApplicationCharge * @property-read Redirect $Redirect * @property-read Report $Report * @property-read ScriptTag $ScriptTag * @property-read ShippingZone $ShippingZone * @property-read Shop $Shop - * @property-read SmartCollection $SmartCollection * @property-read ShopifyPayment $ShopifyPayment + * @property-read SmartCollection $SmartCollection * @property-read TenderTransaction $TenderTransaction * @property-read Theme $Theme * @property-read User $User From e12905e60cdaf2f1522ed20a013cb07a5de82daf Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Tue, 27 Jun 2023 13:21:17 -0600 Subject: [PATCH 57/71] Added the Gift Card Adjustment Resource --- README.md | 1 + lib/GiftCard.php | 9 ++++++++- lib/GiftCardAdjustment.php | 20 ++++++++++++++++++++ lib/ShopifySDK.php | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 lib/GiftCardAdjustment.php diff --git a/README.md b/README.md index e823a6c..bc11ba7 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,7 @@ Some resources are available directly, some resources are only available through - FulfillmentOrder -> [FulfillmentRequest](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillmentrequest) - FulfillmentOrder -> [Fulfillment](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillment) - [GiftCard](https://help.shopify.com/api/reference/gift_card) _(Shopify Plus Only)_ +- [GiftCardAdjustment](https://shopify.dev/docs/api/admin-rest/2023-01/resources/gift-card-adjustment) _(Shopify Plus Only)_ - [InventoryItem](https://help.shopify.com/api/reference/inventoryitem) - [InventoryLevel](https://help.shopify.com/api/reference/inventorylevel) - [Location](https://help.shopify.com/api/reference/location/) _(read only)_ diff --git a/lib/GiftCard.php b/lib/GiftCard.php index 2391064..07d5428 100644 --- a/lib/GiftCard.php +++ b/lib/GiftCard.php @@ -45,4 +45,11 @@ public function disable() return $this->post($dataArray, $url); } -} \ No newline at end of file + + /** + * @inheritDoc + */ + protected $childResource = array( + 'GiftCardAdjustment' => 'Adjustment' + ); +} diff --git a/lib/GiftCardAdjustment.php b/lib/GiftCardAdjustment.php new file mode 100644 index 0000000..066642d --- /dev/null +++ b/lib/GiftCardAdjustment.php @@ -0,0 +1,20 @@ + + * Created at: 8/21/16 8:39 AM UTC+06:00 + * + * @see https://shopify.dev/docs/api/admin-rest/2023-01/resources/gift-card-adjustment Shopify API Reference for Gift Card Adjustment + * @note - requires gift_card_adjustments access scope enabled by Shopify Support + */ + +namespace PHPShopify; + + +class GiftCardAdjustment extends ShopifyResource +{ + /** + * @inheritDoc + */ + protected $resourceKey = 'adjustment'; +} diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index f10caea..36af40b 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -90,6 +90,7 @@ * @property-read Fulfillment $Fulfillment * @property-read FulfillmentService $FulfillmentService * @property-read GiftCard $GiftCard + * @property-read GiftCardAdjustment $GiftCardAdjustment * @property-read InventoryItem $InventoryItem * @property-read InventoryLevel $InventoryLevel * @property-read Location $Location @@ -140,6 +141,7 @@ * @method FulfillmentService FulfillmentService(integer $id = null) * @method FulfillmentOrder FulfillmentOrder(integer $id = null) * @method GiftCard GiftCard(integer $id = null) + * @method GiftCardAdjustment GiftCardAdjustment(integer $id = null) * @method InventoryItem InventoryItem(integer $id = null) * @method InventoryLevel InventoryLevel(integer $id = null) * @method Location Location(integer $id = null) @@ -261,6 +263,7 @@ class ShopifySDK 'Dispute' => 'ShopifyPayment', 'Fulfillment' => 'Order', 'FulfillmentEvent' => 'Fulfillment', + 'GiftCardAdjustment'=> 'GiftCard', 'OrderRisk' => 'Order', 'Payouts' => 'ShopifyPayment', 'ProductImage' => 'Product', From 7a52f6af5f381785b028f774131466531539d4b1 Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Tue, 27 Jun 2023 13:37:48 -0600 Subject: [PATCH 58/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc11ba7..8459ff7 100644 --- a/README.md +++ b/README.md @@ -357,7 +357,7 @@ Some resources are available directly, some resources are only available through - FulfillmentOrder -> [FulfillmentRequest](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillmentrequest) - FulfillmentOrder -> [Fulfillment](https://shopify.dev/api/admin-rest/2023-01/resources/fulfillment) - [GiftCard](https://help.shopify.com/api/reference/gift_card) _(Shopify Plus Only)_ -- [GiftCardAdjustment](https://shopify.dev/docs/api/admin-rest/2023-01/resources/gift-card-adjustment) _(Shopify Plus Only)_ +- GiftCard -> [Adjustment](https://shopify.dev/docs/api/admin-rest/2023-01/resources/gift-card-adjustment) _(Shopify Plus Only)_ - [InventoryItem](https://help.shopify.com/api/reference/inventoryitem) - [InventoryLevel](https://help.shopify.com/api/reference/inventorylevel) - [Location](https://help.shopify.com/api/reference/location/) _(read only)_ From 589ebb808bd363a54dd6016f7e76edf62231940a Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Tue, 27 Jun 2023 13:49:43 -0600 Subject: [PATCH 59/71] added usage to the GiftCardAdjustment class --- lib/GiftCardAdjustment.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/GiftCardAdjustment.php b/lib/GiftCardAdjustment.php index 066642d..933f54b 100644 --- a/lib/GiftCardAdjustment.php +++ b/lib/GiftCardAdjustment.php @@ -6,6 +6,26 @@ * * @see https://shopify.dev/docs/api/admin-rest/2023-01/resources/gift-card-adjustment Shopify API Reference for Gift Card Adjustment * @note - requires gift_card_adjustments access scope enabled by Shopify Support + * + * @usage: + * + $shopify = \PHPShopify\ShopifySDK::config($config); + + $gift_card_id = 88888888888; + + $gift_card_adjustment_id = 999999999999; + + // Get all gift card adjustments + $shopify->GiftCard($gift_card_id)->Adjustment()->get(); + + // Get a single gift card adjustment + $shopify->GiftCard($gift_card_id)->Adjustment($gift_card_adjustment_id)->get(); + + // Create a gift card adjustment + $shopify->GiftCard($gift_card_id)->Adjustment()->post([ + 'amount' => 5, + 'note' => 'Add $5 to gift card' + ]); */ namespace PHPShopify; From ac59e488690beebf948223756486cffa67972ace Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Wed, 28 Jun 2023 13:22:42 +0600 Subject: [PATCH 60/71] Update API Version Number --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 36af40b..dc0433f 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -240,7 +240,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2023-01'; + public static $defaultApiVersion = '2023-04'; /** * Shop / API configurations From 75e8bd2e92850c716bad506d8deea96b80b79c7e Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Wed, 30 Aug 2023 10:10:58 -0600 Subject: [PATCH 61/71] Added the Metafield to the Location Resource --- lib/Location.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Location.php b/lib/Location.php index f4a589a..d99f0ce 100644 --- a/lib/Location.php +++ b/lib/Location.php @@ -9,6 +9,14 @@ namespace PHPShopify; +/** + * -------------------------------------------------------------------------- + * Inventory -> Child Resources + * -------------------------------------------------------------------------- + * @property-read Metafield $Metafield + * + * @method Metafield Metafield(integer $id = null) + */ class Location extends ShopifyResource { @@ -32,5 +40,6 @@ class Location extends ShopifyResource */ protected $childResource = array( 'InventoryLevel', + 'Metafield', ); -} \ No newline at end of file +} From 13dfcb4bf4d4dd64f3c96ba2f12417c46feb8583 Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Thu, 31 Aug 2023 07:31:18 -0600 Subject: [PATCH 62/71] Updated the readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8459ff7..766654b 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,7 @@ Some resources are available directly, some resources are only available through - [InventoryLevel](https://help.shopify.com/api/reference/inventorylevel) - [Location](https://help.shopify.com/api/reference/location/) _(read only)_ - Location -> [InventoryLevel](https://help.shopify.com/api/reference/inventorylevel) +- Location -> [Metafield](https://help.shopify.com/api/reference/metafield) - [Metafield](https://help.shopify.com/api/reference/metafield) - [Multipass](https://help.shopify.com/api/reference/multipass) _(Shopify Plus Only, API not available yet)_ - [Order](https://help.shopify.com/api/reference/order) From b9a35f83356937b6971cd4bc156f8ad8e3624778 Mon Sep 17 00:00:00 2001 From: Steve Barbera Date: Tue, 12 Sep 2023 15:59:08 -0600 Subject: [PATCH 63/71] rename in comments --- lib/Location.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Location.php b/lib/Location.php index d99f0ce..c5c1247 100644 --- a/lib/Location.php +++ b/lib/Location.php @@ -11,7 +11,7 @@ /** * -------------------------------------------------------------------------- - * Inventory -> Child Resources + * Location -> Child Resources * -------------------------------------------------------------------------- * @property-read Metafield $Metafield * From 284d7c8627faf8d6c579259c820215314b1cc4e7 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Sat, 16 Sep 2023 11:42:27 +0600 Subject: [PATCH 64/71] Update Shopify API Version --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 0974595..2a5d4af 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -241,7 +241,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2023-04'; + public static $defaultApiVersion = '2023-07'; /** * Shop / API configurations From 82c040698c15a5c106030b30e1338fb3e46d1606 Mon Sep 17 00:00:00 2001 From: Anik Ghosh Date: Mon, 25 Sep 2023 18:56:40 +0600 Subject: [PATCH 65/71] feat: add getEmbeddedAppUrl method --- lib/ShopifySDK.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 2a5d4af..db7da2f 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -421,6 +421,28 @@ public static function getApiUrl() { return self::$config['ApiUrl']; } + /** + * Returns the appropriate URL for the host that should load the embedded app. + * + * @param string $host The host value received from Shopify + * + * @return string + */ + public static function getEmbeddedAppUrl($host) + { + if (empty($host)) { + throw new SdkException("Host value cannot be empty"); + } + + $decodedHost = base64_decode($host, true); + if (!$decodedHost) { + throw new SdkException("Host was not a valid base64 string"); + } + + $apiKey = self::$config['ApiKey']; + return "https://$decodedHost/apps/$apiKey"; + } + /** * Maintain maximum 2 calls per second to the API * From 010a08555f7cb98ea256bf9da4d0f9bcc135dd07 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Tue, 2 Jul 2024 20:27:05 +0600 Subject: [PATCH 66/71] Update Default Api Version --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index db7da2f..8fd83b1 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -241,7 +241,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2023-07'; + public static $defaultApiVersion = '2024-07'; /** * Shop / API configurations From 628b137a33a2c416c299699e48a970b2161f6074 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Sat, 19 Oct 2024 16:41:38 +0800 Subject: [PATCH 67/71] Update Api Version Number Completes #334 --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 8fd83b1..4d2cdd6 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -241,7 +241,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2024-07'; + public static $defaultApiVersion = '2024-10'; /** * Shop / API configurations From 0b858ac179b1a20cd76482af3195872b90433d0a Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Wed, 12 Feb 2025 02:09:22 +0800 Subject: [PATCH 68/71] API Version Update 2025-01 --- lib/ShopifySDK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 4d2cdd6..de31d00 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -241,7 +241,7 @@ class ShopifySDK /** * @var string Default Shopify API version */ - public static $defaultApiVersion = '2024-10'; + public static $defaultApiVersion = '2025-01'; /** * Shop / API configurations From 0a2e1a88d45a3f559b55e7f00d455193a293fb02 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Wed, 12 Feb 2025 12:31:59 +0800 Subject: [PATCH 69/71] Content type application/graphql is deprecated Details : https://shopify.dev/changelog/content-type-application-graphql-is-deprecated https://shopify.dev/docs/api/release-notes/2025-01 --- lib/HttpRequestGraphQL.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/HttpRequestGraphQL.php b/lib/HttpRequestGraphQL.php index 708f334..10d902f 100644 --- a/lib/HttpRequestGraphQL.php +++ b/lib/HttpRequestGraphQL.php @@ -45,12 +45,10 @@ protected static function prepareRequest($httpHeaders = array(), $data = array() } self::$httpHeaders = $httpHeaders; + self::$httpHeaders['Content-type'] = 'application/json'; if (is_array($variables)) { self::$postDataGraphQL = json_encode(['query' => $data, 'variables' => $variables]); - self::$httpHeaders['Content-type'] = 'application/json'; - } else { - self::$httpHeaders['Content-type'] = 'application/graphql'; } } From 49deba8f3bda86b93ff7c882943d941b70155cf8 Mon Sep 17 00:00:00 2001 From: VISHAL Date: Tue, 18 Feb 2025 18:47:08 +0530 Subject: [PATCH 70/71] fix: 400 bad request api issue with graphql when variables are not passed --- lib/HttpRequestGraphQL.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/HttpRequestGraphQL.php b/lib/HttpRequestGraphQL.php index 10d902f..fe6106c 100644 --- a/lib/HttpRequestGraphQL.php +++ b/lib/HttpRequestGraphQL.php @@ -49,6 +49,8 @@ protected static function prepareRequest($httpHeaders = array(), $data = array() if (is_array($variables)) { self::$postDataGraphQL = json_encode(['query' => $data, 'variables' => $variables]); + } else { + self::$postDataGraphQL = json_encode(['query' => $data]); } } From c6eb4e28a0bd78e1d7f431f6269061f1653a3b80 Mon Sep 17 00:00:00 2001 From: Tareq Mahmood Date: Sat, 19 Jul 2025 19:46:08 +0800 Subject: [PATCH 71/71] Content-Length Header --- lib/HttpRequestGraphQL.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/HttpRequestGraphQL.php b/lib/HttpRequestGraphQL.php index fe6106c..84fa2f6 100644 --- a/lib/HttpRequestGraphQL.php +++ b/lib/HttpRequestGraphQL.php @@ -52,6 +52,8 @@ protected static function prepareRequest($httpHeaders = array(), $data = array() } else { self::$postDataGraphQL = json_encode(['query' => $data]); } + + self::$httpHeaders['Content-Length'] = strlen(self::$postDataGraphQL); } /**