Quantcast
Channel: Square Developer Forums - Latest topics
Viewing all articles
Browse latest Browse all 1326

Create subscription for my member in PHP

$
0
0

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

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1326

Trending Articles