PHP code example of veldora / connect
1. Go to this page and download the library: Download veldora/connect library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
veldora / connect example snippets
'providers' => [
// ...
Veldora\Connect\Stripe\StripeServiceProvider::class,
],
use Veldora\Connect\Stripe\Facades\Stripe;
Route::post('/checkout', function () {
$session = Stripe::checkout()->create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'Veldora Pro Subscription',
],
'unit_amount' => 2000,
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => url('/success?session_id={CHECKOUT_SESSION_ID}'),
'cancel_url' => url('/cancel'),
]);
return redirect($session->url);
});
use Veldora\Connect\Stripe\Facades\Stripe;
use Veldora\Framework\Http\Request;
use Veldora\Framework\Http\Response;
Route::post('/webhook/stripe', function (Request $request) {
$payload = $request->getContent();
$sigHeader = $request->header('stripe-signature');
try {
$event = Stripe::webhook()->constructEvent(
$payload,
$sigHeader,
config('stripe.webhook_secret')
);
if ($event->type === 'checkout.session.completed') {
$session = $event->data->object;
// Fulfill the order
}
return Response::json(['status' => 'success']);
} catch (\Exception $e) {
return Response::json(['error' => $e->getMessage()], 400);
}
});