PHP code example of ankurk91 / laravel-stripe-exceptions

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

    

ankurk91 / laravel-stripe-exceptions example snippets




try {
    $response = \Stripe\Charge::create([
        'source' => request('source'),
        'amount' => 1000,
        'currency' => 'usd',
    ]);
} catch (\Throwable $exception) {
    // send back an errored JSON response to browser
    throw new \Ankurk91\StripeExceptions\ApiException($exception);
}



try {
    $response = \Stripe\OAuth::token([
        'grant_type' => 'authorization_code',
        'code' => request('code')
    ]);
} catch (\Throwable $exception) {
    // redirect with failed error message
    // `error` will be flashed in session to destination page
    throw new \Ankurk91\StripeExceptions\OAuthException($exception, route('stripe.failed'));
}
bash
php artisan vendor:publish --provider="Ankurk91\StripeExceptions\StripeServiceProvider" --tag=translations