Subscription creatpayment link issue

I have created plan and got plan id from response but when i passing that planid in createpaymentlink request that time it is showing something like below.

{
“errors”: [
{
“category”: “INVALID_REQUEST_ERROR”,
“code”: “INVALID_VALUE”,
“detail”: “Invalid object OI6R2HGECR5ETQNXAMI62UHL: incorrect object type SUBSCRIPTION_PLAN.”,
“field”: “subscription_plan_id”
}
]
}

Create Plan request as below

curl https://connect.squareupsandbox.com/v2/catalog/object
-X POST
-H ‘Square-Version: 2023-09-25’
-H ‘Authorization: Bearer ACCESS_TOKEN’
-H ‘Content-Type: application/json’
-d ‘{
“idempotency_key”: “f9ab22ee-5046-4e39-9963-59a02ba875e3”,
“object”: {
“type”: “SUBSCRIPTION_PLAN”,
“id”: “#1990”,
“subscription_plan_data”: {
“name”: “testetstet”,
“phases”: [
{
“cadence”: “MONTHLY”,
“recurring_price_money”: {
“amount”: 1500,
“currency”: “USD”
}
},
{
“cadence”: “MONTHLY”,
“recurring_price_money”: {
“amount”: 1500,
“currency”: “USD”
}
}
],
“all_items”: true
}
}
}’

Create Plan response as below

{
“catalog_object”: {
“type”: “SUBSCRIPTION_PLAN”,
“id”: “OI6R2HGECR5ETQNXAMI62UHL”,
“updated_at”: “2023-10-02T09:29:42.987Z”,
“created_at”: “2023-10-02T09:29:42.987Z”,
“version”: 1696238982987,
“is_deleted”: false,
“present_at_all_locations”: true,
“subscription_plan_data”: {
“name”: “testetstet”,
“all_items”: true
}
},
“id_mappings”: [
{
“client_object_id”: “#189”,
“object_id”: “OI6R2HGECR5ETQNXAMI62UHL”
}
]
}

Createpayment link request as below

curl https://connect.squareupsandbox.com/v2/online-checkout/payment-links
-X POST
-H ‘Square-Version: 2023-09-25’
-H ‘Authorization: Bearer ACCESS_TOKEN’
-H ‘Content-Type: application/json’
-d ‘{
“idempotency_key”: “57291bd7-dce4-4617-ba9a-944ae4d7cd08”,
“quick_pay”: {
“name”: “Gym membership fees”,
“price_money”: {
“amount”: 1500,
“currency”: “USD”
},
“location_id”: “LTBWC2JWZ5WV6”
},
“checkout_options”: {
“subscription_plan_id”: “OI6R2HGECR5ETQNXAMI62UHL”
}
}’

Createpaymentlink response as below

{
“errors”: [
{
“category”: “INVALID_REQUEST_ERROR”,
“code”: “INVALID_VALUE”,
“detail”: “Invalid object OI6R2HGECR5ETQNXAMI62UHL: incorrect object type SUBSCRIPTION_PLAN.”,
“field”: “subscription_plan_id”
}
]
}

Api log request as below

{
“idempotency_key”: “57291bd7-dce4-4617-ba9a-944ae4d7cd08”,
“quick_pay”: {
“name”: “Gym membership fees”,
“price_money”: {
“amount”: 1500,
“currency”: “USD”
},
“location_id”: “LTBWC2JWZ5WV6”
},
“checkout_options”: {
“subscription_plan_id”: “OI6R2HGECR5ETQNXAMI62UHL”
}
}

Your getting this error because of your Square API version. The subscription object shape has changed and any version newer then 2023-06-08 takes the new model. If you set the version of one older then 2023-06-08 it will work as expected. :slightly_smiling_face:

1 Like

So if i want to proceed with the latest version then where/what is should change?

image

Still not working. Same response getting(invalid object type).

I took a look at the API Logs and the API version is being passed in the header which is overriding the API version set in the application.


:slightly_smiling_face:

Hi @Bryan-Square .

I got the same problem in the API Explorer.
I create a subscription plan using Catalog → upsertCatalogObject → SUBSCRIPTION_PLAN (And i fill all needed information). The subscription plan is well created and i can retreive it.

But when I try to create a Payment link using Checkout → Create Payment Link and I add the subscription_plan_id, i got the same error :

 "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_VALUE",
      "detail": "Invalid object `X55Q3YURTQVDVWCLZM6S3CXF`: incorrect object type `SUBSCRIPTION_PLAN`.",
      "field": "subscription_plan_id"

I use the latest version in teh API Explorer.

How to solve it ?
Thanks in advance

You’ll want to pass in the subscription_plan_variation_id when creating the link for the subscription. :slightly_smiling_face: