一次性费用,经过Stripe和Laravel Cashier后再次出现

时间:2018-05-10 12:04:02

标签: laravel stripe-payments laravel-cashier

我试图收取一次性费用+第一个月的订阅费,但我无法弄清楚如何改变他们的界面。

在初始费用+第一个月的订阅费之后,它应该按月滚动。

理想情况下,我希望与Laravel Cashier合作。

欢迎任何想法和例子。

2 个答案:

答案 0 :(得分:1)

以下是如何收取订阅费用或一次性付费:

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);
}

答案 1 :(得分:0)

$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',                     
            ));