Create Subscription Plan and create a payment link through the API

I’m struggling to find up to date API documentation for the flow:

  • create subscription plan
  • create payment link

I tried the steps on this page but I get the error: ‘Invalid object XXXXXXXXXXXXXXX: incorrect object type SUBSCRIPTION_PLAN.’

I’m assuming the API changed at some point and maybe the documentation hasn’t been updated. Really frustrating!

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

https://developer.squareup.com/docs/app-marketplace/requirements/subscriptions-api

Additional Documentation

Guidelines and Limitations
Get Started
Square Developer Documentation

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Are you passing in the subscription_variation_id when creating a subscription with the payment links? :slightly_smiling_face:

I’m following steps 1 and 2 in this guide https://developer.squareup.com/docs/checkout-api/subscription-plan-checkout carrying out each step in the API explorer. I haven’t made any changes to the sample payloads included in each step (other than changing the location ID and inserting the subscription plan id from the response to step 1). I don’t see any mention in the documentation of subscription_variation_id.

Is there an up to date documentation link I should be following instead?

Thanks!

I managed to get a step forward following this newer documentation marked as beta release:

The key was to add subscription_plan_variations to my SUBSCRIPTION_PLAN object. I then needed to use the subscription_variation_id in the Create Payment Link API Post. Confusingly the field is named subscription_plan_id so watch out for that one!

I previewed the payment link but noticed there’s nothing to indicate to the user that it’s a monthly payment. Am I doing something wrong? I’ve tried using the quick pay and order sections but get the same result.

Here’s the body for my batch upsert for the catalog objects:

“batches” : [
{
“objects”: [
{
“id”: “#1”,
“type”: “ITEM”,
“item_data”: {
“product_type”: “DIGITAL”,
“name”: “My Subscription”,
“variations”: [
{
“id”: “#var”,
“type”: “ITEM_VARIATION”,
“item_variation_data”: {
“name”: “Subscription”,
“price_money”: {
“amount”: 1000,
“currency”: “USD”
}
}
}
]
}
},
{
“type”: “SUBSCRIPTION_PLAN”,
“id”: “#plan”,
“subscription_plan_data”: {
“name”: “My Subscription”,
“all_items”: False,
“subscription_plan_variations”: [
{
“id”: “#2”,
“type”: “SUBSCRIPTION_PLAN_VARIATION”,
“subscription_plan_variation_data”: {
“name”: “Starter”,
“phases”: [
{
“cadence”: “DAILY”,
“ordinal”: 0,
“periods”: 14,
“pricing”: {
“type”: “STATIC”,
“price”: {
“amount”: 0,
“currency”: “USD”
}
}
},
{
“cadence”: “MONTHLY”,
“ordinal”: 1,
“pricing”: {
“type”: “STATIC”,
“price”: {
“amount”: 2000,
“currency”: “USD”
}
}
}
]
}
}]
}
}
]
}

Here’s the body for my create payment link call:

{
“idempotency_key”: str(uuid4()),
“checkout_options”: {
“subscription_plan_id”: subscription_variation_id,
“redirect_url”: ‘https://my.website’,
},
“order”: {
“location_id”: “XXXXXXX”,
“line_items”: [
{
“quantity”: ‘1’,
“catalog_object_id” : catalog_object_variation_id,

                   },
               ],
           }
    }

For context here’s the flow I’m trying to create:

  • List of subscription plans displayed to the user (Catalog API - List Catalog types = ‘SUBSCRIPTION_PLAN’)
  • User selects their chosen plan and clicks Subscribe (Checkout API - Create Payment Link)
  • User redirected to payment link
  • User submits credit card info
  • User redirected to thank you page (My API calls Subscription API - Create Subscription)

My biggest area of confusion is the role the order plays and whether I need a catalog item or not.

I’ve failed to find any current documentation that walks through the necessary steps. It doesn’t help that the Subscription API seems to have had a major overhaul recently and much of the documentation isn’t updated.