PHP code example of hakito / cakephp-stripe-payment-intents-plugin

1. Go to this page and download the library: Download hakito/cakephp-stripe-payment-intents-plugin 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/ */

    

hakito / cakephp-stripe-payment-intents-plugin example snippets


public function bootstrap(): void
{
    // Call parent to load bootstrap from files.
    parent::bootstrap();

    $this->addPlugin(\StripePaymentIntents\Plugin::class, ['routes' => true]);
}

'StripePaymentIntents' => [
    'mode'=> 'test',
    'currency' => 'eur',
    'keys' => [
        'test' => [
            'secret' => 'sk_test_4eC39HqLyjWDarjtT1zdp7dc',
            'public' => 'pk_test_abc',
        ],
        'live' => [
            'secret' => 'sk_live_key',
            'public' => 'pk_live_key'
        ]
    ],
    'logging' => false,
]

'Log' =>
[
    'stripe' =>
    [
        'className' => FileLog::class,
        'path' => LOGS,
        'file' => 'stripe',
        'scopes' => ['Stripe'],
        'levels' => ['warning', 'error', 'critical', 'alert', 'emergency', 'info'],
    ],
]

// Load the component
public function initialize(): void
{
    parent::initialize();
    $this->loadComponent('StripePaymentIntents.StripePaymentIntents');
}

// create new
$pi = $this->StripePaymentIntents->Create(1234, ['metadata' => ['order_id' => $orderId]]); // 12.34
// or update shopping cart
$pi = $this->StripePaymentIntents->Retrieve('pi_xyz');

$this->set('StripeClientSecret', $pi->client_secret);
$this->set('StripePublicKey', $this->StripePaymentIntents->GetPublicKey());

\Cake\Event\EventManager::instance()->on('StripePaymentIntents.Event',
function (\Cake\Event\Event $event, \Stripe\Event $stripeEvent)
{
    return ['handled' => true]; // If you don't set the handled flag to true
                                // the plugin will throw an exception
});