Mr.Happy
Mr.Happy

Reputation: 517

Not able to get transaction id in subscription plan

I am working with Stripe payment option for my project. I have a recurring option and that's why I have created plans in subscription page.

After creating plans I have defined my plan when a new stripe customer register.

try {
    $customer = \Stripe\Customer::create([
    'source' => $token,
    'email' => $email,
    'plan' => '20-39-R',
    'metadata' => [
        "First Name" => $first_name,
        "Last Name" => $last_name
    ]
    ]);
} catch (\Stripe\Error\Card $e) {
    return redirect()->route('order')
        ->withErrors($e->getMessage())
        ->withInput();
}

When I have dump($customer) variable I am not getting transaction id.

Any idea why I am not getting transaction id during customer creation?Here is my <code>dump($customer)</code> response

Upvotes: 0

Views: 552

Answers (1)

koopajah
koopajah

Reputation: 25552

The customer object doesn't store a list of transaction ids which I think is what you'd call the id of the charge made on that customer's card right? The customer holds information about the sources (used to pay) and subscriptions that are created after a customer is subscribed to a plan.

Here you can see a sub_XXXXX in subscriptions[data][0][id] which corresponds to the id of the subscription that was created on that customer for your plan 20-39-R.

If you want the charge id, ch_XXXXX you would use the List ChargesAPI and pass the customer id, cus_XXXXX, in the `customer parameter to limit the charges to the ones created on that customer. The first one in the list would be the latest charge and likely the one corresponding to your subscription. You could confirm this by checking the invoice associated with the charge and confirming that it's for your subscription.

Upvotes: 1

Related Questions