Skip to content

Additional endpoints, features, and fixes. #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
eeacfc6
added additional endpoints
Sep 7, 2019
882a18a
Delete .DS_Store
Sep 7, 2019
718ed55
Delete .DS_Store
Sep 7, 2019
4a48a40
added checkout endpoints
Sep 7, 2019
0db069b
added checkout endpoints
Sep 7, 2019
c180ae1
Merge branch 'master' of https://github.com/TuunStudio/php-shopify
Sep 7, 2019
da95575
added sales channel sdk endpoints
Sep 7, 2019
184894e
Delete .DS_Store
Sep 7, 2019
4a9ca6f
Delete .DS_Store
Sep 7, 2019
f470422
added sales channel sdk endpoints
Sep 7, 2019
6aeee19
Merge branch 'master' of https://github.com/TuunStudio/php-shopify
Sep 7, 2019
9b361f6
removed customer order
Sep 7, 2019
8560d2d
added support for cursor based pagination
Dec 21, 2019
91c0ad5
added additional endpoints
Sep 7, 2019
1417d23
Delete .DS_Store
Sep 7, 2019
79c1366
Delete .DS_Store
Sep 7, 2019
2d424c5
added checkout endpoints
Sep 7, 2019
928df36
added checkout endpoints
Sep 7, 2019
e577d9a
added sales channel sdk endpoints
Sep 7, 2019
d23e51b
Delete .DS_Store
Sep 7, 2019
da78ce9
Delete .DS_Store
Sep 7, 2019
65f27b8
added sales channel sdk endpoints
Sep 7, 2019
d332736
removed customer order
Sep 7, 2019
c5bfe0e
added support for cursor based pagination
Dec 21, 2019
4e13a2a
fixed get access token request
Jan 27, 2020
56925b0
Merge branch 'master' of ssh://github.com/TuunStudio/php-shopify
Jan 27, 2020
dd3b467
merge with upstream
Apr 15, 2020
8d3f529
Merge branch 'master' of https://github.com/TuunStudio/php-shopify
Apr 15, 2020
304761d
fixed conflicts
Apr 15, 2020
ddf9bce
fixed shopify resource
Apr 15, 2020
01ddc1b
added json_decode
Apr 15, 2020
5bdf347
paging
Apr 15, 2020
e71baca
fixed auth helper
Apr 21, 2020
eebe407
updated to current version
Apr 23, 2020
764fa9d
added discount code location
Jul 3, 2020
e49925f
added discount code location
Jul 3, 2020
32e6782
added application credit endpoint
Oct 14, 2020
6ecbaf9
updated generate url to support numeric indexed arrays
May 5, 2021
921d83d
added http code to shopify resource
Nov 1, 2021
30bb0f9
combined resources from upstream, and removed url option from post re…
Dec 7, 2022
34066f6
fixed response array issues
Dec 7, 2022
98b357d
added httpcode to resource
Dec 8, 2022
f266b2e
Added gift card adjustment functionality
justin-gist-apps Feb 28, 2023
a9c22b1
added last httpCode
tuun Jun 8, 2023
2d4f380
fixed http code
tuun Dec 8, 2023
bf36ab2
fixed content type header
tuun Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
/nbproject/private/
.idea/
.idea/
.DS_Store
26 changes: 26 additions & 0 deletions lib/ApplicationCredit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* @author Tareq Mahmood <[email protected]>
* Created at 8/18/16 9:50 AM UTC+06:00
*
* @see https://help.shopify.com/api/reference/applicationcharge Shopify API Reference for ApplicationCharge
*/

namespace PHPShopify;


class ApplicationCredit extends ShopifyResource
{
/**
* @inheritDoc
*/
protected $resourceKey = 'application_credit';

/**
* @inheritDoc
*/
public $countEnabled = false;


}
2 changes: 1 addition & 1 deletion lib/AuthHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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

Expand Down
53 changes: 53 additions & 0 deletions lib/Checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Created by PhpStorm.
* @author Tareq Mahmood <[email protected]>
* Created at 8/19/16 2:59 PM UTC+06:00
*
* @see https://help.shopify.com/api/reference/sales-channels/checkout Shopify API Reference for Checkout
*/

namespace PHPShopify;


