猿问

从 Laravel 中删除 Stripe 支付

我有一个来自 Github 的项目,我想修改它。我正在尝试删除条纹支付,因此注册是在没有支付网关的情况下完成的。我正在与 Laravel 合作。


对于路线来说,


Route::post('course/payment', ['uses' => 'CoursesController@payment', 'as' => 'courses.payment']);

对于控制器方法,


    public function payment(Request $request)

{

    $course = Course::findOrFail($request->get('course_id'));

    $this->createStripeCharge($request);

    $course->students()->attach(\Auth::id());

    return redirect()->back()->with('success', 'Payment completed successfully.');

}

Blade.php 文件中的表单操作为:


@if (\Auth::check())

    @if ($course->students()->where('user_id', \Auth::id())->count() == 0)

        <form action="{{ route('courses.payment') }}" method="POST">

            <input type="hidden" name="course_id" value="{{ $course->id }}" />

            <input type="hidden" name="amount" value="{{ $course->price * 100 }}" />

                <script

                    src="https://checkout.stripe.com/checkout.js" class="stripe-button"

                    data-key="{{ env('PUB_STRIPE_API_KEY') }}"

                    data-amount="{{ $course->price * 100 }}"

                    data-currency="usd"

                    data-name="LMS"

                    data-label="Buy this course (${{ $course->price }})"

                    data-description="Course: {{ $course->title }}"

                    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"

                    data-locale="auto"

                    data-zip-code="false">

                </script>

                {{ csrf_field() }}

            </form>

    @endif

@else

我知道我应该找到一种GET方法,但我似乎无法弄清楚。


红糖糍粑
浏览 124回答 1
1回答

不负相思意

对于表单动作,@if (\Auth::check())&nbsp; &nbsp; @if ($course->students()->where('user_id', \Auth::id())->count() == 0)&nbsp; &nbsp; &nbsp; &nbsp; {{Form::open(['action'=> 'CoursesController@payment', 'method' => 'POST'])}}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" name="course_id" value="{{ $course->id }}"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{Form::submit('Enroll', ['class'=>'btn btn-primary'])}}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{Form::close()}}&nbsp; &nbsp; @endif@else对于控制器:public function payment(Request $request) {&nbsp; &nbsp; $course = Course::findOrFail($request->get('course_id'));&nbsp; &nbsp; $course->students()->attach(\Auth::id());&nbsp; &nbsp; return redirect()->back()->with('success', 'Payment completed successfully.');}
随时随地看视频慕课网APP
我要回答