Meet Toki Operator

Docs/Wallet SDK

Paid memberships

Sell paid memberships, and let customers change, pause, cancel and extend their subscription.

A paid membership is a membership customers buy: a recurring Monthly, Quarterly or Annually plan, billed through a Shopify subscription, or a one-time Lifetime plan. Methods that take a membershipId manage the signed-in customer's subscription to that membership. Amounts are decimal amounts in currency units, such as 9.99, and dates are ISO 8601 date-times unless a field says otherwise.

Methods9 reads · 17 actions

getPaidMemberships#

tokiWallet.getPaidMemberships()→ Promise<{ subscriptions: PaidMembership[] }>

Lists the paid memberships your store sells, with their plans and the customer's subscription to each.

Returns your active paid memberships in the current store, in your membership order: one that comes later is an upgrade from one that comes earlier.

To sell a plan, add variant_id to the cart with Shopify's cart API, with the plan's sellingPlanId as its selling plan (none for Lifetime). When the order comes in, the new membership replaces the customer's current recurring one. If you cap a membership with a member limit, check checkMembershipLimit first.

Returns

Promise<{ subscriptions: PaidMembership[] }>
  • subscriptionsPaidMembership[]
    11 fields per item
    • membership_idstring

      The paid membership's ID, the membershipId other methods take.

    • namestring
    • membership_cardstring | null

      URL of the membership's card image.

    • plansPaidMembershipPlan[]

      The plans you sell.

      3 fields per item
      • pricestring

        Price per billing period, or the one-time price for Lifetime, as a decimal string in your store's currency, such as "9.99".

      • option"Monthly" | "Quarterly" | "Annually" | "Lifetime"
      • sellingPlanIdstring | null

        Numeric ID of the plan's Shopify selling plan, to add to the cart with variant_id. null for Lifetime, which is a one-time purchase.

    • planobject

      The customer's plan of this membership, with its option and its price, what they pay, as a decimal string. Empty when they've never subscribed to it.

    • status"ACTIVE" | "PENDING" | "PAUSED" | "CANCELLED" | null

      The customer's subscription to it. null when they've never subscribed to it.

    • is_openedboolean

      true when it's the customer's current membership.

    • is_pendingboolean

      true when it's the customer's next plan, after a downgrade.

    • is_pausedboolean
    • next_payment_atstring | null

      When the customer is next charged for it. For their next plan, when it starts.

    • variant_idstring

      Numeric ID of the membership's Shopify product variant in the current store.

Example
const { subscriptions } =
  await tokiWallet.getPaidMemberships()
const current = subscriptions.find(
  (membership) => membership.is_opened,
)
Result
{
  "subscriptions": [
    {
      "membership_id": "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
      "name": "Gold",
      "membership_card": "https://cdn.shopify.com/s/files/1/0601/2345/files/gold-card.png",
      "plans": [
        { "price": "9.99", "option": "Monthly", "sellingPlanId": "690871287993" }
      ],
      "plan": { "price": "9.99", "option": "Monthly" },
      "status": "ACTIVE",
      "is_opened": true,
      "is_pending": false,
      "is_paused": false,
      "next_payment_at": "2026-11-12T09:30:00.000Z",
      "variant_id": "44012345678901"
    }
  ]
}
read

checkMembershipLimit#

tokiWallet.checkMembershipLimit({ membershipId })→ Promise<MembershipLimit>

Checks whether a paid membership has reached its member limit.

With a member limit on a membership, Toki stops new sign-ups once it's full. Check it before you add the membership to the cart.

Options

one object
  • membershipIdstringRequired

    The paid membership, by membership_id from getPaidMemberships.

Returns

Promise<MembershipLimit>
  • isMembersLimitReachedboolean

    true when the membership has as many members as its limit allows.

Example
const { isMembersLimitReached } =
  await tokiWallet.checkMembershipLimit({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  })
Result
{ "isMembersLimitReached": false }

getUserPaidMemberships#

tokiWallet.getUserPaidMemberships()→ Promise<{ memberships: UserPaidMembership[] }>

Lists the customer's paid membership subscriptions, with their plan, dates, perks, add-ons and subscription box.

Returns the customer's ACTIVE, PENDING and PAUSED subscriptions to your active paid memberships, in your membership order, and a cancelled one while they can reactivate it.

A subscription cancelled at the end of its billing cycle stays ACTIVE until expiresOn, with no nextPaymentAt. A scheduled pause shows as pauseStartsAt on an ACTIVE subscription.

Returns

