Alex
Alex

Reputation: 79

One time fee and recurring after with Stripe and Laravel Cashier

I am trying to charge a one time fee + first month subscription fee in stripe but I can't figure out how to do it since they change their interface.

After the initial fee + first month subscription fee, it should roll on a monthly basis.

Ideally I am looking to do this with Laravel Cashier.

Any ideas and examples will be welcome.

Upvotes: 1

Views: 1319

Answers (2)

Alex
Alex

Reputation: 79

$user->newSubscription('main', 'plan_xxxxxxxxxxxxxx')->create($request->stripeToken);           

$customer = Customer::retrieve($parent_account->stripe_id);

$charge = Charge::create(array(
                'customer' => $customer->id,
                'amount' => $amount,
                'currency' => 'gbp',
        'description' => 'Joining Fee',                     
            ));

Upvotes: 0

Leo
Leo

Reputation: 7420

Here is how to charge a subscription or a one time pay in stripe:

public function index()
{
    if (!request()->wantsJson()) {
        abort(404);
    }

    $plan = request()->get('plan');

    $stripeToken = request()->get('stripeToken');

    $user = User::findOrFail(request()->get('userId'));

    if (is_null($user) || is_null($plan) || is_null($stripeToken)) {
        return response()->json(403);
    }

    if ($plan === self::PREMIUM) {
        $user->newSubscription('main', self::PREMIUM_ID)->create($stripeToken);
    }

    if ($plan === self::EXTENDED) {

        $transaction = $user->charge(999, ['currency' => 'usd', 'source' => $stripeToken]);

        $payment = new Payment([
            'payment_id'     => $transaction->id,
            'payment_status' => $transaction->paid,
            'amount'         => $transaction->amount,
        ]);

        $user->payments()->save($payment);
    }

    return response()->json(200);
}

Upvotes: 1

Related Questions