PHP code example of randomstate / stripe

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

    

randomstate / stripe example snippets


public function register() {
    $this->app->bind(\RandomState\Stripe\BillingProvider::class, \RandomState\Stripe\Stripe::class);
    $this->app->bind(\RandomState\Stripe\Stripe::class, function() {
        return new \RandomState\Stripe\Stripe(env("STRIPE_SECRET"));
    });
}


$stripe->charges()->create([
    'amount' => 100,
    // etc
])

$stripe->subscriptions()->items()->retrieve($itemId); // etc


$webhooks = new WebhookListener($this->stripe->events());
$webhooks->record();

// perform actions

$events = $webhooks->play();

// Alternatively,
$events = $webhooks->during(function() {
    // perform actions
});


// Forward webhooks to your controllers in Laravel like so:
$webhooks->listen(function(Event $event) {
    $this->postJson('/my/webhooks/endpoint', $event->jsonSerialize());
});

$webhooks->during(function() {
     // perform actions and all events will be played automatically by sending the data as 
     // a POST request to your webhook endpoint as defined above.
});