Promise<{ memberships: UserPaidMembership[] }>
  • membershipsUserPaidMembership[]
    17 fields per item
    • membershipIdstring

      The paid membership's ID, for the methods below.

    • namestring
    • status"ACTIVE" | "PENDING" | "PAUSED" | "CANCELLED"

      PENDING is the customer's next plan, after a downgrade. ACTIVE subscriptions give the membership's benefits.

    • planobject

      The plan the customer is on.

      2 fields
      • option"Monthly" | "Quarterly" | "Annually" | "Lifetime"
      • pricestring

        What the customer pays per billing cycle, or once for Lifetime, as a decimal string in your store's currency, such as "9.99".

    • nextPaymentAtstring | null

      When the customer is next charged. null when no payment is scheduled, as for Lifetime plans, after a cancellation, or during a pause without an end date.

    • expiresOnstring | null

      When access ends unless the subscription renews. null for a plan with no end date, such as Lifetime.

    • pauseStartsAtstring | null

      Start of a scheduled pause.

    • pausedAtstring | null

      When the current pause started.

    • pausedUntilstring | null

      When the pause ends and the subscription resumes on its own. null for a pause without an end date.

    • pausedRemainingSecondsnumber | null

      Paid time the customer had left when the pause started, in seconds. It counts again from the resume.

    • membershipCardstring | null

      URL of the membership's card image.

    • cancellationPolicy"immediately" | "endOfBillingCycle"

      What a cancellation does: end access right away, or stop renewals and keep access until expiresOn. Lifetime plans end right away.

    • pauseobject
      1 field
      • enabledboolean

        true when the customer can pause, or could if they had pauses left. See getUserPaidMembershipPauseConfiguration.

    • canReactivateboolean

      true for a cancelled recurring subscription that reactivateUserPaidMembership can restart.

    • perksstring[]

      The membership's rewards, as short texts in the storefront's language, such as "10% off every order".

    • addonsPaidMembershipAddon[]

      The membership's add-ons, with their state for this customer.

      10 fields per item
      • addonIdstring

        The add-on's ID, for the add-on methods.

      • namestring
      • descriptionstring | null
      • plan"Monthly" | "Quarterly" | "Annually" | "Lifetime"

        The membership plan price is for.

      • pricenumber

        What the add-on costs per billing cycle, as a decimal amount, such as 4.99.

      • status"available" | "connected" | "cancellation_scheduled"
      • cancelsAtstring | null

        With cancellation_scheduled: when the add-on ends, the subscription's next payment date.

      • canConnectboolean

        true when the customer can add it.

      • canCancelboolean
      • canUndoCancellationboolean
    • box{ enabled: false } | SubscriptionBox

      The customer's next subscription box, as getUserPaidMembershipBox returns it, or { enabled: false } when the subscription has no box.

Example
const { memberships } =
  await tokiWallet.getUserPaidMemberships()
const current = memberships.find(
  (membership) => membership.status === "ACTIVE",
)
Result
{
  "memberships": [
    {
      "membershipId": "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
      "name": "Gold",
      "status": "ACTIVE",
      "plan": { "price": "9.99", "option": "Monthly" },
      "nextPaymentAt": "2026-11-12T09:30:00.000Z",
      "expiresOn": "2026-11-13T09:30:00.000Z",
      "pauseStartsAt": null,
      "pausedAt": null,
      "pausedUntil": null,
      "pausedRemainingSeconds": null,
      "membershipCard": "https://cdn.shopify.com/s/files/1/0601/2345/files/gold-card.png",
      "cancellationPolicy": "endOfBillingCycle",
      "pause": { "enabled": true },
      "canReactivate": false,
      "perks": ["10% off every order"],
      "addons": [
        {
          "addonId": "b7e4c2a1-9d3f-4e6b-8a5c-2f1e0d9c8b7a",
          "name": "Priority support",
          "description": "Skip the line when you contact us.",
          "plan": "Monthly",
          "price": 4.99,
          "status": "available",
          "cancelsAt": null,
          "canConnect": true,
          "canCancel": false,
          "canUndoCancellation": false
        }
      ],
      "box": { "enabled": false }
    }
  ]
}

changeUserMembership#

tokiWallet.changeUserMembership({ targetPlan, confirm? })→ Promise<PlanChange>

Previews or makes a change of the customer's plan: to another plan of their membership, or to another paid membership.

Call it without confirm first: it changes nothing and returns what the change would do. With storefrontAction: "require_confirmation", show the customer result, then call it again with the same targetPlan and confirm: true. With "add_to_cart", the customer buys the plan at checkout instead, as for a Lifetime plan, a plan they can start with a trial, or any plan when they have no active recurring subscription: add it to the cart (see getPaidMemberships).

A move to a membership later in your membership order, or to a pricier plan of the same membership, is an upgrade. It takes effect right away on a new Shopify subscription, and the customer pays the new price at once with their saved payment method, less credit for the unused days of their current plan when you turn prorations on and they're not in a trial. With prorations, an upgrade to a plan that costs less than the current one costs nothing now and moves the next payment to nextPaymentAt. A payment can take a minute or two to process.

A downgrade is scheduled: the current plan stops renewing and lasts until it ends, and the new plan starts with its first payment at nextPaymentAt. Until then, a downgrade to another membership shows as a PENDING subscription.

Rejects when targetPlan is the customer's current plan, or when the target membership isn't active or is full.

Options

one object
  • targetPlanobjectRequired

    The plan to move to.

    2 fields
    • idstringRequired

      The paid membership, by membershipId.

    • plan"Monthly" | "Quarterly" | "Annually" | "Lifetime"Required
  • confirmbooleandefault false

    true makes the change. Leave it out to preview.

Returns

Promise<PlanChange>

