StorefrontClient
Your own storefront on a shop's catalog, carts and shopper accounts, through the Storefront API, from your PHP server. Checkout, payment and orders stay on Store Hugs: a cart ends in a link to the shop's own checkout page.
Get started
-
Turn it on. In the Store Hugs panel, open Shop Settings → Integration API and set your site's address, which checkout links back to.
-
Make a secret key (
sk_live_…). It works only from servers and is shown once; keep it in your server's secrets. Pass each shopper's IP asshopperIp, so limits count each shopper rather than your server. -
Install the SDK:
composer require storehugs/integration -
Make a client for the shopper's request:
use StoreHugs\Integration\StorefrontClient; $storefront = new StorefrontClient( host: 'shop.example.com', key: getenv('STOREHUGS_SECRET_KEY'), shopperIp: $request->ip(), locale: 'ar', ); -
Sell: list products, fill a cart, and redirect to its checkout link.
$products = $storefront->products->list(['perPage' => 12])['data']; $cart = $storefront->createCart(); $session = $storefront->cart($cart['cartToken']); $session->addItem($products[0]['id'], 2); $link = $session->checkout(['returnPath' => '/thanks']); return redirect()->away($link['checkoutUrl']);Keep
$cart['cartToken'](in the shopper's session or a cookie) to come back to the cart.
Constructor
| Parameter | Type | |
|---|---|---|
host |
string |
Required. The shop's {slug}.storehugs.com host or its custom domain. https:// is added when missing. |
key |
string |
Required. A secret key (or a publishable key). |
shopperIp |
?string |
With a secret key: the shopper your server calls for. |
accessToken |
?string |
A signed-in shopper's access token (see sign-in). |
locale |
?string |
The language of names and descriptions, one of the shop's; the shop's default otherwise. |
http |
HttpOptions |
Timeouts, retries and your own HTTP client (see HTTP options). |
Models and methods
Each page describes every method in full: its parameters, the fields it sends and gets back, its refusals and an example.