diff --git a/app/Billing/StripePaymentGateway.php b/app/Billing/StripePaymentGateway.php index 1d945da..0022d26 100644 --- a/app/Billing/StripePaymentGateway.php +++ b/app/Billing/StripePaymentGateway.php @@ -23,7 +23,7 @@ class StripePaymentGateway implements PaymentGateway 'currency' => 'usd', ], ['api_key' => $this->apiKey]); } catch (InvalidRequest $e) { - return false; + throw new PaymentFailedException; } } } diff --git a/tests/unit/Billing/StripePaymentGatewayTest.php b/tests/unit/Billing/StripePaymentGatewayTest.php index 764e22f..7722700 100644 --- a/tests/unit/Billing/StripePaymentGatewayTest.php +++ b/tests/unit/Billing/StripePaymentGatewayTest.php @@ -28,9 +28,15 @@ class StripePaymentGatewayTest extends TestCase /** @test */ function charges_with_an_invalid_payment_token_fail() { - $paymentGateway = new StripePaymentGateway(config('services.stripe.secret')); - $result = $paymentGateway->charge(2500, 'invalid-payment-token'); - $this->assertFalse($result); + try { + $paymentGateway = new StripePaymentGateway(config('services.stripe.secret')); + $paymentGateway->charge(2500, 'invalid-payment-token'); + } catch (PaymentFailedException $e) { + $this->assertCount(0, $this->newCharges()); + return; + } + + $this->fail("Charging with an invalid payment token did not throw a PaymentFailedException."); } private function lastCharge()