A preview without confirm, the outcome with it.

  • storefrontAction"require_confirmation" | "add_to_cart" | "none"

    What to do next. Preview: require_confirmation to confirm the change with the customer, or add_to_cart to sell the plan at checkout. With confirm: none once the change is made, or add_to_cart.

  • action"upgrade" | "downgrade"Optional

    Whether the change is an upgrade or a downgrade.

  • resultPlanChangeQuote | nullOptional

    Preview only: what the change costs and when. null with add_to_cart.

    6 fields
    • action"extend_membership" | "apply_discount" | "upgrade_membership" | "downgrade_membership"

      extend_membership: nothing to pay now, and the next payment moves to nextPaymentAt. apply_discount: the customer pays nextPayment now, the new price less discount. upgrade_membership: they pay the full price now. downgrade_membership: the new plan starts at nextPaymentAt.

    • nextPaymentnumber

      Amount of the next payment: charged right away for apply_discount and upgrade_membership, at nextPaymentAt otherwise.

    • nextScheduledPaymentnumber

      The new plan's regular price, charged at later renewals.

    • nextPaymentAtstring

      Date of the next scheduled payment, as YYYY-MM-DD. After a payment made right away, it's the renewal that follows.

    • discountnumberOptional

      apply_discount only: credit for the unused time of the current plan.

    • currency{ code: string; symbol: string }Optional

      apply_discount only: the currency of the amounts. The other results are in your store's currency.

  • nextPaymentAtstringOptional

    With confirm: when the new plan is next charged. For a downgrade, its first payment.

  • isBillingImmediatelybooleanOptional

    With confirm: true when the change charged the customer right away.

Example
const preview = await tokiWallet.changeUserMembership({
  targetPlan: {
    id: "8d2e5f4a-1b3c-4d6e-8f9a-0b1c2d3e4f5a",
    plan: "Monthly",
  },
})
Result
{
  "storefrontAction": "require_confirmation",
  "action": "upgrade",
  "result": {
    "action": "apply_discount",
    "nextPayment": 12.5,
    "nextScheduledPayment": 19.99,
    "nextPaymentAt": "2026-12-12",
    "discount": 7.49,
    "currency": { "code": "USD", "symbol": "$" }
  }
}

getUserPaidMembershipPauseConfiguration#

tokiWallet.getUserPaidMembershipPauseConfiguration({ membershipId })→ Promise<PauseConfiguration>

Returns whether the customer can pause their subscription, when the pause would start and how long it can last.

Uses the first of your pause rules that matches the customer. Let them pick a resume date after pauseStartsAt and within duration.limit of it, or no date when the duration is unlimited.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<PauseConfiguration>
  • availableboolean

    true when the customer can pause now.

  • reasonstringOptional

    When available is false: why, such as usage_limit_exceeded when the customer has used their pauses for the period, or pause_disabled.

  • pauseStartsAtstringOptional

    When available: when a pause would start. Now, or the next payment date when pauses start at the end of the billing period in your settings.

  • durationobjectOptional

    How long a pause can last.

    2 fields
    • type"limited" | "unlimited"
    • limit{ period: number; interval: "days" | "months" | "years" }Optional

      limited only: the longest a pause can last.

  • usageLimitobjectOptional

    How often the customer can pause.

    5 fields
    • amountnumber

      Pauses allowed within the rolling period.

    • periodnumber

      Length of the period, in interval units.

    • interval"days" | "months" | "years"
    • usednumber

      Pauses the customer started within the period.

    • remainingnumber

      Pauses left.

Example
const pause =
  await tokiWallet.getUserPaidMembershipPauseConfiguration(
    {
      membershipId:
        "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    },
  )
Result
{
  "available": true,
  "pauseStartsAt": "2026-10-20T14:05:12.000Z",
  "duration": { "type": "limited", "limit": { "period": 3, "interval": "months" } },
  "usageLimit": { "amount": 1, "period": 1, "interval": "years", "used": 0, "remaining": 1 }
}

pauseUserPaidMembership#

tokiWallet.pauseUserPaidMembership({ membershipId, pausedUntil? })→ Promise<void>

Pauses the customer's subscription, or schedules the pause for their next payment date.

If pauses start immediately in your pause settings, the subscription is PAUSED right away: its benefits and renewals stop, and its Shopify subscription is paused. The paid time the customer had left is kept: at pausedUntil, Toki resumes the subscription, and the next payment comes once that time has run.

If pauses start at the end of the billing period, the pause is scheduled for the next payment date (pauseStartsAt), and the subscription stays ACTIVE until then. When it resumes, a new billing period starts with a payment.

Rejects when the customer can't pause (see getUserPaidMembershipPauseConfiguration), or when pausedUntil doesn't fit the pause rule.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • pausedUntilstring | nulldefault null

    When the subscription resumes on its own, as an ISO 8601 date-time such as "2027-01-15T00:00:00.000Z". null pauses it until the customer resumes, when the rule's duration is unlimited.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.pauseUserPaidMembership({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  pausedUntil: new Date("2027-01-15").toISOString(),
})

resumeUserPaidMembership#

tokiWallet.resumeUserPaidMembership({ membershipId })→ Promise<void>

Resumes the customer's paused subscription, or calls off a scheduled pause.

A PAUSED subscription is ACTIVE again right away, with its benefits and its Shopify subscription. The paid time the customer had left when they paused counts again from now, and the next payment comes at its end. After a scheduled pause, a new billing period starts now with a payment.

