How to use laravel cashier charge with `withMetaData` and `create`

  laravel, laravel-cashier, stripe-payments

I am new to laravel cashier, and I am stuck here.

For my games, users can subscribe. I have 3 subscription methods.

  • Monthly
  • Yearly
  • One-time.

For monthly and Yearly subscriptions, I have used the below code and it works perfectly.

$subscription = $user->newSubscription($subscriptionName, $plan->stripe_id)->withMetaData(['game' => $game->name])->create(null, [
    'email' => $user->email,
    'name'  => $user->name,
    ['metadata' => ['game' => $game->name]],
], $subscriptionOptions);

But for the one-time subscription, I have used the below code

$subscription = $user->charge(2500, 'pm_1IpuT.....')->withMetaData(['game' => $game->name])->create(null, [
    'email' => $user->email,
    'name'  => $user->name,
    ['metadata' => ['game' => $game->name]],
], $subscriptionOptions);

for this, I am and getting the below error

Error
Call to undefined method LaravelCashierPayment::withMetaData()

Can anyone help to solve this?

Source: Laravel

Leave a Reply