PHP code example of zfr / zfr-stripe

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

    

zfr / zfr-stripe example snippets


$client = new StripeClient('my-api-key');

$client = new StripeClient('my-api-key', '2015-10-16');

$details = $client->createCharge([
    'amount'   => 500,
    'currency' => 'EUR',
    'customer' => 'cus_37EGGf4LMGgYy8'
]);

$stripeClient = new StripeClient('my-api-key', '2014-03-28');

$stripeClient = new StripeClient('my-api-key', '2014-03-28');

// Responses will be formatted according to the 2014-03-28 version...

$stripeClient->setApiVersion('2014-08-20');

// Responses will now be formatted according to the 2014-08-20 version...

$client->setApiKey('my-customers-token');
// All API calls will be made on behalf of this customer now!

$details = $client->getCharges([
    'expand' => ['customer']
]);

$iterator = $client->getCustomersIterator();

foreach ($iterator as $user) {
    // Do something
}

$iterator = $client->getEventsIterator(array('type' => 'customer.subscription.updated'));
$iterator->setPageSize(50);
$iterator->setLimit(500);

foreach ($iterator as $event) {
    // Do something
}

$iterator = $client->getInvoicesIterator(['starting_after' => 'in_abcdef');

foreach ($iterator as $invoices) {
    // Do something
}

$key = 'ABC';

$stripeClient->createSubscription([
    'id'              => 'cus_abc',
    'plan'            => 'planA',
    'idempotency_key' => $key
]);

$stripeClient->createSubscription([
    'id'              => 'cus_abc',
    'plan'            => 'planA',
    'idempotency_key' => $key
]);

// Only one subscription is created

$events = $client->getEvents(['object_id' => 'cus_abc', 'type' => 'customer.*']);

$customers = $client->getCustomers(['deleted' => true]);

$notPaidCharges = $client->getCharges(['paid' => false]);

$invoiceItems = $client->getInvoiceItems(['proration' => true]);

use ZfrStripe\Exception\TransactionErrorException;

try {
    $client->createCard([
        'card' => [
            'number'    => '4242424242424242',
            'exp_month' => '01',
            'exp_year'  => '2016'
        ]
    ]);
} catch (CardErrorException $exception) {
    // Seems we couldn't create the card, maybe because it's invalid
    $why = $exception->getMessage();

    // Let's also get the response to have more info:
    $response = $exception->getResponse();
} catch (\Exception $exception) {
    // Catch any other exception...
}
sh
php composer.phar