On an ACTIVE subscription with a scheduled pause, it calls the pause off and keeps the next payment date the subscription had before.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.resumeUserPaidMembership({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
})

getUserPaidMembershipRetentionOffer#

tokiWallet.getUserPaidMembershipRetentionOffer({ membershipId })→ Promise<RetentionOfferResult>

Returns the retention offer the customer would get if they started to cancel.

Picks the retention offer that matches the customer, to decide whether your cancellation flow shows an offer. To make the offer, so the customer can accept it, call createUserPaidMembershipRetentionOffer.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<RetentionOfferResult>
  • availableboolean

    false when you don't offer retention offers, none matches the customer, or they've accepted the matching one as often as it allows.

  • offerRetentionOfferOptional

    When available: the offer.

    9 fields
    • idstring
    • namestring

      The offer's title, shown to the customer.

    • descriptionstring | nullOptional
    • acceptedMessagestring | nullOptional

      The message to show once the customer accepts.

    • type"discount" | "free-days"
    • discountType"percentage" | "fixed"Optional

      discount only: how amount applies.

    • amountnumberOptional

      discount only: the percentage off, such as 20, or the amount off in the subscription's currency.

    • recurringCycleLimitnumberOptional

      discount only: how many renewals the discount lasts.

    • daysnumberOptional

      free-days only: how many days later the next payment and expiry dates move.

Example
const { available, offer } =
  await tokiWallet.getUserPaidMembershipRetentionOffer({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  })
Result
{
  "available": true,
  "offer": {
    "id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
    "name": "20% off your next 2 months",
    "description": "Stay a little longer and save.",
    "acceptedMessage": "Done! Your next 2 renewals are 20% off.",
    "type": "discount",
    "discountType": "percentage",
    "amount": 20,
    "recurringCycleLimit": 2
  }
}

createUserPaidMembershipRetentionOffer#

tokiWallet.createUserPaidMembershipRetentionOffer({ membershipId })→ Promise<RetentionOfferResult>

Makes the customer a retention offer when they start to cancel.

Picks the offer like getUserPaidMembershipRetentionOffer and records that the customer was offered it. Show it with a choice to accept it or continue cancelling, and pass userOfferId to acceptUserPaidMembershipRetentionOffer when they accept. The subscription doesn't change until then.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<RetentionOfferResult>
  • availableboolean

    false when there's no offer for the customer: continue with the cancellation.

  • offerRetentionOfferOptional

    When available: the offer.

    9 fields
    • idstring
    • namestring

      The offer's title, shown to the customer.

    • descriptionstring | nullOptional
    • acceptedMessagestring | nullOptional

      The message to show once the customer accepts.

    • type"discount" | "free-days"
    • discountType"percentage" | "fixed"Optional

      discount only: how amount applies.

    • amountnumberOptional

      discount only: the percentage off, such as 20, or the amount off in the subscription's currency.

    • recurringCycleLimitnumberOptional

      discount only: how many renewals the discount lasts.

    • daysnumberOptional

      free-days only: how many days later the next payment and expiry dates move.

  • userOfferIdstringOptional

    When available: pass it to acceptUserPaidMembershipRetentionOffer.

Example
const { available, offer, userOfferId } =
  await tokiWallet.createUserPaidMembershipRetentionOffer(
    {
      membershipId:
        "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    },
  )
Result
{
  "available": true,
  "offer": {
    "id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
    "name": "1 month on us",
    "description": "Take 30 free days before you decide.",
    "acceptedMessage": "Enjoy! Your next payment moved 30 days later.",
    "type": "free-days",
    "days": 30
  },
  "userOfferId": "5e6f7a8b-9c0d-4e1f-a2b3-c4d5e6f7a8b9"
}

acceptUserPaidMembershipRetentionOffer#

tokiWallet.acceptUserPaidMembershipRetentionOffer({ membershipId, userOfferId })→ Promise<void>

Accepts a retention offer for the customer and applies it to their subscription right away.

A discount offer adds a discount to the customer's Shopify subscription for its number of renewals. A free-days offer moves their next payment date, and their expiry date, that many days later. Nothing is charged now. Show the offer's acceptedMessage once it resolves.

Rejects when the customer has already accepted this offer.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • userOfferIdstringRequired

    From createUserPaidMembershipRetentionOffer.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.acceptUserPaidMembershipRetentionOffer({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  userOfferId: "5e6f7a8b-9c0d-4e1f-a2b3-c4d5e6f7a8b9",
})

cancelUserPaidMembership#

tokiWallet.cancelUserPaidMembership({ membershipId, reasonDescription })→ Promise<void>

Cancels the customer's subscription, following your cancellation policy.

If your cancellation policy cancels benefits immediately, the subscription is CANCELLED right away, along with its Shopify subscription. If it cancels them at the end of the billing cycle, the subscription stops renewing and stays ACTIVE until expiresOn. Lifetime plans end right away.

Its add-ons follow the same policy, and a scheduled downgrade is called off. Toki records reasonDescription and sends the cancellation to your connected integrations. To keep the customer, make them a retention offer first with createUserPaidMembershipRetentionOffer.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • reasonDescriptionstringRequired

    Why the customer is cancelling, such as the reason they picked. It can be empty.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.cancelUserPaidMembership({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  reasonDescription: "Too expensive",
})

reactivateUserPaidMembership#

tokiWallet.reactivateUserPaidMembership({ membershipId })→ Promise<void>

Restarts the customer's cancelled subscription and charges them for it right away.

Works for a cancelled recurring subscription whose access has ended, when canReactivate is true in getUserPaidMemberships. Toki reactivates its Shopify subscription and charges the saved payment method, and the promise resolves once the subscription is ACTIVE again.

Rejects with the reason when the payment doesn't go through.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.reactivateUserPaidMembership({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
})

