Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- $charge = \Stripe\Charge::create(array(
- 'amount' => $amount, // amount in cents, again
- 'currency' => 'usd',
- 'source' => $token,
- 'description' => 'one-time', )
- );
- echo json_encode($charge);
- } catch (Stripe\Error\Base $e) {
- // Code to do something with the $e exception object when an error occurs
- echo json_encode($e->getJsonBody());
- // echo json_encode($e);
- } catch (\Stripe\Error\Card $e) {
- // Since it's a decline, \Stripe\Error\Card will be caught
- echo json_encode($e->getJsonBody());
- } catch (\Stripe\Error\RateLimit $e) {
- // Too many requests made to the API too quickly
- echo json_encode($e->getJsonBody());
- } catch (\Stripe\Error\InvalidRequest $e) {
- // Invalid parameters were supplied to Stripe's API
- echo json_encode($e->getJsonBody());
- } catch (\Stripe\Error\Authentication $e) {
- // Authentication with Stripe's API failed
- // (maybe you changed API keys recently)
- echo json_encode($e->getJsonBody());
- } catch (\Stripe\Error\ApiConnection $e) {
- // Network communication with Stripe failed
- echo json_encode($e->getJsonBody());
- } catch (\Stripe\Error\Base $e) {
- // Display a very generic error to the user, and maybe send
- // yourself an email
- echo json_encode($e->getJsonBody());
- } catch (Exception $e) {
- // Something else happened, completely unrelated to Stripe
- echo json_encode($e->getJsonBody());
- }
- } catch (Exception $e) {
- // One or more variables was NULL
- echo json_encode($e->getJsonBody());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement