#msmello

1 messages · Page 1 of 1 (latest)

frail valeBOT
loud smelt
#

What are 'children' and 'organisation' in this context?

#

I suspect this is something you'll need to account for and track yourself in your own logic

#

We can't automatically apply discounts to other Subscriptions, you'd need to apply the coupon when creating it according to your organisation/children logic

cyan inlet
#

I am creating a Saas, so organisation is the entity created by the user and he can adds a new member, every time.

loud smelt
#

And they each have their own unique Subscription?

cyan inlet
#

Each organization has its subscription and after that, I am updating the quantity of the subscription. (as far I understood)

  const subscription = await stripe.subscriptions.retrieve(subscriptionId);

  // As we add only 1 line item during the subscription creation
  // we can safely select the first in the array
  //
  // NB: if you customize the line items, you have to find a different way
  // to select the correct line item!
  const lineItem = subscription.items.data[0];

  if (!lineItem) {
    throw new Error(
      `Subscription with ID ${subscriptionId} has no line items?`
    );
  }

  const currentQuantity = lineItem.quantity ?? 0;
  const quantity = currentQuantity + 1;
  console.log({ quantity, currentQuantity, lineItem })

  return stripe.subscriptionItems.update(lineItem.id, {
    quantity,
  });
#

My knowledge of Stripe is really limited, so if I am skipping something simple, sorry about that.

loud smelt
#

Ok, and you want to apply the coupon during this quantity update?

#

Not at all, just trying to understand what it is you're doing and whether we can support it!

#

Do you have a sub_xxx ID I can look at?

#

Or can you describe what happens to the discount/coupon on the Subscription when you increase the quantity of the item?

cyan inlet
#

I can send you the sub. but where can I get this?

What is happening now is that, the discount is not being applied to the new members.

#

The sub id I get it, sorry, I just noticed what you asked for

loud smelt
#

From the Dashboard, or in the response of your API calls

cyan inlet
#

sub_1MrRk3HZABaXHq0Tx9K8x7E9

#

In 10 minutes I will need to get a train but I will be back in 40 min +-.

#

I just sent you the checkout with the discount applied and then the quantities that were added to the subscription

loud smelt
#

Yeah your update call:

return stripe.subscriptionItems.update(lineItem.id, {
    quantity,
  });
#

is unsetting the existing discount/coupon

cyan inlet
#

But from the typescript, does not exist this field (info)

loud smelt
#

And you can re-apply the coupon in that API call

cyan inlet
#

Ok

#

This is one demo response from Stripe.

{
  "id": "sub_1Mrfzq2x6R10KRrh349s11jt",
  "object": "subscription",
...
  "collection_method": "charge_automatically",
  "created": 1680261594,
  "currency": "gbp",
 ...
  "discount": null,
  "ended_at": null,
  "items": {
    "object": "list",
    "data": [
      {
        "id": "si_Ncvr4usKNmCnHj",
        "object": "subscription_item",
        "billing_thresholds": null,
        "created": 1680261594,
        "metadata": {},
        "price": {
          "id": "price_1MijJ52x6R10KRrhnLh3Ao1g",
          "object": "price",
          "active": true,
          "billing_scheme": "per_unit",
          "created": 1678129367,
          "currency": "gbp",
          "custom_unit_amount": null,
          "livemode": false,
          "lookup_key": null,
          "metadata": {},
          "nickname": null,
          "product": "prod_NTggG2HqyxKR4y",
          "recurring": {
            "aggregate_usage": null,
            "interval": "month",
            "interval_count": 1,
            "usage_type": "licensed"
          },
          "tax_behavior": "unspecified",
          "tiers_mode": null,
          "transform_quantity": null,
          "type": "recurring",
          "unit_amount": 999,
          "unit_amount_decimal": "999"
        },
        "quantity": 1,
        "subscription": "sub_1Mrfzq2x6R10KRrh349s11jt",
        "tax_rates": []
      }
    ],
    "has_more": false,
    "url": "/v1/subscription_items?subscription=sub_1Mrfzq2x6R10KRrh349s11jt"
  },
#

I would like to know if the discount and quantity are the only 2 fields that I will need to pass

#

Or do you see any other valid information here?

loud smelt
#

Well depends what it you're wanting to update exactly

cyan inlet
#

I need to increase +1 user and re-apply the coupon if was added before.

#

Apart from that I believe Stripe will take care of the price and the rest of the valid information.

loud smelt
#

Then yep, you'll just need to do:

stripe.subscription.update('sub_xxx', {
  items: [{ id: item[0].id, quantity: '8' }],
  coupon: 'abc'
});
cyan inlet
#

Thank you so much, I will test here and give you a feedback

#

But thank you for the support