/**
* --------------------------------------------------------------------------
* Order -> Child Resources
* --------------------------------------------------------------------------
* @property-read ShippingRate $ShippingRate
*
* @method ShippingRate ShippingRate(integer $id = null)
*

* --------------------------------------------------------------------------
* Checkout -> Custom actions
* --------------------------------------------------------------------------
* @method array complete() Completes Checkout without payment
*
*/
class Checkout extends ShopifyResource
{
/**
* @inheritDoc
*/
protected $resourceKey = 'checkout';

/**
* @inheritDoc
*/
public $countEnabled = false;

/**
* @inheritDoc
*/
protected $childResource = array (
'ShippingRate',
);
/**
* @inheritDoc
*/
protected $customPostActions = array(
'complete',
'payments'
);
}
32 changes: 32 additions & 0 deletions lib/CollectionListing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* @author Tareq Mahmood <[email protected]>
* Created at: 6/2/18 1:38 PM UTC+06:00
*
* @see https://help.shopify.com/api/reference/sales_channels/collectionlisting
*/

namespace PHPShopify;
/**
* --------------------------------------------------------------------------
* CollectionListing -> Custom actions
* --------------------------------------------------------------------------
* @method array productIds() Sets the address as default for the customer
*/

class CollectionListing extends ShopifyResource
{
/**
* @inheritDoc
*/
protected $resourceKey = 'collection_listing';

/**
* @inheritDoc
*/
protected $customGetActions = array(
'product_ids' => 'productIds',
);

}
9 changes: 8 additions & 1 deletion lib/GiftCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class GiftCard extends ShopifyResource
*/
public $searchEnabled = true;

/**
* @inheritDoc
*/
protected $childResource = array(
'GiftCardAdjustment' => 'Adjustment'
);

/**
* Disable a gift card.
* Disabling a gift card is permanent and cannot be undone.
Expand All @@ -45,4 +52,4 @@ public function disable()

return $this->post($dataArray, $url);
}
}
}
36 changes: 36 additions & 0 deletions lib/GiftCardAdjustment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Created by PhpStorm.
* @author Tareq Mahmood <[email protected]>
* Created at 8/19/16 12:07 PM UTC+06:00
*
* @see https://help.shopify.com/api/reference/customeraddress Shopify API Reference for CustomerAddress
*/

namespace PHPShopify;


/**
* --------------------------------------------------------------------------
* GiftCardAdjustment -> Custom actions
* --------------------------------------------------------------------------
* @method array makeDefault() Sets the address as default for the customer
*
*/
class GiftCardAdjustment extends ShopifyResource
{
/**
* @inheritDoc
*/
protected $resourceKey = 'adjustment';

/**
* @inheritDoc
*/
protected function pluralizeKey()
{
return 'adjustments';
}


}
4 changes: 2 additions & 2 deletions lib/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function post($graphQL, $url = null, $wrapData = false, $variables = null
if (!$url) $url = $this->generateUrl();

$response = HttpRequestGraphQL::post($url, $graphQL, $this->httpHeaders, $variables);

return $this->processResponse($response);
}

Expand Down Expand Up @@ -75,4 +75,4 @@ public function delete($urlParams = array(), $url = null)
{
throw new SdkException("Only POST method is allowed for GraphQL!");
}
}
}
11 changes: 7 additions & 4 deletions lib/HttpRequestGraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ protected static function prepareRequest($httpHeaders = array(), $data = array()
throw new SdkException("The GraphQL Admin API requires an access token for making authenticated requests!");
}

self::$httpHeaders = $httpHeaders;

if (is_array($variables)) {
self::$postDataGraphQL = json_encode(['query' => $data, 'variables' => $variables]);
self::$httpHeaders['Content-type'] = 'application/json';
$httpHeaders['Content-type'] = 'application/json';
} else {
self::$httpHeaders['Content-type'] = 'application/graphql';
$httpHeaders['Content-type'] = 'application/graphql';
}

$httpHeaders['X-Shopify-Access-Token'] = $httpHeaders['X-Shopify-Access-Token'];

self::$httpHeaders = $httpHeaders;
}

