shopify

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

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

View Source
const APIVersion = "2026-10"

APIVersion is the Admin API version ReputeCast speaks (brief §4).

View Source
const Key = "shopify"

Key is the adapter's key in the stores registry.

View Source
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

View Source
var (
	Scopes        = []string{"read_customers", "read_orders", "read_products"}
	OptionalScope = "write_customers"
)

Scopes the app needs, and the optional one that passes unsubscribes back.

View Source
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

func AuthorizeURL(domain, clientID, redirect, state string, scopes []string) string

AuthorizeURL is Shopify's approval page for the app on a store.

func Sign

func Sign(secret string, body []byte) string

Sign is the X-Shopify-Hmac-Sha256 value of a body (tests and the fake).

func SignQuery

func SignQuery(q url.Values, secret string) string

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 TopicEnum

func TopicEnum(topic string) string

TopicEnum turns "orders/create" into ORDERS_CREATE.

func TopicFromEnum

func TopicFromEnum(enum string) string

TopicFromEnum turns ORDERS_CREATE into "orders/create".

func ValidShopDomain

func ValidShopDomain(host string) bool

ValidShopDomain reports whether host is a myshopify.com store domain, as Shopify names them in its redirects (letters, digits and hyphens).

func VerifyQuery

func VerifyQuery(q url.Values, secret string, now time.Time) bool

VerifyQuery checks the hmac of a query string Shopify sent, and that its timestamp is recent (a link replayed later is refused).

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a store reached with the app's access token.

func New

func New(cfg stores.Config) (*Client, error)

New opens a client on a store.

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) Count

func (c *Client) Count(ctx context.Context, kind string, r stores.Range) (int, error)

Count 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

func (c *Client) SetConsent(ctx context.Context, customerID, state string, at time.Time) error

SetConsent implements stores.Client: the customer's email marketing consent becomes unsubscribed (write_customers).

func (*Client) Shop

func (c *Client) Shop(ctx context.Context) (stores.Shop, error)

Shop implements stores.Client.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, topic, address, _ string) (stores.Webhook, error)

Subscribe implements stores.Client. Shopify signs deliveries with the app's client secret, so secret isn't sent.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(ctx context.Context, id string) error

Unsubscribe implements stores.Client. A webhook that's already gone is not an error.

func (*Client) Webhooks

func (c *Client) Webhooks(ctx context.Context) ([]stores.Webhook, error)

Webhooks implements stores.Client.

type Storefront

type Storefront struct {
	Name     string
	Domain   string // acme-merch.myshopify.com
	Currency string
}

Storefront is what a store's public address says about it.

func Resolve

func Resolve(ctx context.Context, cfg stores.Config, address string) (Storefront, error)

Resolve checks that an address answers like a Shopify store and finds its myshopify.com domain: a custom domain (shop.acme.io) answers /meta.json with it. A myshopify.com address is taken as it is when the storefront can't be read (a password-protected store).

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.

func Exchange

func Exchange(ctx context.Context, cfg stores.Config, clientID, secret, code string) (Token, error)

Exchange trades the approval's code for the store's access token. A refused client secret is stores.ErrUnauthorized (the dialog's "Shopify refused this client secret").

func Refresh

func Refresh(ctx context.Context, cfg stores.Config, clientID, secret, refresh string) (Token, error)

Refresh renews an expiring offline token.

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).

func (Webhooks) Parse

func (w Webhooks) Parse(h http.Header, body []byte) (stores.Event, error)

Parse implements stores.WebhookParser.

func (Webhooks) Topic

func (Webhooks) Topic(h http.Header) (string, string)

Topic implements stores.WebhookParser. Shopify's event id identifies an event across its retries; the older webhook id is used when it's absent.

func (Webhooks) Verify

func (Webhooks) Verify(h http.Header, body []byte, secret string) error

Verify implements stores.WebhookParser.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL