簡體   English   中英

一次性費用,之后與Stripe和Laravel Cashier重復發生

[英]One time fee and recurring after with Stripe and Laravel Cashier

我正在嘗試收取一次費用+條帶化的第一個月訂閱費,但由於他們更改了界面,我不知道該怎么辦。

扣除初始費用+第一個月的訂閱費用后,它應該按月滾動。

理想情況下,我希望與Laravel Cashier合作。

任何想法和例子都將受到歡迎。

以下是在條帶中收取訂閱費用或一次性付款的方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM