59 - Handling Invalid Payment Tokens

This commit is contained in:
Adam Wathan
2016-12-30 16:51:27 -05:00
parent 874f63872a
commit 8d96de356c
2 changed files with 25 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Billing;
use Stripe\Charge;
use Stripe\Error\InvalidRequest;
class StripePaymentGateway implements PaymentGateway
{
@@ -15,10 +16,14 @@ class StripePaymentGateway implements PaymentGateway
public function charge($amount, $token)
{
Charge::create([
'amount' => $amount,
'source' => $token,
'currency' => 'usd',
], ['api_key' => $this->apiKey]);
try {
Charge::create([
'amount' => $amount,
'source' => $token,
'currency' => 'usd',
], ['api_key' => $this->apiKey]);
} catch (InvalidRequest $e) {
throw new PaymentFailedException;
}
}
}