skip to Main Content

Whenever I try to create a Stripe subscription in PHP with the ‘id’ parameter, it gives an error of invalid parameter, and when I remove the id parameter, it works. Does anyone know how to manually set the subscription id instead of getting an error like this?

What I tried:

$stripe->subscriptions->create([
    'id' => $id,
    'customer' => $id,
    'items' => [
        ['price' => 'price_'],
    ],
]);

What I got:

Fatal error: Uncaught Error sending request to Stripe: (Status 400) (Request req_no) Received unknown parameter: id StripeExceptionInvalidRequestException: Received unknown parameter: id in public_html/stripe-php-13.0.0/lib/Exception/ApiErrorException.php:38

2

Answers


  1. There really is no id key in the api. Perhaps you need to use metadata for your own keys, for example:

    
    $stripe->subscriptions->create([
            'customer' => $customer->id,
            'metadata' => [
                'id' => $id,
            ],
            'items' => [[
                'price' => $price->id,
            ]],
        ]);
    
    
    Login or Signup to reply.
  2. Here’s how you should create a subscription in Stripe using PHP:

    $stripe->subscriptions->create([
        'customer' => $customer_id, 
        'items' => [
            ['price' => 'price_XXXXXXXXXXXXXX'], 
        ],
    ]);
    

    Here’s an example of how you might capture the subscription ID after creation:

    $subscription = $stripe->subscriptions->create([
        'customer' => $customer_id,
        'items' => [
            ['price' => 'price_XXXXXXXXXXXXXX'],
        ],
    ]);
    
    $subscription_id = $subscription->id; // This is the generated subscription ID
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search