From 57a2b0b2de1bbe35ff190c8f780032dd91d168a3 Mon Sep 17 00:00:00 2001 From: Joe Cohen Date: Thu, 1 Jun 2023 00:20:35 -0400 Subject: [PATCH 1/2] Update OpenPayGateway.php --- src/Gateways/OpenPay/OpenPayGateway.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Gateways/OpenPay/OpenPayGateway.php b/src/Gateways/OpenPay/OpenPayGateway.php index f8dfdee..d8a7933 100755 --- a/src/Gateways/OpenPay/OpenPayGateway.php +++ b/src/Gateways/OpenPay/OpenPayGateway.php @@ -310,9 +310,6 @@ protected function getStatus(array $response) protected function getErrorCode(array $response) { $code = Arr::get($response, 'error_code', 1001); - if (!isset($codeMap[$code])) { - $code = 1001; - } $codeMap = [ 1000 => 'processing_error', // OpenPay internal server error @@ -348,6 +345,10 @@ protected function getErrorCode(array $response) 3012 => 'card_declined', // A bank authorization is required to make this payment 4001 => 'insufficient_funds', // The Openpay account has not enough ]; + + if (!isset($codeMap[$code])) { + $code = 1001; + } return new ErrorCode($codeMap[$code]); } From 16313083dffe5442f6e3f036b541d80cd7cd8c14 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 1 Jun 2023 04:20:56 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/Gateways/OpenPay/Events.php | 24 ++++++++++++------- src/Gateways/OpenPay/OpenPayGateway.php | 2 +- src/Gateways/PaypalPlus/PaypalPlusGateway.php | 8 +++---- src/Gateways/Stripe/StripeGateway.php | 2 +- tests/ErrorCodeTest.php | 1 + tests/FactoryTest.php | 4 ++++ tests/Functional/Charges/ConektaTest.php | 7 ++++++ tests/Functional/Charges/MercadoPagoTest.php | 2 ++ tests/Functional/Charges/OpenPayTest.php | 2 ++ tests/Functional/Charges/PaypalPlusTest.php | 2 ++ tests/Functional/Charges/SrPagoTest.php | 6 +++++ tests/Functional/Events/ConektaTest.php | 1 + tests/Functional/Webhooks/PaypalPlusTest.php | 2 ++ tests/Functional/Webhooks/StripeTest.php | 1 + tests/PayMeTest.php | 11 ++++++++- tests/StatusTest.php | 1 + tests/Support/ArrTest.php | 1 + 17 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/Gateways/OpenPay/Events.php b/src/Gateways/OpenPay/Events.php index 5dbe6e8..aebc29d 100755 --- a/src/Gateways/OpenPay/Events.php +++ b/src/Gateways/OpenPay/Events.php @@ -50,16 +50,19 @@ public function find($id, array $options = []) case 'charge.cancelled': case 'charge.failed': case 'charge.rescored.to.decline': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'chargeback.created': case 'chargeback.accepted': case 'chargeback.rejected': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'fee.refund.succeeded': case 'fee.succeeded': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'order.activated': case 'order.cancelled': @@ -68,21 +71,26 @@ public function find($id, array $options = []) case 'order.expired': case 'order.payment.cancelled': case 'order.payment.received': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'payout.created': case 'payout.failed': case 'payout.succeeded': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'spei.received': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'subscription.charge.failed': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; case 'transfer.succeeded': - $endpoint = 'charges'; break; + $endpoint = 'charges'; + break; } if (!$endpoint) { diff --git a/src/Gateways/OpenPay/OpenPayGateway.php b/src/Gateways/OpenPay/OpenPayGateway.php index d8a7933..7043dbb 100755 --- a/src/Gateways/OpenPay/OpenPayGateway.php +++ b/src/Gateways/OpenPay/OpenPayGateway.php @@ -345,7 +345,7 @@ protected function getErrorCode(array $response) 3012 => 'card_declined', // A bank authorization is required to make this payment 4001 => 'insufficient_funds', // The Openpay account has not enough ]; - + if (!isset($codeMap[$code])) { $code = 1001; } diff --git a/src/Gateways/PaypalPlus/PaypalPlusGateway.php b/src/Gateways/PaypalPlus/PaypalPlusGateway.php index 01c1109..0822a21 100644 --- a/src/Gateways/PaypalPlus/PaypalPlusGateway.php +++ b/src/Gateways/PaypalPlus/PaypalPlusGateway.php @@ -411,13 +411,13 @@ protected function getPaymentStatus($status) return new Status('refunded'); case 'denied': return new Status('declined'); - // payment general status + // payment general status case 'created': case 'approved': return new Status('pending'); case 'failed': return new Status('failed'); - // IPN status + // IPN status case 'Completed': case 'Processed': return new Status('paid'); @@ -460,11 +460,11 @@ protected function getErrorCode($error) case 'INTERNAL_SERVICE_ERROR': return new ErrorCode('processing_error'); - // Bank decline, payment no approved + // Bank decline, payment no approved case 'INSTRUMENT_DECLINED': return new ErrorCode('card_declined'); - // PayPal risk decline, payment not approved + // PayPal risk decline, payment not approved case 'CREDIT_CARD_REFUSED': case 'TRANSACTION_REFUSED_BY_PAYPAL_RISK': return new ErrorCode('suspected_fraud'); diff --git a/src/Gateways/Stripe/StripeGateway.php b/src/Gateways/Stripe/StripeGateway.php index 5113f49..4fc4f5d 100644 --- a/src/Gateways/Stripe/StripeGateway.php +++ b/src/Gateways/Stripe/StripeGateway.php @@ -217,7 +217,7 @@ protected function getStatus(array $response) case 'requires_confirmation': return new Status('pending'); - // When the PaymentIntent is created or if the payment attempt fails + // When the PaymentIntent is created or if the payment attempt fails case 'requires_payment_method': $isRecent = $response['last_payment_error'] === null; diff --git a/tests/ErrorCodeTest.php b/tests/ErrorCodeTest.php index 13261e7..0cfe49d 100644 --- a/tests/ErrorCodeTest.php +++ b/tests/ErrorCodeTest.php @@ -16,6 +16,7 @@ public function it_returns_a_valid_status() /** * @test + * * @expectedException InvalidArgumentException */ public function it_throws_exception_when_invalid_status() diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 90b9426..af1ad13 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -20,7 +20,9 @@ protected function setUp() /** * @test + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage A gateway must be specified. */ public function it_throws_if_no_driver_specified() @@ -30,7 +32,9 @@ public function it_throws_if_no_driver_specified() /** * @test + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Unsupported gateway [bar]. */ public function it_thorws_on_not_gateway_supported() diff --git a/tests/Functional/Charges/ConektaTest.php b/tests/Functional/Charges/ConektaTest.php index 2e78457..eb478e6 100644 --- a/tests/Functional/Charges/ConektaTest.php +++ b/tests/Functional/Charges/ConektaTest.php @@ -33,6 +33,7 @@ public function it_should_create_a_new_customer() /** * @test + * * @depends it_should_create_a_new_customer */ public function it_should_succeed_to_charge_an_order_with_customer_token($data) @@ -57,6 +58,7 @@ public function it_should_succeed_to_charge_an_order_with_customer_token($data) /** * @test + * * @depends it_should_create_a_new_customer */ public function it_should_find_a_customer($data) @@ -74,6 +76,7 @@ public function it_should_find_a_customer($data) /** * @test + * * @depends it_should_find_a_customer */ public function it_should_create_a_customer_card($data) @@ -96,6 +99,7 @@ public function it_should_create_a_customer_card($data) /** * @test + * * @depends it_should_create_a_customer_card */ public function it_should_update_a_customer($data) @@ -118,6 +122,7 @@ public function it_should_update_a_customer($data) /** * @test + * * @depends it_should_update_a_customer */ public function it_should_delete_a_customer_card($data) @@ -234,6 +239,7 @@ public function it_should_succeed_to_charge_an_order_with_card_token() /** * @test + * * @depends it_should_succeed_to_charge_an_order_with_card_token */ public function it_should_succeed_to_fully_refund_a_charge($prevResponse) @@ -254,6 +260,7 @@ public function it_should_succeed_to_fully_refund_a_charge($prevResponse) /** * @test + * * @depends it_should_succeed_to_charge_an_order_with_card_token */ public function it_should_succeed_to_partially_refund_a_charge() diff --git a/tests/Functional/Charges/MercadoPagoTest.php b/tests/Functional/Charges/MercadoPagoTest.php index 6d8e359..56d4326 100644 --- a/tests/Functional/Charges/MercadoPagoTest.php +++ b/tests/Functional/Charges/MercadoPagoTest.php @@ -125,6 +125,7 @@ public function it_should_fail_charging_with_invalid_access_key() /** * @test + * * @depends it_should_succeed_to_charge_a_token_with_params * * @param array $responseAndAmount @@ -148,6 +149,7 @@ public function it_should_succeed_to_refund_a_charge($responseAndAmount) /** * @test + * * @depends it_should_succeed_to_create_a_charge_with_ticket * * @param array $dataAndAmount diff --git a/tests/Functional/Charges/OpenPayTest.php b/tests/Functional/Charges/OpenPayTest.php index bdabca6..8d7924a 100644 --- a/tests/Functional/Charges/OpenPayTest.php +++ b/tests/Functional/Charges/OpenPayTest.php @@ -95,6 +95,7 @@ public function it_should_succeed_to_charge_a_token_with_params() /** * @test + * * @depends it_should_succeed_to_charge_a_token_with_params * * @param array $dataAndAmount @@ -115,6 +116,7 @@ public function it_should_retrieve_a_single_event($dataAndAmount) /** * @test + * * @depends it_should_succeed_to_charge_a_token_with_params * * @param array $responseAndAmount diff --git a/tests/Functional/Charges/PaypalPlusTest.php b/tests/Functional/Charges/PaypalPlusTest.php index b301795..64014de 100644 --- a/tests/Functional/Charges/PaypalPlusTest.php +++ b/tests/Functional/Charges/PaypalPlusTest.php @@ -44,6 +44,7 @@ public function it_should_generate_a_token() /** * @test + * * @depends it_should_generate_a_token * * @param string $token @@ -68,6 +69,7 @@ public function it_should_succeed_to_request_a_charge($token) /** * @test + * * @depends it_should_generate_a_token * * @param string $token diff --git a/tests/Functional/Charges/SrPagoTest.php b/tests/Functional/Charges/SrPagoTest.php index e60ac42..81c774d 100644 --- a/tests/Functional/Charges/SrPagoTest.php +++ b/tests/Functional/Charges/SrPagoTest.php @@ -80,6 +80,7 @@ public function it_should_succeed_to_create_a_new_customer() /** * @test + * * @depends it_should_succeed_to_create_a_new_customer * */ public function it_should_update_customer_information($data) @@ -100,6 +101,7 @@ public function it_should_update_customer_information($data) /** * @test + * * @depends it_should_succeed_to_create_a_new_customer */ public function it_should_add_card_to_a_customer($data) @@ -122,6 +124,7 @@ public function it_should_add_card_to_a_customer($data) /** * @test + * * @depends it_should_succeed_to_create_a_new_customer */ public function it_should_find_a_customer($data) @@ -135,6 +138,7 @@ public function it_should_find_a_customer($data) /** * @test + * * @depends it_should_succeed_to_create_a_new_customer */ public function it_should_delete_a_customer($data) @@ -183,6 +187,7 @@ private function getValidTestToken($attributes = []) /** * @test + * * @expectedException BadMethodCallException */ public function it_throws_charge_complete_method_call() @@ -192,6 +197,7 @@ public function it_throws_charge_complete_method_call() /** * @test + * * @expectedException BadMethodCallException */ public function it_throws_charge_refund_method_call() diff --git a/tests/Functional/Events/ConektaTest.php b/tests/Functional/Events/ConektaTest.php index 7330fa9..0b4afdf 100644 --- a/tests/Functional/Events/ConektaTest.php +++ b/tests/Functional/Events/ConektaTest.php @@ -21,6 +21,7 @@ public function it_should_retrieve_all_events() /** * @test + * * @depends it_should_retrieve_all_events */ public function it_should_retrieve_a_single_event($events) diff --git a/tests/Functional/Webhooks/PaypalPlusTest.php b/tests/Functional/Webhooks/PaypalPlusTest.php index 2bf0a3f..c1b270c 100644 --- a/tests/Functional/Webhooks/PaypalPlusTest.php +++ b/tests/Functional/Webhooks/PaypalPlusTest.php @@ -24,6 +24,7 @@ public function it_should_generate_a_token() /** * @test + * * @depends it_should_generate_a_token * * @param string $token @@ -43,6 +44,7 @@ public function it_should_get_all_hooks($token) /** * @test + * * @depends it_should_get_all_hooks */ public function it_should_create_and_delete_a_webhook($token) diff --git a/tests/Functional/Webhooks/StripeTest.php b/tests/Functional/Webhooks/StripeTest.php index e2ecced..7e11943 100644 --- a/tests/Functional/Webhooks/StripeTest.php +++ b/tests/Functional/Webhooks/StripeTest.php @@ -34,6 +34,7 @@ public function it_should_create_a_webhook() /** * @test + * * @depends it_should_create_a_webhook */ public function it_should_delete_a_webhook($hookId) diff --git a/tests/PayMeTest.php b/tests/PayMeTest.php index 7654d75..9a04c04 100644 --- a/tests/PayMeTest.php +++ b/tests/PayMeTest.php @@ -16,16 +16,19 @@ public function it_gets_the_verson() /** * @test + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage A gateway must be specified. */ public function it_throws_if_no_driver_specified() { - (new PayMe([])); + new PayMe([]); } /** * @expectedException InvalidArgumentException + * * @expectedExceptionMessage A gateway must be specified. */ public function it_throws_if_no_driver_specified_on_make() @@ -35,7 +38,9 @@ public function it_throws_if_no_driver_specified_on_make() /** * @test + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage Unsupported gateway [foo]. */ public function it_thorws_on_not_gateway_supported() @@ -45,7 +50,9 @@ public function it_thorws_on_not_gateway_supported() /** * @test + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage Unsupported gateway [bar]. */ public function it_thorws_on_not_factory_specified() @@ -108,7 +115,9 @@ public function it_can_call_an_api_class_on_multiple_gateways() /** * @test + * * @expectedException BadMethodCallException + * * @expectedExceptionMessage Undefined method [foo] called. */ public function it_throws_on_unsupported_method_for_gateway() diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 8a452e1..b095643 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -16,6 +16,7 @@ public function it_returns_a_valid_status() /** * @test + * * @expectedException InvalidArgumentException */ public function it_throws_exception_when_invalid_status() diff --git a/tests/Support/ArrTest.php b/tests/Support/ArrTest.php index f18ad2d..0636403 100644 --- a/tests/Support/ArrTest.php +++ b/tests/Support/ArrTest.php @@ -22,6 +22,7 @@ public function testArrGet() /** * @test + * * @expectedException InvalidArgumentException */ public function it_validates_array_requires()