PHP code example of leifermendez / laravel-stripe

1. Go to this page and download the library: Download leifermendez/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/ */

    

leifermendez / laravel-stripe example snippets



    'providers'     => array(

        //...
        leifermendez\stripe\StripeProvider::class,

    ),



    'aliases'       => array(

        //...
        'StripeSCA'  => leifermendez\stripe\StripeLaravelFacade::class,

    ),


//Test card: https://stripe.com/docs/testing#cards

$card_data = array(
    'card' => [
        'number' => 4000002500003155,
        'exp_month' => 12,
        'exp_year' => 2020,
        'cvc' => 123
    ]
);

$card = StripeLaravelFacade::tokenCard($card_data);
$card = json_decode($card, true);

dd($card);


// https://stripe.com/docs/api/payment_intents/create

$data = array(
    'email' => '[email protected]',
    'source' => 'tok_1FOO42HBaMrHjOH4Cu0dnogU' // <-- Token Card Paso (1)
);

$user = StripeLaravelFacade::saveCustomer($data);
$user = json_decode($user, true);

dd($response);



// https://stripe.com/docs/api/payment_intents/create

$amount = 134;
$charge = array(
    'description' => 'Mi primer cobro',
    'amount' => floatval($amount * 100),
    'currency' => 'EUR',
    'payment_method_types' => ['card'],
    'customer' => cus_G0amE3Dmn4p1f0, // <--- ID Customer Paso (2)
    'setup_future_usage' => 'off_session' // <--- Off Session
);

$response = StripeLaravelFacade::charge_sca($charge);

dd($response);



$amount = 134;

$charge = array(
    'description' => 'Cobro de fianza' ,
    'amount' => floatval($amount * 100),
    'currency' => 'EUR',
    'payment_method_types' => ['card'],
    'off_session' => 'true',
    'confirm' => 'true',
    'capture_method' => 'manual', // <--- Indicamos que es un pago No Capturado
    'source' => 'card_1FX8TaHBaMrHjOH4MeiQmvPC', // <---  ID Source Customer Paso (2)
    'customer' => 'cus_G0amE3Dmn4p1f0'  // <--- ID Customer Paso (2)

);

$response = StripeLaravelFacade::charge_sca($charge);

dd($response);