Display the subscription id on the strip after creating the subscription in php

I can’t figure it out. So what I do is there is an automatic payment page. The client performs autopopulation, and the php script will create a subscription with a strip. I cannot figure out how to get this subscription id to save it on my db. Here is what I have:

$cu = Stripe_Customer::retrieve("$stripename"); 
$cu->subscriptions->create(array("plan" => "cocacola"));

Thus, this creates a subscription in the strip in order. Now I want to save this new subscription identifier in my database. I can get a list of data using this line:

echo "$cu->subscriptions";

The subscription ID is displayed there along with a host of other data, but I cannot isolate it and save it in a row.

Answer from the echo:

{
    "object": "list",
    "count": 1,
    "url": "/v1/customers/cus_3bgSLHOiTUHFjq/subscriptions",
    "data": [
        {
            "id": "sub_3c3YirUU5jAftr",
            "plan": {
                "id": "cocacola",
                "interval": "month",
                "name": "cocacola",
                "created": 1392273785,
                "amount": 80000,
                "currency": "usd",
                "object": "plan",
                "livemode": false,
                "interval_count": 1,
                "trial_period_days": null,
                "metadata": []
            },
            "object": "subscription",
            "start": 1394065982,
            "status": "active",
            "customer": "cus_3bgSLHOiTUHFjq",
            "cancel_at_period_end": false,
            "current_period_start": 1394065982,
            "current_period_end": 1396744382,
            "ended_at": null,
            "trial_start": null,
            "trial_end": null,
            "canceled_at": null,
            "quantity": 1,
            "application_fee_percent": null,
            "discount": null
        }
    ]
}

I am trying to save "sub_3c3YirUU5jAftr" to a string.

+4
source share
1
    Stripe::setApiKey("Use your api key"); // use your api key
            $subscription = Stripe_Customer::create(array(
                'source' => 'Use your token', // Pass Token
                'plan' => '1', // Pass plan id
                'customer' => 'Use Customer Id' // Pass customer id
                )
              ); 
echo $subscription['subscription']['id'];

$subscription

+2

Source: https://habr.com/ru/post/1530347/


All Articles