Stripe tutorial
This commit is contained in:
parent
2deaa14dcf
commit
e1a989b2a6
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Stripe\Stripe;
|
||||
|
||||
class StripeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('stripe.index');
|
||||
}
|
||||
|
||||
public function checkout()
|
||||
{
|
||||
Stripe::setApiKey(config('stripe.sk'));
|
||||
|
||||
$session = \Stripe\Checkout\Session::create([
|
||||
'line_items' => [
|
||||
[
|
||||
'price_data' => [
|
||||
'currency' => 'usd',
|
||||
'product_data' => [
|
||||
'name' => 'send me money',
|
||||
],
|
||||
'unit_amount' => 3250, // in cents
|
||||
],
|
||||
'quantity' => 1,
|
||||
],
|
||||
],
|
||||
'mode' => 'payment',
|
||||
'success_url' => route('stripe.success'),
|
||||
'cancel_url' => route('stripe.index'),
|
||||
]);
|
||||
|
||||
return redirect()->away($session->url);
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
return view('stripe.index');
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,8 @@
|
|||
"laravel/framework": "^12.49",
|
||||
"laravel/tinker": "^2.11.0",
|
||||
"livewire/flux": "^2.11.1",
|
||||
"livewire/livewire": "^4.1"
|
||||
"livewire/livewire": "^4.1",
|
||||
"stripe/stripe-php": "^19.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.24.1",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "aa16a4acb2dc4a2a7bb2eb1dd04b1907",
|
||||
"content-hash": "fae50eff8a59cae5ee7908635763dacf",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bacon/bacon-qr-code",
|
||||
|
|
@ -3721,6 +3721,65 @@
|
|||
},
|
||||
"time": "2025-12-14T04:43:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "stripe/stripe-php",
|
||||
"version": "v19.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/stripe/stripe-php.git",
|
||||
"reference": "462272ae7560ee29bb891763fd0967d5a77784e5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/stripe/stripe-php/zipball/462272ae7560ee29bb891763fd0967d5a77784e5",
|
||||
"reference": "462272ae7560ee29bb891763fd0967d5a77784e5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "3.72.0",
|
||||
"phpstan/phpstan": "^1.2",
|
||||
"phpunit/phpunit": "^5.7 || ^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Stripe\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Stripe and contributors",
|
||||
"homepage": "https://github.com/stripe/stripe-php/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Stripe PHP Library",
|
||||
"homepage": "https://stripe.com/",
|
||||
"keywords": [
|
||||
"api",
|
||||
"payment processing",
|
||||
"stripe"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/stripe/stripe-php/issues",
|
||||
"source": "https://github.com/stripe/stripe-php/tree/v19.3.0"
|
||||
},
|
||||
"time": "2026-01-28T21:15:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/clock",
|
||||
"version": "v8.0.0",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'sk' => env('STRIPE_SK'),
|
||||
'pk' => env('STRIPE_PK'),
|
||||
];
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<form action="/checkout" method="POST">
|
||||
@csrf
|
||||
<button type="submit">Checkout</button>
|
||||
</form>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\CustomerInvoiceController;
|
||||
use App\Http\Controllers\StripeController;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
|
@ -20,12 +21,9 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||
Route::view('payments', 'payments.index')->name('payments');
|
||||
});
|
||||
|
||||
// Route::view('dashboard', 'dashboard')
|
||||
// ->middleware(['auth', 'verified'])
|
||||
// ->name('dashboard');
|
||||
|
||||
// Route::view('clients', 'clients.index')
|
||||
// ->middleware(['auth', 'verified'])
|
||||
// ->name('clients.index');
|
||||
// Testing Stripe
|
||||
Route::get('stripe', [StripeController::class, 'index'])->name('stripe.index');
|
||||
Route::post('/checkout ', [StripeController::class, 'checkout'])->name('stripe.checkout');
|
||||
Route::get('/success', [StripeController::class, 'success'])->name('stripe.success');
|
||||
|
||||
require __DIR__.'/settings.php';
|
||||
|
|
|
|||
Loading…
Reference in New Issue