Stripe Bi-Weekly Subscription Description

Viewed 32

Using Stripe's PHP API I was able to create a bi-weekly subscription for my customers but I'm having an issue, the "description" on all subscriptions is defaulting to "Subscription creation" and I can't seem to find a way to add a description although I thought the following code worked in the past (I updated the API since then). Please see my code below

        case "BiWeekly":
        try {
            $product = \Stripe\Product::create([
                "name" => "NEO Bi-Weekly Payments for $cname",
                "type" => "service",
                "statement_descriptor" => "NEO",
            ]);

            $plan = \Stripe\Plan::create([
                "product" => $product->id,
                "amount" => $totalAmount,
                "currency" => "usd",
                "interval" => "week",
                "interval_count" => 2,
                "usage_type" => "licensed",
            ]);

            $subscription = \Stripe\Subscription::create([
                "customer" => $customer->id,
                "items" => [["plan" => $plan->id]],
                "metadata" => array("Name" => $cname, "For" => "NEO Bi-Wkly Pymts")
            ]);
            
            } catch(\Stripe\Error\Card $e) {
                $body = $e->getJsonBody();
                $err  = $body['error'];
                header("Location: https://www.neo.com/declined/");
                exit();
            };
    break;

Any help would be greatly appreciated!

1 Answers

As clarified in the comments - description='Subscription creation' is on the corresponding PaymentIntent (not the Subscription).

There's no easy way to do this - it's not possible to specify a description when creating the Subscription to automatically populate on the corresponding PaymentIntent.

What I suggest is to :

  1. Create the Subscription with metadata
  2. listen for the invoice.payment_succeeded webhook event - https://stripe.com/docs/webhooks
  3. The invoice.payment_succeeded will contain the metadata from step 1 in lines and the payment_intent

Example

...
"lines": {
      "object": "list",
      "data": [
        {
          "id": "il_...",
          "object": "line_item",
          ...
          "metadata": {
            "subscription_metadata": "some_value"
          },
  ...
"payment_intent": "pi_...",
...
  1. using the data from step 3, make a request to update the PaymentIntent's description

On a side note, you should no longer be creating Plans (which is deprecated), but should be creating Prices instead.

Related