Documentation
¶
Overview ¶
Package shopify is the Shopify store adapter: a custom app the merchant creates in their own Shopify account (Dev Dashboard), installed through Shopify's own approval page (OAuth authorization code grant), then Shopify's GraphQL Admin API over plain HTTPS with the app's access token (no SDK), and webhooks verified with the app's client secret (HMAC).
The API version is pinned, and webhooks are registered with it, so the payloads keep the shape the parsers read. Addresses, phone numbers, payment details and order notes are never read: the queries don't ask for them and the webhook structs have no field for them.
Index ¶
- Constants
- Variables
- func AuthorizeURL(domain, clientID, redirect, state string, scopes []string) string
- func Sign(secret string, body []byte) string
- func SignQuery(q url.Values, secret string) string
- func TopicEnum(topic string) string
- func TopicFromEnum(enum string) string
- func ValidShopDomain(host string) bool
- func VerifyQuery(q url.Values, secret string, now time.Time) bool
- type Client
- func (c *Client) Checkouts(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Checkout], error)
- func (c *Client) Collections(ctx context.Context, cursor string) (stores.Page[stores.Collection], error)
- func (c *Client) Count(ctx context.Context, kind string, r stores.Range) (int, error)
- func (c *Client) Customers(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Customer], error)
- func (c *Client) Orders(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Order], error)
- func (c *Client) Products(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Product], error)
- func (c *Client) SetConsent(ctx context.Context, customerID, state string, at time.Time) error
- func (c *Client) Shop(ctx context.Context) (stores.Shop, error)
- func (c *Client) Subscribe(ctx context.Context, topic, address, _ string) (stores.Webhook, error)
- func (c *Client) Unsubscribe(ctx context.Context, id string) error
- func (c *Client) Webhooks(ctx context.Context) ([]stores.Webhook, error)
- type Storefront
- type Token
- type Webhooks
Constants ¶
const APIVersion = "2026-10"
APIVersion is the Admin API version ReputeCast speaks (brief §4).
const Key = "shopify"
Key is the adapter's key in the stores registry.
const LifecycleTopic = "app/uninstalled"
LifecycleTopic tells ReputeCast the app was uninstalled. It is registered with the others but isn't one of the store's data webhooks.
Variables ¶
var ( Scopes = []string{"read_customers", "read_orders", "read_products"} OptionalScope = "write_customers" )
Scopes the app needs, and the optional one that passes unsubscribes back.
var Topics = []string{
"orders/create",
"orders/paid",
"orders/updated",
"refunds/create",
"customers/create",
"customers/update",
"checkouts/create",
"checkouts/update",
"products/create",
"products/update",
"products/delete",
}
Topics are the 11 webhooks ReputeCast registers, in the order of the store page's table (brief §4).
Functions ¶
func AuthorizeURL ¶
AuthorizeURL is Shopify's approval page for the app on a store.
func SignQuery ¶
SignQuery is the hmac Shopify adds to the query strings it sends to the app URL and the redirect URL: hex HMAC-SHA256 of the other parameters, sorted, joined with "&" (tests and the fake).
func TopicFromEnum ¶
TopicFromEnum turns ORDERS_CREATE into "orders/create".
func ValidShopDomain ¶
ValidShopDomain reports whether host is a myshopify.com store domain, as Shopify names them in its redirects (letters, digits and hyphens).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a store reached with the app's access token.
func (*Client) Checkouts ¶
func (c *Client) Checkouts(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Checkout], error)
Checkouts implements stores.Client: Shopify's abandoned checkouts.
func (*Client) Collections ¶
func (c *Client) Collections(ctx context.Context, cursor string) (stores.Page[stores.Collection], error)
Collections implements stores.Client.
func (*Client) Customers ¶
func (c *Client) Customers(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Customer], error)
Customers implements stores.Client.
func (*Client) Orders ¶
func (c *Client) Orders(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Order], error)
Orders implements stores.Client.
func (*Client) Products ¶
func (c *Client) Products(ctx context.Context, cursor string, r stores.Range) (stores.Page[stores.Product], error)
Products implements stores.Client.
func (*Client) SetConsent ¶
SetConsent implements stores.Client: the customer's email marketing consent becomes unsubscribed (write_customers).
func (*Client) Subscribe ¶
Subscribe implements stores.Client. Shopify signs deliveries with the app's client secret, so secret isn't sent.
func (*Client) Unsubscribe ¶
Unsubscribe implements stores.Client. A webhook that's already gone is not an error.
type Storefront ¶
Storefront is what a store's public address says about it.
type Token ¶
type Token struct {
AccessToken string
Scopes []string
// RefreshToken and ExpiresAt are set when Shopify issues an expiring
// offline token.
RefreshToken string
ExpiresAt *time.Time
}
Token is what the code exchange returns.
type Webhooks ¶
type Webhooks struct{}
Webhooks verifies and parses Shopify's deliveries. Shopify signs the raw body with the app's client secret (X-Shopify-Hmac-Sha256, base64).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package shopifytest is an in-memory Shopify: the store's storefront metadata (/meta.json), the app install (OAuth's code exchange and token refresh) and the subset of the GraphQL Admin API the adapter calls, answered from an in-memory store in the shapes Shopify returns, plus helpers that build signed webhook deliveries in Shopify's REST payload shape.
|
Package shopifytest is an in-memory Shopify: the store's storefront metadata (/meta.json), the app install (OAuth's code exchange and token refresh) and the subset of the GraphQL Admin API the adapter calls, answered from an in-memory store in the shapes Shopify returns, plus helpers that build signed webhook deliveries in Shopify's REST payload shape. |