Create subscription for my member in PHP

Hello,
I have a question about creating subscription sales via PHP.

I created a subscription plan today on my dashboard (Sandbox). Then I created an item and then added to my subscription plan. Now when I go to my subscription plan, I see my item that has a price. ex. $10.

So i get the subscription_plan id with this API in the Explorer : GET /v2/catalog/list - Square API Explorer

Now in PHP, I want to allow members to subscribe to this plan.

Here is my code:

// the id of subscription_plan i want.. here 6 months
$planVariationId="EHH55BZEMEPQNC6E2KMDBIPU"; 

$body = new \Square\Models\CreateSubscriptionRequest($locationId, $sandboxToken);
$body->setIdempotencyKey($idempotencyKey);
$body->setPlanVariationId($planVariationId);
$body->setCardId($result->getCard()->getId());
$body->setCustomerId($customerId);

$api_response = $client->getSubscriptionsApi()->createSubscription($body);

if ($api_response->isSuccess()) {
    $result = $api_response->getResult();
    $d["ok"]="ok";
} else {
    $errors = $api_response->getErrors();
    var_dump($errors);
}

But i receive this message :
Phases with RELATIVE pricing type must have phases on the subscription

I see in a forum post : here

that since 2023-06-08 that when creating plan and item on dashboard, it is RELATIVE instead of STATIC.

And mention that if we want a STATIC price, we need touse the APIs in EXPLORER for example…
What I tried but I don’t understand all the options that are offered to me here: POST /v2/catalog/object - Square API Explorer

In fact I don’t have any variation…
I only have 3 possible packages:

For example :
VIP 1 month - $10 (recurring every 1 month)
VIP 3 months $20 (recurring every 3 months)
VIP 6 months $30 (recurring every 6 months)

So in the API in EXPLORER, it asks me for:
subscription_plan_data and
subscription_plan_variations
and subscription_plan_variations_data…

So i am very lost ! Is it possible to help me please?
Should i create again all plan in API ?
Or i just only need to change somethng in my PHP code ?

Thanks so much !
Pascal

Ideally if your going to create subscriptions with the Subscriptions API you should build them with the API. Our Subscriptions Documentation will walk you through creating the plan, variation, and subscription. :slightly_smiling_face:

Hello Bryan,

Ok thanks i will try it soon !
Have a great weekend !

Hi @Bryan-Square ,
It works ! thanks !

But i have 1 more small question :

In production mode, is there a way to don’t send receipt to users after a person subscribes to a monthly plan ? I’m asking it because i will send one by myself… Because I have members who speak French, Spanish and English. And the receipe you send is on my dashboard language ! I cannot choose a language for a receipt … i think !

Thanks so much !
Pascal

That’s great that it’s working!

Currently there isn’t a way to disable the invoices that Square automatically sends when a customer subscribes. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face:

Thanks so much Bryan !
Have a great day
Pascal