previewUserPaidMembershipAddons#

tokiWallet.previewUserPaidMembershipAddons({ membershipId, addonIds })→ Promise<AddonPurchasePreview>

Previews what adding add-ons to the customer's subscription costs now.

Returns what purchaseUserPaidMembershipAddons would charge for the same add-ons, without charging. With prorations on, the first payment covers only the days left until the next renewal, and is at least 0.50 in the subscription's currency. During a trial, nothing is due now.

Rejects when any of the add-ons can't be added (see canConnect in getUserPaidMemberships).

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • addonIdsstring[]Required

    The add-ons, by addonId. At least one.

Returns

Promise<AddonPurchasePreview>
  • subtotalnumber

    The add-ons' regular price per billing cycle, together.

  • discountnumber

    The proration discount on the first payment.

  • amountDueNownumber

    What the customer pays now: subtotal less discount, or 0 during a trial.

  • currencyCodestring

    The subscription's currency, such as USD.

  • trialboolean

    true while the subscription is in its trial: the add-ons start billing at its next payment.

  • paymentMethodobject | null

    The saved payment method that's charged.

    2 fields
    • type"card" | "shop_pay" | "paypal" | "saved"
    • displayNamestring

      A name to show, such as the card brand and its last digits.

Example
const preview =
  await tokiWallet.previewUserPaidMembershipAddons({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    addonIds: ["b7e4c2a1-9d3f-4e6b-8a5c-2f1e0d9c8b7a"],
  })
Result
{
  "subtotal": 4.99,
  "discount": 2.49,
  "amountDueNow": 2.5,
  "currencyCode": "USD",
  "trial": false,
  "paymentMethod": { "type": "card", "displayName": "Visa •••• •••• •••• 4242" }
}

purchaseUserPaidMembershipAddons#

tokiWallet.purchaseUserPaidMembershipAddons({ membershipId, addonIds })→ Promise<AddonPurchase>

Adds add-ons to the customer's subscription and charges for them right away.

Charges amountDueNow from previewUserPaidMembershipAddons to the saved payment method. Once the payment goes through, the add-ons join the customer's Shopify subscription and renew with the membership. During a trial, they're added without a payment now.

Rejects when any of the add-ons can't be added.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • addonIdsstring[]Required

    The add-ons, by addonId. At least one.

Returns

Promise<AddonPurchase>
  • status"paid" | "trial-added" | "test-added" | "pending" | "failed"

    paid: charged, and the add-ons show as connected once Toki has processed the payment. trial-added and test-added: added to a subscription in its trial, or to a test subscription, without a payment. pending: the payment is still processing. failed: the payment didn't go through, and errorMessage says why.

  • addonIdsstring[]

    The add-ons this purchase adds.

  • errorMessagestring | nullOptional

    With failed: why the payment didn't go through.

Example
const { status } =
  await tokiWallet.purchaseUserPaidMembershipAddons({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    addonIds: ["b7e4c2a1-9d3f-4e6b-8a5c-2f1e0d9c8b7a"],
  })
Result
{
  "status": "paid",
  "addonIds": ["b7e4c2a1-9d3f-4e6b-8a5c-2f1e0d9c8b7a"],
  "errorMessage": null
}

cancelUserPaidMembershipAddon#

tokiWallet.cancelUserPaidMembershipAddon({ membershipId, addonId })→ Promise<AddonCancellation>

Cancels an add-on on the customer's subscription from its next renewal.

Removes the add-on from the customer's Shopify subscription, so it doesn't renew. The customer keeps it until cancelsAt, the subscription's next payment date, and can keep it after all with undoUserPaidMembershipAddonCancellation until then.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • addonIdstringRequired

Returns

Promise<AddonCancellation>
  • status"cancellation_scheduled" | "cancelled"

    cancelled when the add-on ends right away, as on a test subscription.

  • cancelsAtstring | null

    When the add-on ends.

Example
const { cancelsAt } =
  await tokiWallet.cancelUserPaidMembershipAddon({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    addonId: "b7e4c2a1-9d3f-4e6b-8a5c-2f1e0d9c8b7a",
  })
Result
{ "status": "cancellation_scheduled", "cancelsAt": "2026-11-12T09:30:00.000Z" }

undoUserPaidMembershipAddonCancellation#

tokiWallet.undoUserPaidMembershipAddonCancellation({ membershipId, addonId })→ Promise<void>

Keeps an add-on whose cancellation is scheduled.

Puts the add-on back on the customer's Shopify subscription, so it renews with the membership again. Nothing is charged now.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • addonIdstringRequired

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.undoUserPaidMembershipAddonCancellation({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  addonId: "b7e4c2a1-9d3f-4e6b-8a5c-2f1e0d9c8b7a",
})

getUserPaidMembershipBox#

tokiWallet.getUserPaidMembershipBox({ membershipId })→ Promise<SubscriptionBox>

Returns the customer's next subscription box: its renewal date, included products and the paid products they added.

With a subscription box, each renewal includes free products from your schedule and any paid products the customer added for it. exclusiveSelection says which included products the customer can pick from, and whether they can change their picks now.

Works for an active recurring subscription to a membership with a subscription box, in the store where the customer bought it.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<SubscriptionBox>
  • enabledtrue
  • nextPaymentAtstring | null

    When the renewal with this box is charged.

  • currencyCodestring

    The subscription's currency, such as USD.

  • nextExclusiveProductsSubscriptionBoxProduct[]

    The included products of the next box: the customer's picks, or the first ones you scheduled.

    9 fields per item
    • productIdstring

      Numeric ID of the Shopify product.

    • variantIdstring

      Numeric ID of the Shopify product variant.

    • titlestring
    • variantTitlestring
    • imageUrlstring | null
    • productUrlstring | null
    • pricenumber

      The variant's regular price, as a decimal amount. Included products are free in the box.

    • currencyCodestring
    • availableboolean

      true while the product is on sale.

  • exclusiveSelectionSubscriptionBoxSelection | null

    What the customer can pick for the next box. null when nothing is scheduled for it.

    6 fields
    • editableboolean

      true while the customer can change their picks. With scheduled billing, that's from the schedule entry's start until its billing date.

    • nextSwapAtstring | null

      With scheduled billing: when the customer can pick next.

    • selectionLimitnumber

      How many included products a box has. Picks have exactly this many.

    • selectedVariantIdsstring[]

      Variant IDs of the current picks.

    • scheduledOptionsSubscriptionBoxProduct[]

      The scheduled products to pick from.

      9 fields per item
      • productIdstring

        Numeric ID of the Shopify product.

      • variantIdstring

        Numeric ID of the Shopify product variant.

      • titlestring
      • variantTitlestring
      • imageUrlstring | null
      • productUrlstring | null
      • pricenumber

        The variant's regular price, as a decimal amount. Included products are free in the box.

      • currencyCodestring
      • availableboolean

        true while the product is on sale.

    • collections{ collectionId: string; title: string }[]

      Your swap collections, with more products to pick from: list them with getUserPaidMembershipBoxCatalog.

  • paidItemsSubscriptionBoxItem[]

    Paid products the customer added to the next box.

    12 fields per item
    • boxItemIdstring

      Pass it to updateUserPaidMembershipBoxItemQuantity and removeUserPaidMembershipBoxItem.

    • contractLineIdstring

      Matches the item's line in getUserPaidMembershipRenewalSummary.

    • productIdstring
    • variantIdstring
    • titlestring
    • variantTitlestring
    • imageUrlstring | null
    • productUrlstring | null
    • quantitynumber
    • lockedPricenumber

      Price per unit, set when the product was added, as a decimal amount.

    • currencyCodestring
    • availableboolean

      true while the product is on sale.

Example
const box = await tokiWallet.getUserPaidMembershipBox({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
})
Result
{
  "enabled": true,
  "nextPaymentAt": "2026-11-01T09:00:00.000Z",
  "currencyCode": "USD",
  "nextExclusiveProducts": [
    {
      "productId": "8901234567890",
      "variantId": "44012345678901",
      "title": "Ethiopia Yirgacheffe",
      "variantTitle": "250 g",
      "imageUrl": "https://cdn.shopify.com/s/files/1/0601/2345/files/yirgacheffe.jpg",
      "productUrl": "https://acmecoffee.com/products/ethiopia-yirgacheffe",
      "price": 18,
      "currencyCode": "USD",
      "available": true
    }
  ],
  "exclusiveSelection": {
    "editable": true,
    "nextSwapAt": null,
    "selectionLimit": 1,
    "selectedVariantIds": ["44012345678901"],
    "scheduledOptions": [
      {
        "productId": "8901234567890",
        "variantId": "44012345678901",
        "title": "Ethiopia Yirgacheffe",
        "variantTitle": "250 g",
        "imageUrl": "https://cdn.shopify.com/s/files/1/0601/2345/files/yirgacheffe.jpg",
        "productUrl": "https://acmecoffee.com/products/ethiopia-yirgacheffe",
        "price": 18,
        "currencyCode": "USD",
        "available": true
      }
    ],
    "collections": [{ "collectionId": "458932617430", "title": "Single origins" }]
  },
  "paidItems": [
    {
      "boxItemId": "6a7b8c9d-0e1f-4a2b-8c3d-4e5f6a7b8c9d",
      "contractLineId": "gid://shopify/SubscriptionLine/1f2e3d4c-5b6a-4789-a0b1-c2d3e4f5a6b7",
      "productId": "8901234567123",
      "variantId": "44012345679012",
      "title": "Ceramic pour-over",
      "variantTitle": "White",
      "imageUrl": "https://cdn.shopify.com/s/files/1/0601/2345/files/pour-over.jpg",
      "productUrl": "https://acmecoffee.com/products/ceramic-pour-over",
      "quantity": 1,
      "lockedPrice": 32,
      "currencyCode": "USD",
      "available": true
    }
  ]
}

getUserPaidMembershipBoxCatalog#

tokiWallet.getUserPaidMembershipBoxCatalog({ membershipId, … })→ Promise<SubscriptionBoxCatalog>

Lists products the customer can add to their next subscription box, or pick as an included product.

Without collectionId, it lists products from your catalog that the customer can add to the box. With collectionId, one of the box's swap collections, it lists that collection's products, to pick included products from.

Each product is listed once per variant, and first counts products. Pass pageInfo.endCursor as after to get the next page. A product added to the box is charged at the customer's market price, its lockedPrice in getUserPaidMembershipBox.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • searchstring

    Words to search for, as in Shopify's product search.

  • firstnumberdefault 20

    Products per page, from 1 to 50.

  • afterstring

    pageInfo.endCursor of the previous page.

  • collectionIdstring

    Numeric ID of one of the box's swap collections.

Returns

Promise<SubscriptionBoxCatalog>
  • productsSubscriptionBoxCatalogProduct[]
    8 fields per item
    • productIdstring

      Numeric ID of the Shopify product.

    • variantIdstring

      Numeric ID of the Shopify product variant.

    • titlestring
    • variantTitlestring
    • imageUrlstring | null
    • productUrlstring | null
    • pricenumber

      The variant's regular price in your store's currency, as a decimal amount.

    • currencyCodestring
  • pageInfoobject
    2 fields
    • hasNextPageboolean
    • endCursorstring | null

      Pass it as after for the next page.

Example
const { products, pageInfo } =
  await tokiWallet.getUserPaidMembershipBoxCatalog({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    search: "pour-over",
  })
Result
{
  "products": [
    {
      "productId": "8901234567123",
      "variantId": "44012345679012",
      "title": "Ceramic pour-over",
      "variantTitle": "White",
      "imageUrl": "https://cdn.shopify.com/s/files/1/0601/2345/files/pour-over.jpg",
      "productUrl": "https://acmecoffee.com/products/ceramic-pour-over",
      "price": 32,
      "currencyCode": "USD"
    }
  ],
  "pageInfo": { "hasNextPage": false, "endCursor": "eyJsYXN0X2lkIjo4OTAxMjM0NTY3MTIzfQ==" }
}

updateUserPaidMembershipBoxExclusiveSelection#

tokiWallet.updateUserPaidMembershipBoxExclusiveSelection({ membershipId, variantIds })→ Promise<void>

Sets the included products of the customer's next subscription box.

Pass exactly selectionLimit different variants, from scheduledOptions or from the box's swap collections (see getUserPaidMembershipBoxCatalog). Toki saves the picks for the next renewal and puts them on the customer's Shopify subscription at 100% off. Picks can change while editable is true.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • variantIdsstring[]Required

    Numeric IDs of the Shopify product variants.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.updateUserPaidMembershipBoxExclusiveSelection(
  {
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    variantIds: ["44012345678902"],
  },
)

addUserPaidMembershipBoxItem#

tokiWallet.addUserPaidMembershipBoxItem({ membershipId, variantId, quantity })→ Promise<void>

Adds a paid product to the customer's next subscription box.

Adds the product to the customer's Shopify subscription, charged once with the next renewal at the customer's market price, its lockedPrice. Nothing is charged now. If the variant is already in the box, this sets its quantity.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • variantIdstringRequired

    Numeric ID of the Shopify product variant, such as "44012345679012".

  • quantitynumberRequired

    From 1 to 99.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.addUserPaidMembershipBoxItem({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  variantId: "44012345679012",
  quantity: 1,
})

updateUserPaidMembershipBoxItemQuantity#

tokiWallet.updateUserPaidMembershipBoxItemQuantity({ membershipId, boxItemId, quantity })→ Promise<void>

Changes the quantity of a paid product in the customer's next subscription box.

Updates the product on the customer's Shopify subscription, at its lockedPrice.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • boxItemIdstringRequired

    From paidItems in getUserPaidMembershipBox.

  • quantitynumberRequired

    From 1 to 99.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.updateUserPaidMembershipBoxItemQuantity({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  boxItemId: "6a7b8c9d-0e1f-4a2b-8c3d-4e5f6a7b8c9d",
  quantity: 2,
})

removeUserPaidMembershipBoxItem#

tokiWallet.removeUserPaidMembershipBoxItem({ membershipId, boxItemId })→ Promise<void>

Removes a paid product from the customer's next subscription box.

Takes the product off the customer's Shopify subscription, so it isn't charged with the renewal.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • boxItemIdstringRequired

    From paidItems in getUserPaidMembershipBox.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.removeUserPaidMembershipBoxItem({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  boxItemId: "6a7b8c9d-0e1f-4a2b-8c3d-4e5f6a7b8c9d",
})

getUserPaidMembershipRenewalSummary#

tokiWallet.getUserPaidMembershipRenewalSummary({ membershipId })→ Promise<{ renewalSummary: RenewalSummary | null }>

Returns what the customer's next subscription box renewal is projected to cost, line by line.

