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


use Dominservice\LaraStripe\Client as StripeClient;

$stripe = new StripeClient();
$session = $stripe->checkoutSessions()
    ->setMode('payment')
    ->setSuccessUrl(url('/checkout/success') . '?session_id={CHECKOUT_SESSION_ID}')
    ->setCancelUrl(url('/checkout/cancel'))
    ->setLineItems([['price' => 'price_your_test_price_id', 'quantity' => 1]])
    ->create();

return redirect()->away($session->url);

'currencies' => ['PLN', 'EUR', 'USD', 'GBP'],

Route::middleware(['stripe.verify:checkout'])->group(function () {
    Route::post('/webhook/payments', [WebhookController::class, 'payments']);
});

config('stripe.webhooks.signing_secrets.checkout')

use Dominservice\LaraStripe\Client as StripeClient;

$stripe = new StripeClient();

$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);

$productStripe = $stripe->products()
    ->setName($product->name)
    ->setActive(true)
    ->setExtendPricesCurrency('pln')
    ->setExtendPricesUnitAmount((float) $amount)
    ->setExtendPricesBillingScheme('per_unit')
    ->create($product);

$session = $stripe->checkoutSessions()
    ->setSuccessUrl(route('payment.afterTransaction', $order->ulid) . '?session_id={CHECKOUT_SESSION_ID}')
    ->setCancelUrl(route('payment.canceled', $order->ulid))
    ->setMode('payment')
    ->setClientReferenceId($order->ulid)
    ->setCustomer($customer->id)
    ->setLineItems([
        [
            'price' => $productStripe->default_price->id,
            'quantity' => 1,
        ],
    ])
    ->create();

use Dominservice\LaraStripe\Helpers\PaymentHelper;

$currency = PaymentHelper::normalizeCurrencyCode('eur', true); // eur

$unitAmount = PaymentHelper::getValidAmount('EUR', 49.99); // 4999

use Dominservice\LaraStripe\Helpers\PaymentHelper;

$methods = PaymentHelper::getPaymentMethodsByCountry('PL', 'PLN');
// ['card', 'blik', 'klarna', 'p24', 'paypal']

$methods = PaymentHelper::getPaymentMethodsByCountry('DE', 'EUR');
// ['card', 'klarna', 'paypal', 'sepa_debit']

$methods = PaymentHelper::getPaymentMethodsByCountry('PL', 'PLN', [
    'customer_type' => 'private',
    'mcc' => '7991',
    'project_type' => 'travel',
    'allowed_methods' => ['card', 'blik', 'paypal'],
    'forbidden_methods' => ['klarna'],
]);

stripe.payment_method_policies

'allowed_methods_by_project_type' => [
    'travel' => ['card', 'paypal'],
    'hotel' => ['card', 'paypal', 'klarna'],
    'saas' => ['card', 'paypal', 'sepa_debit'],
],

'allowed_methods_by_business_type' => [
    'tourism' => ['card', 'paypal'],
    'saas' => ['card', 'paypal', 'sepa_debit'],
],

'forbidden_methods_by_project_type' => [
    'travel' => ['p24'],
],

'forbidden_methods_by_business_type' => [
    'regulated' => ['klarna'],
],

'customer_type' => 'company'

'forbidden_methods_by_mcc' => [
    '4722' => ['p24'],
    '7011-7012' => ['p24'],
],

use Dominservice\LaraStripe\Client as StripeClient;

$stripe = new StripeClient();

$account = $stripe->accounts()
    ->setType('express')
    ->setCountry('PL')
    ->setEmail($expert->email)
    ->setCapabilities([
        'transfers' => ['requested' => true],
    ])
    ->create($expert);

$onboarding = $stripe->accountLinks()
    ->setAccount($account->id)
    ->setRefreshUrl(route('expert.billing.refresh'))
    ->setReturnUrl(route('expert.billing.return'))
    ->setType('account_onboarding')
    ->create();

$loginLink = $stripe->loginLinks()->create($account->id);
shell
php artisan vendor:publish --provider="Dominservice\\LaraStripe\\ServiceProvider" --tag=stripe
shell
php artisan vendor:publish --provider="Dominservice\\LaraStripe\\ServiceProvider" --tag=stripe-migrations
shell
php artisan migrate