PHP code example of jacobbennett / stripe-test-token

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

    

jacobbennett / stripe-test-token example snippets




use JacobBennett\StripeTestToken;
use Stripe\Charge;

StripeTestToken::setApiKey('your_stripe_secret_test_key');

// Fake a Successful Charge

Charge::create([
        'amount' => 500,
        'currency' => 'usd',
        'source' => StripeTestToken::validVisa(),
]);


// Fake a Failing Charge

try {

        Charge::create([
                'amount' => 500,
                'currency' => 'usd',
                'source' => StripeTestToken::cvcFail(),
        ]);

} catch (\Stripe\Error\Card $e) {
        // handle errors
}


 

\JacobBennett\StripeCardNumber::validVisa(); // Returns the valid Visa card number 4012888888881881
\JacobBennett\StripeTestToken::validVisa(); // Attempts to generate a token against the Stripe API for a valid Visa card