我有一个来自 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方法,但我似乎无法弄清楚。
不负相思意