Skip to content

Commit

Permalink
Merge pull request #158 from Shoperti/fix-openpay-errorcode
Browse files Browse the repository at this point in the history
Update OpenPayGateway.php
  • Loading branch information
joecohens authored Jun 1, 2023
2 parents 1331d81 + 6c924c5 commit 7e42f0e
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 17 deletions.
24 changes: 16 additions & 8 deletions src/Gateways/OpenPay/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/Gateways/OpenPay/OpenPayGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -349,6 +346,10 @@ protected function getErrorCode(array $response)
4001 => 'insufficient_funds', // The Openpay account has not enough
];

if (!isset($codeMap[$code])) {
$code = 1001;
}

return new ErrorCode($codeMap[$code]);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Gateways/PaypalPlus/PaypalPlusGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Stripe/StripeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions tests/ErrorCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function it_returns_a_valid_status()

/**
* @test
*
* @expectedException InvalidArgumentException
*/
public function it_throws_exception_when_invalid_status()
Expand Down
4 changes: 4 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ protected function setUp()

/**
* @test
*
* @expectedException \InvalidArgumentException
*
* @expectedExceptionMessage A gateway must be specified.
*/
public function it_throws_if_no_driver_specified()
Expand All @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions tests/Functional/Charges/ConektaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Charges/MercadoPagoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Charges/OpenPayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Charges/PaypalPlusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function it_should_generate_a_token()

/**
* @test
*
* @depends it_should_generate_a_token
*
* @param string $token
Expand All @@ -68,6 +69,7 @@ public function it_should_succeed_to_request_a_charge($token)

/**
* @test
*
* @depends it_should_generate_a_token
*
* @param string $token
Expand Down
6 changes: 6 additions & 0 deletions tests/Functional/Charges/SrPagoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -183,6 +187,7 @@ private function getValidTestToken($attributes = [])

/**
* @test
*
* @expectedException BadMethodCallException
*/
public function it_throws_charge_complete_method_call()
Expand All @@ -192,6 +197,7 @@ public function it_throws_charge_complete_method_call()

/**
* @test
*
* @expectedException BadMethodCallException
*/
public function it_throws_charge_refund_method_call()
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/Events/ConektaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Webhooks/PaypalPlusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function it_should_generate_a_token()

/**
* @test
*
* @depends it_should_generate_a_token
*
* @param string $token
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/Functional/Webhooks/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion tests/PayMeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function it_returns_a_valid_status()

/**
* @test
*
* @expectedException InvalidArgumentException
*/
public function it_throws_exception_when_invalid_status()
Expand Down
1 change: 1 addition & 0 deletions tests/Support/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testArrGet()

/**
* @test
*
* @expectedException InvalidArgumentException
*/
public function it_validates_array_requires()
Expand Down

0 comments on commit 7e42f0e

Please sign in to comment.