PHP code example of dominservice / laravel-stripe
1. Go to this page and download the library: Download dominservice/laravel-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/ */
dominservice / laravel-stripe example snippets
Route::group(['middleware' => ['stripe.verify:checkout'], 'namespace' => '\App\Http\Controllers'], function () {
Route::get('/webhook/payments', 'WebhookController@payments');
(...)
use Dominservice\LaraStripe\Client as StripeClient;
(...)
$stripe = (new StripeClient());
// Create product with price
$product = \App\Models\Product::find(1);
$productStripe = $stripe->products()
->setName($product->name)
->setActive(true)
->setExtendPricesCurrency('pln')
->setExtendPricesUnitAmount((float)$amount)
->setExtendPricesBillingScheme('per_unit')
->setExtendPricesRecurring(['interval' => 'month'])
->create($product);
// Create customer
$customer = $stripe->customers()
->setName($user->name)
->setEmail($user->email)
->setPhone($user->phone)
->setAddress([
'country' => 'PL',
'city' => 'Warszawa',
'postal_code' => '00-000',
'line1' => 'ul. kopernika 1/2',
])
->create($user);
// Checkout session
$session = $stripe->checkoutSessions()
->setSuccessUrl(route('payment.afterTransaction', $order->ulid) . '?session_id={CHECKOUT_SESSION_ID}')
->setCancelUrl(route('payment.canceled', $order->ulid))
->setMode('subscription')
->setClientReferenceId($order->ulid)
->setCustomer($customer->id)
->setLineItems([
[
'price' => $productStripe->default_price->id,
'quantity' => 1,
]
])
->create();
shell
php artisan vendor:publish --tag=stripe
shell
php artisan vendor:publish --tag=stripe-migrations