I’m trying to clean up my subscriptions so that they’re all variations nested under two primary subscription plans - as I have two ‘products’, a fitness plan and a nutrition plan, and everything is a pricing variation of those two.
I have easily created the main subscription plan and a number of variations linked to that plan, but when I try to create a variation with an introductory price (half off the first month), I get this error:
"category": "INVALID_REQUEST_ERROR",
"code": "INVALID_VALUE",
"detail": "Invalid object: Invalid Object with Id: #7BRU56LNOMEGH5VYBTXSLDRR\n[merchant_token=H82A8258P8YWG] subscription phase requires period unless it is last phase."
}
Im using the API Explorer v 2023-09-25. I have two phases, phase[0] which has a period of 1 (price 8000 and cadence MONTHLY) and phase[1] is MONTHLY, 16000 and period is left blank, to indicate no ending. The error seems to suggest I have an additional phase, but I only have those two and was careful not to use Subscription Phase Object. I’m not sure why I continue to get this error, subscription phase IS the last phase, which has no period.
Here’s the PHP request:
$price_money = new \Square\Models\Money();
$price_money->setAmount(8000);
$price_money->setCurrency('USD');
$pricing = new \Square\Models\SubscriptionPricing();
$pricing->setType('STATIC');
$pricing->setPriceMoney($price_money);
$subscription_phase = new \Square\Models\SubscriptionPhase();
$subscription_phase->setCadence('MONTHLY');
$subscription_phase->setPeriods(1);
$subscription_phase->setOrdinal(1);
$subscription_phase->setPricing($pricing);
$price_money1 = new \Square\Models\Money();
$price_money1->setAmount(16000);
$price_money1->setCurrency('USD');
$pricing1 = new \Square\Models\SubscriptionPricing();
$pricing1->setPriceMoney($price_money1);
$subscription_phase1 = new \Square\Models\SubscriptionPhase();
$subscription_phase1->setCadence('MONTHLY');
$subscription_phase1->setOrdinal(1);
$subscription_phase1->setPricing($pricing1);
$phases = [$subscription_phase, $subscription_phase1];
$subscription_plan_variation_data = new \Square\Models\CatalogSubscriptionPlanVariation('DickinsonFIT Nutrition Plan Half Off First Month 160', $phases);
$subscription_plan_variation_data->setSubscriptionPlanId('IYBMOI3Z6LUDDO6SYAXXXXX');
$object = new \Square\Models\CatalogObject('#DickinsonFITNutritionHalfOffFirstMonth160');
$object->setType('SUBSCRIPTION_PLAN_VARIATION');
$object->setSubscriptionPlanVariationData($subscription_plan_variation_data);
$body = new \Square\Models\UpsertCatalogObjectRequest('050774d0-fa41-4ae7-a1c2-c98fXXXXXX', $object);
$api_response = $client->getCatalogApi()->upsertCatalogObject($body);
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}