From 19e44bb234973c205dfc9e53503c92705ff5bc42 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Tue, 17 Jan 2017 15:28:57 -0500 Subject: [PATCH] 61 - When Interfaces Aren't Enough --- app/Billing/StripePaymentGateway.php | 2 +- tests/unit/Billing/StripePaymentGatewayTest.php | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/Billing/StripePaymentGateway.php b/app/Billing/StripePaymentGateway.php index 0022d26..1d945da 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) { - throw new PaymentFailedException; + return false; } } } diff --git a/tests/unit/Billing/StripePaymentGatewayTest.php b/tests/unit/Billing/StripePaymentGatewayTest.php index 7722700..764e22f 100644 --- a/tests/unit/Billing/StripePaymentGatewayTest.php +++ b/tests/unit/Billing/StripePaymentGatewayTest.php @@ -28,15 +28,9 @@ class StripePaymentGatewayTest extends TestCase /** @test */ function charges_with_an_invalid_payment_token_fail() { - 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."); + $paymentGateway = new StripePaymentGateway(config('services.stripe.secret')); + $result = $paymentGateway->charge(2500, 'invalid-payment-token'); + $this->assertFalse($result); } private function lastCharge()