#jovan_subscription-trial

1 messages ¡ Page 1 of 1 (latest)

wicked garnetBOT
#

👋 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/1227301486699216991

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

deep aspenBOT
#

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.

peak tide
#

This is my code when creating a subscription

      // Create a subscription with 30 days trial
      $subscription = $this->stripe->subscriptions->create([
        'customer' => $customer->id,
        'items' => [
            [
              'price' => $_ENV['STARTER_PLAN'],
              'quantity' => $fields['client_allowed_members']
            ]
        ],
        'trial_period_days' => 30,
        'payment_behavior' => 'default_incomplete',
        'payment_settings' => [
          'save_default_payment_method' => 'on_subscription',
          'payment_method_types' => ['card'],
        ],
        'expand' => ['pending_setup_intent'],
        // 'metadata' => $metadata
      ]);
deep aspenBOT
proper peak
#

jovan_subscription-trial

#

@peak tide there isn't really an easy way to do that. What you can do is create the SetupIntent first, wait for it to succeed and only then create the Subscription.

peak tide
proper peak
#

yep

peak tide
#

How do you create a subscription with setupIntent attached?

proper peak
#

you don't, it doesn't really make sense to do that

peak tide
#

Is this also suitable for after setupIntent has been created?

      // Create a subscription with 30 days trial
      $subscription = $this->stripe->subscriptions->create([
        'customer' => $customer->id,
        'items' => [
            [
              'price' => $_ENV['STARTER_PLAN'],
              'quantity' => $fields['client_allowed_members']
            ]
        ],
        'trial_period_days' => 30,
        'payment_behavior' => 'default_incomplete',
        'payment_settings' => [
          'save_default_payment_method' => 'on_subscription',
          'payment_method_types' => ['card'],
        ],
        'expand' => ['pending_setup_intent'],
        // 'metadata' => $metadata
      ]);
proper peak
#

You create a SetupIntent, confirm it to collect card/payment method details and attach it to a Customer, then you create a Subscription with that PaymentMethod pm_123 as the default. No need to do anything else

peak tide
#

Ohhhh so you need the payment method

#

How do you create a subscription with an existing payment method?

proper peak
peak tide
#
// Create a subscription with 30 days trial
      $subscription = $this->stripe->subscriptions->create([
        'customer' => $customer->id,
        'default_payment_method'  => $PAYMENT_METHOD
        'items' => [
            [
              'price' => $_ENV['STARTER_PLAN'],
              'quantity' => $fields['client_allowed_members']
            ]
        ],
        'trial_period_days' => 30,
      ]);

Is this enough?

proper peak
#

yes

peak tide
#

Okay I'll try it out

wicked garnetBOT
peak tide
#

Is the automatic_payment_methods unnecessary here?

      $setupIntent = $this->stripe->setupIntents->create([
        'customer' => $customer->id,
        'automatic_payment_methods' => ['enabled' => true],
        'payment_method_types' => ['card'],
      ]);

I have Credit/Debit, Google Play, and Link

#

Is it okay to remove the customer item here?

// Create a subscription with 30 days trial
      $subscription = $this->stripe->subscriptions->create([
        'customer' => $customer->id,
        'default_payment_method'  => $PAYMENT_METHOD
        'items' => [
            [
              'price' => $_ENV['STARTER_PLAN'],
              'quantity' => $fields['client_allowed_members']
            ]
        ],
        'trial_period_days' => 30,
      ]);

since I already have a default_payment_method ?

loud jacinth
#

Hello! I'm taking over and catching up...

#

automatic_payment_methods may or may not be optional depending on your API version. It also conflicts with payment_method_types. The idea is that you either specify specific payment_method_types or you use automatic_payment_methods (the ones enabled in your Dashboard).

#

The Customer can't be removed, since the Payment Method in question belongs to that Customer.

peak tide
#

What will happen if I don't attached a customer on create setupintent?

      $setupIntent = $this->stripe->setupIntents->create([
        'payment_method_types' => ['card'],
      ]);

Then only create a customer when it is ready to create a subscription

// Create a subscription with 30 days trial

      // Create a customer
      $customer = $this->createCustomer($fields['name'], $fields['business_email']);

      $subscription = $this->stripe->subscriptions->create([
        'customer' => $customer->id,
        'default_payment_method'  => $PAYMENT_METHOD
        'items' => [
            [
              'price' => $_ENV['STARTER_PLAN'],
              'quantity' => $fields['client_allowed_members']
            ]
        ],
        'trial_period_days' => 30,
      ]);

Is that possible?

#

Or is it really necessary to attach a customer when creating a setupIntent?

loud jacinth
#

Yeah, you can create a Setup Intent without a Customer and add the Customer later.

peak tide
#

Okay, I'll try it out and get back to you.

loud jacinth
#

Sounds good!

peak tide
#

I think it's not possible:

"The customer does not have a payment method with the ID pm_1P3igjFB7z3o5hlIBQERWhTZ. The payment method must be attached to the customer."
loud jacinth
#

Let's back up a bit. What's the flow you're trying to build at a high level?

peak tide
#

I want to verify if the card is legit or not before creating a subscription. To do this, this is my current flow:

  1. Create SetupIntent
  2. confirmSetup()
  3. Create Customer
      [
        'email' => "$email",
        'name' => "$name",
      ]
    );
  1. Create Subscription

Our service has a free 30-day trial and we want to automatically charge the customer after trial ended.

#

I guess I should attach the payment method to a customer first?

loud jacinth
#

What I recommend you do is create the Customer, create a Setup Intent for them, confirm that, then create the Subscription. If the Setup Intent fails you can use the same Customer for a second Setup Intent.