Advertisement
bennyp

Untitled

Mar 22nd, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1.    try {
  2.          $charge = \Stripe\Charge::create(array(
  3.            'amount' => $amount, // amount in cents, again
  4.            'currency' => 'usd',
  5.            'source' => $token,
  6.            'description' => 'one-time', )
  7.          );
  8.  
  9.          echo json_encode($charge);
  10.      } catch (Stripe\Error\Base $e) {
  11.          // Code to do something with the $e exception object when an error occurs
  12.          echo json_encode($e->getJsonBody());
  13.         //  echo json_encode($e);
  14.      } catch (\Stripe\Error\Card $e) {
  15.          // Since it's a decline, \Stripe\Error\Card will be caught
  16.          echo json_encode($e->getJsonBody());
  17.      } catch (\Stripe\Error\RateLimit $e) {
  18.          // Too many requests made to the API too quickly
  19.          echo json_encode($e->getJsonBody());
  20.      } catch (\Stripe\Error\InvalidRequest $e) {
  21.          // Invalid parameters were supplied to Stripe's API
  22.          echo json_encode($e->getJsonBody());
  23.      } catch (\Stripe\Error\Authentication $e) {
  24.          // Authentication with Stripe's API failed
  25.          // (maybe you changed API keys recently)
  26.          echo json_encode($e->getJsonBody());
  27.      } catch (\Stripe\Error\ApiConnection $e) {
  28.          // Network communication with Stripe failed
  29.          echo json_encode($e->getJsonBody());
  30.      } catch (\Stripe\Error\Base $e) {
  31.          // Display a very generic error to the user, and maybe send
  32.          // yourself an email
  33.          echo json_encode($e->getJsonBody());
  34.      } catch (Exception $e) {
  35.          // Something else happened, completely unrelated to Stripe
  36.          echo json_encode($e->getJsonBody());
  37.      }
  38.  } catch (Exception $e) {
  39.      // One or more variables was NULL
  40.    echo json_encode($e->getJsonBody());
  41.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement