Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -8061,6 +8061,7 @@
"enum": [
"ALELO",
"AMEX",
"BANCOMAT",
"CONECS",
"CUP",
"DINERS",
Expand Down
8 changes: 8 additions & 0 deletions src/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ private static function castEnumValue($value, $enumClass)
if ($enum !== null) {
return $enum;
}

// The API can return values added after the SDK was generated
// (e.g. a new card network). Enums that declare an UNKNOWN case
// are meant to absorb them instead of failing the whole response.
$unknown = $enumClass::tryFrom('UNKNOWN');
if ($unknown !== null) {
return $unknown;
}
}

if (method_exists($enumClass, 'from')) {
Expand Down
1 change: 1 addition & 0 deletions src/Types/CardResponseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum CardResponseType: string
{
case ALELO = 'ALELO';
case AMEX = 'AMEX';
case BANCOMAT = 'BANCOMAT';
case CONECS = 'CONECS';
case CUP = 'CUP';
case DINERS = 'DINERS';
Expand Down
1 change: 1 addition & 0 deletions src/Types/CardType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum CardType: string
{
case ALELO = 'ALELO';
case AMEX = 'AMEX';
case BANCOMAT = 'BANCOMAT';
case CONECS = 'CONECS';
case CUP = 'CUP';
case DINERS = 'DINERS';
Expand Down
1 change: 1 addition & 0 deletions src/Types/PaymentInstrumentResponseCardType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum PaymentInstrumentResponseCardType: string
{
case ALELO = 'ALELO';
case AMEX = 'AMEX';
case BANCOMAT = 'BANCOMAT';
case CONECS = 'CONECS';
case CUP = 'CUP';
case DINERS = 'DINERS';
Expand Down
1 change: 1 addition & 0 deletions src/Types/TransactionHistoryCardType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum TransactionHistoryCardType: string
{
case ALELO = 'ALELO';
case AMEX = 'AMEX';
case BANCOMAT = 'BANCOMAT';
case CONECS = 'CONECS';
case CUP = 'CUP';
case DINERS = 'DINERS';
Expand Down
24 changes: 24 additions & 0 deletions tests/HydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PHPUnit\Framework\TestCase;
use SumUp\Hydrator;
use SumUp\Types\CardResponse;
use SumUp\Types\CardResponseType;
use SumUp\Types\Checkout;
use SumUp\Types\CheckoutCurrency;
use SumUp\Types\MandateResponse;
Expand Down Expand Up @@ -79,6 +81,28 @@ public function testHydrateArrayItemsFromDocblockClassNames()
$this->assertSame('https://example.test/2', $response->links[1]->href);
}

public function testHydrateBancomatCardType()
{
$card = Hydrator::hydrate([
'type' => 'BANCOMAT',
], CardResponse::class);

$this->assertInstanceOf(CardResponse::class, $card);
$this->assertSame(CardResponseType::BANCOMAT, $card->type);
}

public function testHydrateUnknownValueOfEnumWithUnknownCaseFallsBackToUnknown()
{
$card = Hydrator::hydrate([
'type' => 'SOME_FUTURE_NETWORK',
'last_4_digits' => '1234',
], CardResponse::class);

$this->assertInstanceOf(CardResponse::class, $card);
$this->assertSame(CardResponseType::UNKNOWN, $card->type);
$this->assertSame('1234', $card->last4Digits);
}

public function testHydrateInvalidBackedEnumValueThrowsValueError()
{
$this->expectException(\ValueError::class);
Expand Down