Error creation catalogObject (subscription)

Hello,

i am trying to create subscription from API but i am getting this error.

"errors":[{"category":"INVALID_REQUEST_ERROR","code":"MISSING_REQUIRED_PARAMETER","detail":"Invalid object `#ABONNEMENT`: [merchant_token=ML0NMDX8JSNVV] Attribute with definition SQ_COGS_SPID required.."}]}

This is my code

        $price_money = new \Square\Models\Money();
        $price_money->setAmount(0);
        $price_money->setCurrency('EUR');

        $pricing = new \Square\Models\SubscriptionPricing();
        $pricing->setType('STATIC');
        $pricing->setPriceMoney($price_money);

        $subscription_trial = new \Square\Models\SubscriptionPhase('WEEKLY');
        $subscription_trial->setCadence('WEEKLY');
        $subscription_trial->setPeriods(1);
        $subscription_trial->setOrdinal(0);
        $subscription_trial->setPricing($pricing);

        $price_money_full = new \Square\Models\Money();
        $price_money_full->setAmount(5999);
        $price_money_full->setCurrency('EUR');

        $pricingFull = new \Square\Models\SubscriptionPricing();
        $pricingFull->setPriceMoney($price_money_full);

        $subscription_phase = new \Square\Models\SubscriptionPhase('MONTHLY');
        $subscription_phase->setCadence('MONTHLY');
        $subscription_phase->setOrdinal(1);
        $subscription_phase->setPricing($pricingFull);

        $phases = [$subscription_trial, $subscription_phase];
        $subscription_plan_variation_data = new \Square\Models\CatalogSubscriptionPlanVariation("abonnement avec pƩriode d'essai", $phases);
        // $subscription_plan_variation_data->setSubscriptionPlanId('IYBMOI3Z6LUDDO6SYAXXXXX');

        $object = new \Square\Models\CatalogObject('Abonnement', '#ABONNEMENT_1');
        $object->setType('SUBSCRIPTION_PLAN_VARIATION');
        $object->setSubscriptionPlanVariationData($subscription_plan_variation_data);

        $body = new \Square\Models\UpsertCatalogObjectRequest(Str::uuid()->toString(), $object);
        $api_response = $this->client->getCatalogApi()->upsertCatalogObject($body);

        dd($subscription_plan_variation_data, $object, $api_response);

Any idea why isnā€™t working ?
Am I missing something ?

Thanks,
Best regards

In your request there isnā€™t a pricing.type in the MONTHLY phase. Youā€™ll need to set it as either STATIC or RELATIVE. :slightly_smiling_face:

@Bryan-Square
I have the same issue but Iā€™m including pricing type, Iā€™m using the API Explorer. Here is my data:

"object": {
      "id": "#1",
      "type": "SUBSCRIPTION_PLAN_VARIATION",
      "subscription_plan_variation_data": {
        "phases": [
          {
            "cadence": "MONTHLY",
            "pricing": {
              "type": "STATIC",
              "price_money": {
                "amount": 1,
                "currency": "USD"
              }
            },
            "ordinal": 0
          }
        ],
        "name": "Plan Testing #1"
      }
    },
    "idempotency_key": "1c4ec513-2e66-44a7-b3e5-c50a12663c2d"
  }'

@amity did you find a solution yet?

Hello,

I just add
$pricingFull->setType('STATIC');
and I have same errorā€¦

@Gustavol Noā€¦ i am looking for answer ! Lets keep in touch

I followed all steps here : Subscription Plans and Variations (squareup.com)
and still not working

API Explorer not working too

1 Like

It looks like the request is missing the subscription_plan_id. For example:

{
    "idempotency_key": "{{$guid}}",
    "object": {
      "type": "SUBSCRIPTION_PLAN_VARIATION",
      "id": "#1",
      "subscription_plan_variation_data": {
        "name": "Plan Testing #1",
        "phases": [
          {
            "cadence": "MONTHLY",
            "ordinal": 0,
            "pricing": {
              "type": "STATIC",
              "price": {
                "amount": 100,
                "currency": "USD"
              }
            }
          }
        ],
        "subscription_plan_id": "Y2Y7AS6N3A7DCBW3WU55TIOJ"
      }
    }
  }

:slightly_smiling_face:

but when i am reading the doc :
/**
* Sets Subscription Plan Id.
* The id of the subscription plan, if there is one.
*
* @maps subscription_plan_id
*/

so where should i guess the ID ?

Because when i am trying to put ID i have error


{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"INVALID_VALUE","detail":"[merchant_token=ML0NMDX8JSNVV] Object `#WEECALLER` of type SUBSCRIPTION_PLAN_VARIATION references an object with token `WEECALLER123456789`, which does not exist. Expected an object of type SUBSCRIPTION_PLAN.","field":"subscription_plan_id"}]}

how to fix ?? 3 days i am wasting my time & money.

Did you first create the subscription plan? In the documentation you first create the plan to generate the subscription_plan_id. Then you pass it in when creating the variation. :slightly_smiling_face:

Please, I put all my code in my first message, could you review it ?

Your doc isnā€™t complete, many things are missing isnā€™t clear enough.
Somewhere I will have something and somewhere else another thing ā€¦ā€¦

Please provide me full good answer :muscle:t2:

@Bryan-Square I get what you say. We need to create a Subscription Plan before trying to create a Subscription Plan Variation in order to create a Subscription.

So Iā€™m trying to create a Subscription Plan as described in the docsā€¦ but then I found I need to send this array ā€œeligible_category_idsā€, and if I left it in blank because I donā€™t have any, it fails.

Note: It failed with all_items as true (because I wanted to make all items subscribable under this Plan), so I tried again but with all_items as false and it worked. I wasnā€™t convinced anyways because I wanted to make all the items subscribable, so I tried again with all_items as true and it worked this timeā€¦

This flow looks inconsistent and I canā€™t trust 100% on it, but Iā€™ll take it since Stripe is not working for iOS on my app and I need to make subscriptions purchases available on my app.

@amity Try creating first a Plan Subscription and then create a Plan Variation.

@Bryan-Square Thereā€™s still an issue. API wonā€™t let me create a Plan Variation that costs $1, it says it must be greater than $100. How is it possible I cannot reate a Plan Variation less than $100? am I missing something?

What does the request to create the subscription look like. I just ran this and it was successful:

{
    "idempotency_key": "{{$guid}}",
    "object": {
      "type": "SUBSCRIPTION_PLAN",
      "id": "#1",
      "subscription_plan_data": {
        "name": "Coffee Subscription",
        "all_items": true
      }
    }
  }

Also the 100 is $1.00. The amount is in the smallest denomination which is cents. :slightly_smiling_face:

Subscription Plans are working fine, the first time it fails idk why.

And thanks so much for the price clarification, totally my bad.

Iā€™ll keep you posted in case something is wrong or it succeeds.

Thanks for help, i created my subscription, i will try full process now.

But I still have one issue about card_id, i am using basic payment in JS.
How should I retrieve card_id ? I dont see in response when user submit credit card ā€¦

I am trying to link card object to my customer, but during creation card i have this
{ā€œerrorsā€:[{ā€œcategoryā€:ā€œINVALID_REQUEST_ERRORā€,ā€œcodeā€:ā€œINVALID_CARD_DATAā€,ā€œdetailā€:ā€œInvalid card data.ā€,ā€œfieldā€:ā€œsource_idā€}]}
I am following POST /v2/cards - Square API Reference (squareup.com)

   $body = new \Square\Models\CreateCardRequest(
                Str::uuid()->toString(),
                $data['sourceId'],
                $card
   );

$data[ā€˜sourceIdā€™] is coming from data processPayment request (from front side)
Whatā€™s wrong ?

Are you creating the token from the Web Payments SDK and passing it in as the source_id for the CreateCard call? :slightly_smiling_face:

Yes i am doing this !

Is this in sandbox or production? :slightly_smiling_face:

Still in sandbox ! i am tryingā€¦

image
fist line in my function controller POST
I am retrieving sourceId and i use it to put it in creation card

Are you using our test value cnon:card-nonce-ok? :slightly_smiling_face:

Mmh no, why should i do that ?
I am using test card yes, so i am sending sourceId of this test card.
I want to simulate full process subscription to put this in production for my website.

Our test values are mainly for generating tokens with the Web Payments SDK and walking through various buyer verification scenarios. They donā€™t work well when being saved on file and charged. If thatā€™s the scenario you need to test we recommend using cnon:card-nonce-ok. :slightly_smiling_face: