#ruul_api

1 messages ¡ Page 1 of 1 (latest)

fallow zephyrBOT
gray violetBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

fallow zephyrBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1257307819317661820

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

severe arch
#
   * Purchase subscription
   * @param customer customer id
   * @param price stripe price id
   * @param paymentMethodId id of the payment method (optional)
   * @param quantity number of items (optional)
   * @param trialDays trial days (optional)
   * @returns subscription object
   */
  public async purchaseSubscriptionWithPaymentMethodPresent(
    customer: string,
    price: string,
    paymentMethodId: string,
    quantity?: number,
    trialDays?: number
  ): Promise<Stripe.Subscription> {
    return this.stripe.subscriptions.create({
      customer,
      items: [{ price, ...(quantity && { quantity }) }],
      default_payment_method: paymentMethodId,
      ...(trialDays && { trial_period_days: trialDays }),
    });
  }
#
   * Upgrade a subscription to a new product and price
   * @param subscription current subscription
   * @param newPrice new price id
   * @param quantity number of items
   * @returns updated subscription object
   */
  public async upgradeSubscription(
    subscription: Stripe.Subscription,
    newPrice: string,
    quantity?: number
  ): Promise<Stripe.Subscription> {
    return this.stripe.subscriptions.update(subscription.id, {
      cancel_at_period_end: false,
      proration_behavior: "always_invoice",
      items: [
        {
          id: subscription.items.data[0].id,
          price: newPrice,
          ...(quantity && { quantity }),
        },
      ],
    });
  }
#
   * Downgrade a subscription to a new product and price with proration
   * @param subscription current subscription
   * @param newPrice new price id
   * @param quantity number of items
   * @returns updated subscription object
   */
  public async downgradeSubscription(
    subscription: Stripe.Subscription,
    newPrice: string,
    quantity?: number
  ): Promise<Stripe.Subscription> {
    return this.stripe.subscriptions.update(subscription.id, {
      cancel_at_period_end: false,
      proration_behavior: "create_prorations",
      items: [
        {
          id: subscription.items.data[0].id,
          price: newPrice,
          ...(quantity && { quantity }),
        },
      ],
    });
  }```
#

I attached relevant code

#

I believe we should provide a coupon id whether it's a downgrade/upgrade/purchase but

#

do we lookup the coupon that the input promotion code belongs to ?

#

is that the normal way to do this ?

spare scroll
#

Will the discount be input by the customer via a form, or is it applied programmatically in your integration?

severe arch
#

we use a setup session to save the card details & then they only select which card to pay with & for what but they'll have to input some kind of code from frontend in the new flow

#

so I was thinking that they need to create a coupon & promotion codes for that in the dashboard give them to whoever they want & on code we get the promotion code from input & validate it/get the coupon for that (I'm not sure about how this part is done) & then just provide the couponId to one of the methods mentioned above