superphonic
superphonic

Reputation: 8074

Create a new Stripe user on a paid plan, setting a trial period, without a Credit Card

Using the Stripe API, Creating a new user on a paid plan with a trial period doesn't seem to work without a credit card token.

I am using the PHP SDK and doing the following:

$customer = \Stripe\Customer::create(array(
    "source" => NULL,
    "plan" => 'PROFESSIONAL',
    "email" => $email_address,
    "trial_end" => $unix_timestamp
);

Which returns the error:

Error: Invalid source object: must be a dictionary or a non-empty string.

There are two reasons I think this should work, which is why I think I am doing something wrong.

  1. Adding trial_end adds a trial to the subscription, so no payment is needed which means it doesn't need a Credit Card at that point in time.
  2. Using the Stripe online Portal, you can create a user on a paid subscription, and also move existing users on to a paid subscription without the need for a Credit Card, when you specify a trial period. If you can do it in the portal, why can't you do it via the API?

Is there something I have missed in the Documentation to allow me to do this?

Upvotes: 1

Views: 1045

Answers (2)

Deepak Saini
Deepak Saini

Reputation: 116

Follow these step

  1. Create a customer using

    \Stripe\Customer::create(array( "description" => $descriptions, "email" => $email ));

  2. Store the returned customer ID from stripe

  3. Now subscribe the customer for that plan

    $customer = \Stripe\Customer::retrieve($customer_id);

    $subscriptions = $customer->subscriptions->create(array("plan" => $plan_id));

Please make sure plan is already created on stripe.

Upvotes: 0

superphonic
superphonic

Reputation: 8074

Just tried the following which worked.

$customer = \Stripe\Customer::create(array(
    "plan" => 'PROFESSIONAL',
    "email" => $email_address,
    "trial_end" => $unix_timestamp
);

Basically I just removed the source key/value completely. It then created the user on the paid plan with the trial.

Odd behaviour as when you create a user on a FREE plan, you can have the source key there with a value of NULL and it works. Also not documented as far as I can see.

Upvotes: 1

Related Questions