Shopify's projection of the next payment: the membership, add-ons and paid box products, with discounts, shipping and taxes. Included products are free and aren't listed. Shopify sets the final amount when it charges the renewal. For subscription boxes.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<{ renewalSummary: RenewalSummary | null }>
  • renewalSummaryRenewalSummary | null

    null when there's no projection to show yet.

    10 fields
    • currencyCodestring

      The subscription's currency, such as USD.

    • linesRenewalLine[]
      7 fields per item
      • contractLineIdstring

        Matches contractLineId of a paid product in getUserPaidMembershipBox.

      • kind"membership" | "addon" | "product"

        product is a paid box product.

      • titlestring
      • quantitynumber
      • unitPricenumber
      • subtotalnumber

        unitPrice times quantity.

      • totalnumber

        subtotal after discounts.

    • subtotalnumber

      The lines before discounts.

    • discountsnumber

      All discounts on the lines.

    • discountBreakdown{ title: string; amount: number }[]

      The discounts by title, such as a discount code or a retention offer.

    • discountCodes{ id: string; code: string }[]

      Discount codes on the subscription. Remove one with removeDiscountFromMembership and its id.

    • shipping{ originalAmount: number; amount: number; discountTitles?: string[] } | null

      Shipping before and after shipping discounts. null when the subscription has no delivery method.

    • shippingPendingboolean

      true when the renewal's shipping is priced when it's charged.

    • taxesnumberOptional
    • totalnumber

      What the renewal is projected to cost, including shipping and taxes when they're present.

Example
const { renewalSummary } =
  await tokiWallet.getUserPaidMembershipRenewalSummary({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  })
Result
{
  "renewalSummary": {
    "currencyCode": "USD",
    "lines": [
      {
        "contractLineId": "gid://shopify/SubscriptionLine/9a8b7c6d-5e4f-4a3b-b2c1-d0e9f8a7b6c5",
        "kind": "membership",
        "title": "Coffee Club",
        "quantity": 1,
        "unitPrice": 29,
        "subtotal": 29,
        "total": 26.1
      }
    ],
    "subtotal": 61,
    "discounts": 2.9,
    "discountBreakdown": [{ "title": "WELCOME10", "amount": 2.9 }],
    "discountCodes": [
      { "id": "gid://shopify/SubscriptionManualDiscount/4f1c2a3b-9d8e-4c7b-a6f5-e4d3c2b1a090", "code": "WELCOME10" }
    ],
    "shipping": { "originalAmount": 5, "amount": 5 },
    "shippingPending": false,
    "taxes": 0,
    "total": 63.1
  }
}

applyDiscountToCurrentMembership#

tokiWallet.applyDiscountToCurrentMembership({ discountCode, membershipId? })→ Promise<{ success: true } | { error: string }>

Applies a discount code to the customer's subscription renewals.

Adds the discount code to the customer's Shopify subscription, so upcoming renewals get the discount the code gives. Without membershipId, it goes on the customer's highest active recurring subscription in your membership order.

When the code doesn't apply, the result has an error message to show the customer, such as This discount code was not found. Check the code and try again.

Options

one object
  • discountCodestringRequired

    The code, up to 255 characters.

  • membershipIdstring

    The subscription to apply it to, by membershipId.

Returns

Promise<{ success: true } | { error: string }>

{ success: true } once it's done, or { error } with a message to show the customer.

  • successtrueOptional
  • errorstringOptional

    Why it didn't go through, ready to show.

Example
const result =
  await tokiWallet.applyDiscountToCurrentMembership({
    membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
    discountCode: "WELCOME10",
  })
if ("error" in result) showMessage(result.error)
Result
{
  "success": true
}

removeDiscountFromMembership#

tokiWallet.removeDiscountFromMembership({ membershipId, discountId })→ Promise<{ success: true } | { error: string }>

Removes a discount code from the customer's subscription.

Takes the code off the customer's Shopify subscription, so upcoming renewals are charged without it. Get discountId from discountCodes in getUserPaidMembershipRenewalSummary.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

  • discountIdstringRequired

    id from discountCodes in getUserPaidMembershipRenewalSummary.

Returns

Promise<{ success: true } | { error: string }>

{ success: true } once it's done, or { error } with a message to show the customer.

  • successtrueOptional
  • errorstringOptional

    Why it didn't go through, ready to show.

Example
await tokiWallet.removeDiscountFromMembership({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
  discountId:
    "gid://shopify/SubscriptionManualDiscount/4f1c2a3b-9d8e-4c7b-a6f5-e4d3c2b1a090",
})
Result
{
  "success": true
}

updateUserPaymentMethod#

tokiWallet.updateUserPaymentMethod({ membershipId })→ Promise<{ type: "link"; url: string } | { type: "email" }>

Lets the customer update the payment method their subscription is charged to.

Asks Shopify for a page where the customer updates the payment method of their subscription. With type: "link", open url. With type: "email", Shopify has emailed the customer a link: tell them to check their inbox.

Options

one object
  • membershipIdstringRequired

    The paid membership the customer subscribes to, by membershipId.

Returns

Promise<{ type: "link"; url: string } | { type: "email" }>
  • type"link" | "email"
  • urlstringOptional

    With link: the page to open.

Example
const update = await tokiWallet.updateUserPaymentMethod({
  membershipId: "3f6c1b8e-6a1d-4c9e-9f5a-2b7d8e4a1c90",
})
if (update.type === "link") window.open(update.url)
Result
{ "type": "email" }