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/ */
$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);
use \Lunar\Stripe\Facades\Stripe;
Stripe::updateIntent(\Lunar\Models\Cart $cart, [
'shipping' => [/*..*/]
]);
use Lunar\Stripe\Enums\CancellationReason;
CancellationReason::ABANDONED;
CancellationReason::DUPLICATE;
CancellationReason::REQUESTED_BY_CUSTOMER;
CancellationReason::FRAUDULENT;
use Lunar\Stripe\Facades\Stripe;
use Lunar\Stripe\Enums\CancellationReason;
Stripe::cancelIntent(\Lunar\Models\Cart $cart, CancellationReason $reason);
use \Lunar\Stripe\Facades\Stripe;
Stripe::updateShippingAddress(\Lunar\Models\Cart $cart);
use \Lunar\Stripe\Facades\Stripe;
Stripe::getCharge(string $chargeId);
use \Lunar\Stripe\Facades\Stripe;
Stripe::getCharges(string $paymentIntentId);
$cart = CartSession::current();
// With a draft order...
$draftOrder = $cart->createOrder();
Payments::driver('stripe')->order($draftOrder)->withData([
'payment_intent' => $draftOrder->meta['payment_intent'],
])->authorize();
// Using just the cart...
Payments::driver('stripe')->cart($cart)->withData([
'payment_intent' => $cart->meta['payment_intent'],
])->authorize();
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');
// AppServiceProvider
use Lunar\Stripe\Concerns\ProcessesEventParameters;
use Lunar\Stripe\DataTransferObjects\EventParameters;
public function boot()
{
$this->app->instance(ProcessesEventParameters::class, new class implements ProcessesEventParameters
{
public function handle(\Stripe\Event $event): EventParameters
{
$paymentIntentId = $event->data->object->id;
// Setting $orderId to null will mean a new order is created.
$orderId = null;
return new EventParameters($paymentIntentId, $orderId);
}
});
## Events
Below are the events which are dispatched under specific situations within the addon.
### `Lunar\Stripe\Events\Webhook\CartMissingForIntent`
Dispatched when attempting to process a payment intent, but no matching Order or Cart model can be found.
sh
php artisan vendor:publish --tag=lunar.stripe.config
sh
php artisan vendor:publish --tag=lunar.stripe.components
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.