/**
Expand All @@ -66,6 +68,7 @@ protected static function prepareRequest($httpHeaders = array(), $data = array()
*/
public static function post($url, $data, $httpHeaders = array(), $variables = null)
{

self::prepareRequest($httpHeaders, $data, $variables);

self::$postDataJSON = self::$postDataGraphQL;
Expand Down
2 changes: 1 addition & 1 deletion lib/HttpRequestJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static function shouldRetry($response, $error, $retry) {
*
* @param string $response
*
* @return array
* @return string
*/
protected static function processResponse($response)
{
Expand Down
19 changes: 19 additions & 0 deletions lib/ShippingRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* @author Tareq Mahmood <[email protected]>
* Created at 8/19/16 7:27 PM UTC+06:00
*
* @see https://help.shopify.com/api/reference/shipping_rates Shopify API Reference for ShippingRate
*/

namespace PHPShopify;


class ShippingRate extends ShopifyResource
{
/**
* @inheritDoc
*/
protected $resourceKey = 'shipping_rate';
}
53 changes: 42 additions & 11 deletions lib/ShopifyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ abstract class ShopifyResource
*/
private $prevLink = null;

/**
* HTTP code used to check if we need to poll or not
*/
public $httpCode = null;

/**
* Response Header Location, used for discount code lookup
* @see: https://shopify.dev/docs/admin-api/rest/reference/discounts/discountcode?api[version]=2020-04#lookup-2020-04
* @var string $discountLocation
*/
private $discountLocation = null;

public function __construct($id = null, $parentResourceUrl = '')
{
$this->id = $id;
Expand Down Expand Up @@ -319,7 +331,7 @@ protected function getResourcePath()
*/
public function generateUrl($urlParams = array(), $customAction = null)
{
return $this->resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . http_build_query($urlParams) : '');
return $this->resourceUrl . ($customAction ? "/$customAction" : '') . '.json' . (!empty($urlParams) ? '?' . preg_replace('/\%5B\d+\%5D/', '%5B%5D', http_build_query($urlParams)) : '');
}

/**
Expand Down Expand Up @@ -514,44 +526,59 @@ protected function castString($array)
/**
* Process the request response
*
* @param array $responseArray Request response in array format
* @param array $response Request response in array format
* @param string $dataKey Keyname to fetch data from response array
*
* @throws ApiException if the response has an error specified
* @throws CurlException if response received with unexpected HTTP code.
*
* @return array
*/
public function processResponse($responseArray, $dataKey = null)
public function processResponse($response, $dataKey = null)
{

self::$lastHttpResponseHeaders = CurlRequest::$lastHttpResponseHeaders;

$lastResponseHeaders = CurlRequest::$lastHttpResponseHeaders;

$this->getLinks($lastResponseHeaders);

if (isset($responseArray['errors'])) {
$message = $this->castString($responseArray['errors']);
$this->getLocationHeader($lastResponseHeaders);

$httpCode = CurlRequest::$lastHttpCode;
$this->httpCode = $httpCode;

if (isset($response['errors'])) {
$message = $this->castString($response['errors']);

//check account already enabled or not
if($message=='account already enabled'){
return array('account_activation_url'=>false);
}
throw new ApiException($message, CurlRequest::$lastHttpCode);

throw new ApiException($message, $httpCode);
}

if ($dataKey && isset($responseArray[$dataKey])) {
return $responseArray[$dataKey];
if ($dataKey && isset($response[$dataKey])) {
return $response[$dataKey];
} else {
return $responseArray;
return $response;
}
}

public function getLinks($responseHeaders){
public function getLinks($responseHeaders) {
$this->nextLink = $this->getLink($responseHeaders,'next');
$this->prevLink = $this->getLink($responseHeaders,'previous');
}

public function getLocationHeader($responseHeaders) {

if(!empty($responseHeaders['location'])) {
$this->discountLocation = $responseHeaders['location'];
}

}

public function getLink($responseHeaders, $type='next'){

if(array_key_exists('x-shopify-api-version', $responseHeaders)
Expand Down Expand Up @@ -587,6 +614,10 @@ public function getNextLink(){
return $this->nextLink;
}

public function getDiscountLocation(){
return $this->discountLocation;
}

public function getUrlParams($url) {
if ($url) {
$parts = parse_url($url);
Expand Down
Loading