SUBSCRIPTION_PLAN_VARIATION with intro month discount causing error

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();
}

It looks like there’s no pricing.type on the second phase. The error isn’t a very descriptive error. I’ve reached out to the team about this. :slightly_smiling_face:

{
  "idempotency_key": "{{$guid}}",
  "object": {
    "type": "SUBSCRIPTION_PLAN_VARIATION",
    "id": "#DickinsonFITNutritionHalfOffFirstMonth160",
    "subscription_plan_variation_data": {
      "name": "DickinsonFIT Nutrition Plan Half Off First Month 160",
      "phases": [
        {
          "cadence": "MONTHLY",
          "periods": 1,
          "ordinal": 0,
          "pricing": {
            "type": "STATIC",
            "price_money": {
              "amount": 8000,
              "currency": "USD"
            }
          }
        },
        {
          "cadence": "MONTHLY",
          "ordinal": 1,
          "pricing": {
            "type": "STATIC",
            "price_money": {
              "amount": 16000,
              "currency": "USD"
            }
          }
        }
      ],
      "subscription_plan_id": "J27BT5MGHLJRIJIWRAGIIXQO"
    }
  }
}

That sounds logical, however if I set pricing type to STATIC for phase[1] I get the same result.

$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->setType(‘STATIC’);
$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(‘IYBMOI3Z6LUDDO6SYAL3ADQE’);

$object = new \Square\Models\CatalogObject(‘#DickinsonFITNutritionHalfOffFirstMonth160’);
$object->setType(‘SUBSCRIPTION_PLAN_VARIATION’);
$object->setSubscriptionPlanVariationData($subscription_plan_variation_data);

$body = new \Square\Models\UpsertCatalogObjectRequest(‘af356727-ce04-4158-853c-61ce34936f99’, $object);

$api_response = $client->getCatalogApi()->upsertCatalogObject($body);

if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}

returns

{
  "errors": [
    {
      "category": "INVALID_REQUEST_ERROR",
      "code": "INVALID_VALUE",
      "detail": "Invalid object: Invalid Object with Id: #WDK6P6IWMLTSLDWL6MXH6HAB\n[merchant_token=H82A8258P8YWG] subscription phase requires period unless it is last phase."
    }
  ]
}

Is your first phase ordinal indexed from 0. The second phase should be set to 1 but the first needs to be 0. :slightly_smiling_face:

AH! Good work, thanks! I glazed over that and mixed it up with period. All set thanks for your help!

Hi Bryan, hoping maybe you can answer another question for me as you were so helpful before!

Using the API I created six subscriptions - I believe they were done so using the same process but three have the following:
“price_override_money”: {
“amount”: 16000,
“currency”: “USD”
},

All six subscriptions use a plan variation with a 5 month $100/mo intro, then $160 indefinitely after. But somehow three users have this override and several others do not.

Is there a way to remove the price_override_money on those three subscriptions?

Do you know of some way or reason the override would be added? I’m using pretty simple PHP API calls right form the Explorer:

$body = new \Square\Models\CreateSubscriptionRequest(config(‘app.square_location_id’), $this->square_customer_id);
$body->setIdempotencyKey(uniqid());
$body->setPlanVariationId($program->square_id);
$body->setStartDate(\Helper::currentDateSql());
$body->setCardId($card->square_id);
$body->setTimezone(‘America/Los_Angeles’);

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

Dylan
(DickinsonFIT.com)

Turns out Jason (business owner) changed the price then changed it back… so that’s how the override was set. Is there a way to remove the override so it reverts back to the multiphase plan variation?

Dylan

Yeah, you can call UpdateSubscription to remove the price override. :slightly_smiling_face: