#bitsmyth_best-practices

1 messages · Page 1 of 1 (latest)

halcyon briarBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1404350423028076598

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

hollow blaze
#

Serverside:

  def create
    subscription = Stripe::Subscription.create(
      customer: Current.account.stripe_customer_id,
      items: [{
        price: price_id
      }],
      add_invoice_items: additional_one_time_prices,
      payment_behavior: "default_incomplete",
      payment_settings: {save_default_payment_method: "on_subscription"},
      expand: ["latest_invoice.confirmation_secret"]
    )

    render json: {subscription_id: subscription.id, client_secret: subscription.latest_invoice.confirmation_secret.client_secret}, status: :ok
  end

Clientside:

  const handleCheckout = async (priceId: string) => {
      const response = await api.stripe.subscriptions.create(priceId)
      const { client_secret } = response.data
      await initPaymentSheet({
        paymentIntentClientSecret: client_secret,
        allowsDelayedPaymentMethods: false,
        billingDetailsCollectionConfiguration: {
          name: PaymentSheet.CollectionMode.ALWAYS,
          email: PaymentSheet.CollectionMode.NEVER,
          phone: PaymentSheet.CollectionMode.ALWAYS,
          address: PaymentSheet.AddressCollectionMode.FULL,
          attachDefaultsToPaymentMethod: true,
        },
      })
      await presentPaymentSheet()
  }
umbral gorge
#

Hi!

I am on the hunt for a workflow that does not create invoices before payment was actually completed.
Invoices are statements of amounts owed by a customer. So it cannot be created after a payment has completed. The invoice informs the customer what they are supposed to pay.

hollow blaze
#

Thanks sam!

So how do then companies deal with „funny“ customers who click multiple times on the subscription button?

I can try to reuse the previously created subscription but would loose access to the client secret as i only retrieve without expand…

Anyway this approach would just reduce the amount of cancelled invoices to 1 instead

umbral gorge
#

Looking into your query!

umbral gorge
#

Thanks for waiting!

#

What you can consider doing is to check if a customer already has a subscription with an open invoice. If they do, don't create a new subscription for them. Instead you can retrieve the client secret of the existing subscription by retrieving the subscription and expanding latest_invoice.confirmation_secret.client_secret . This way you don't have to save the client secret and you can re-open the payment sheet.