PHP code example of lunarphp / stripe
1. Go to this page and download the library: Download lunarphp/stripe 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/ */
lunarphp / stripe example snippets
return [
// ...
'types' => [
'card' => [
// ...
'driver' => 'stripe',
],
],
];
'stripe' => [
'key' => env('STRIPE_SECRET'),
'public_key' => env('STRIPE_PK'),
],
use \Lunar\Stripe\Facades\Stripe;
Stripe::createIntent(\Lunar\Models\Cart $cart);
$paymentIntentId = $cart->meta['payment_intent']; // The resulting ID from the method above.
$cart->meta->payment_intent;
use \Lunar\Stripe\Facades\Stripe;
Stripe::fetchIntent($paymentIntentId);
use \Lunar\Stripe\Facades\Stripe;
Stripe::syncIntent(\Lunar\Models\Cart $cart);
return [
// ...
'stripe' => [
// ...
'webhooks' => [
'payment_intent' => '...'
],
],
];
use \Lunar\Stripe\Facades\Stripe;
Route::post('api/payment-intent', function () {
$cart = CartSession::current();
$cartData = CartData::from($cart);
if ($paymentIntent = $cartData->meta['payment_intent'] ?? false) {
$intent = StripeFacade::fetchIntent($paymentIntent);
} else {
$intent = StripeFacade::createIntent($cart);
}
if ($intent->amount != $cart->total->value) {
StripeFacade::syncIntent($cart);
}
return $intent;
})->middleware('web');
sh
php artisan vendor:publish --tag=getcandy.stripe.config
sh
php artisan vendor:publish --tag=getcandy.stripe.components