Skip to content

Commit

Permalink
Merge pull request #44 from freerkminnema/patch-3
Browse files Browse the repository at this point in the history
Add methods to get Giftcard by its UUID
  • Loading branch information
EdingerMike authored Nov 14, 2024
2 parents 7c4c45f + 76ba48a commit 058a0e9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Models/Giftcards/Giftcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ public function getId(): ?int
return $this->id;
}

/**
* @param mixed[] $params
*
* @throws MaintenanceModeException|GuzzleException|PiggyRequestException
*/
public static function get(string $giftcardUuid, array $params = []): Giftcard
{
$response = ApiClient::get(self::resourceUri."/$giftcardUuid", $params);

return GiftcardMapper::map($response->getData());
}

/**
* @param mixed[] $params
*
Expand Down
12 changes: 12 additions & 0 deletions src/Resources/OAuth/Giftcards/GiftcardsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class GiftcardsResource extends BaseResource
*/
protected $resourceUri = '/api/v3/oauth/clients/giftcards';

/**
* @throws PiggyRequestException
*/
public function get(string $giftcardUuid): Giftcard
{
$response = $this->client->get("$this->resourceUri/$giftcardUuid");

$mapper = new GiftcardMapper();

return $mapper->map($response->getData());
}

/**
* @throws PiggyRequestException
*/
Expand Down
38 changes: 37 additions & 1 deletion tests/OAuth/Giftcards/GiftcardsResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@

class GiftcardsResourceTest extends OAuthTestCase
{
/**
* @test
*
* @throws GuzzleException
* @throws PiggyRequestException
* @throws MaintenanceModeException
*/
public function it_gets_a_giftcard()
{
$this->addExpectedResponse([
'uuid' => '00a8878d-5d51-405f-a0c0-34e1863785f1',
'hash' => 'FOOBAR',
'amount_in_cents' => 321,
'type' => 'DIGITAL',
'active' => true,
'upgradeable' => false,
'expiration_date' => '2130-06-13T12:09:00+00:00',
'giftcard_program' => [
'name' => 'My Giftcards',
'active' => 'true',
'uuid' => 'ea7c5a55-1df5-45cc-868e-343947b6b3b4',
],
]);

$giftcard = $this->mockedClient->giftcards->get('00a8878d-5d51-405f-a0c0-34e1863785f1');

$this->assertEquals('00a8878d-5d51-405f-a0c0-34e1863785f1', $giftcard->getUuid());
$this->assertEquals('FOOBAR', $giftcard->getHash());
$this->assertEquals(321, $giftcard->getAmountInCents());
$this->assertEquals('DIGITAL', GiftcardType::byValue($giftcard->getType())->getName());
$this->assertEquals(true, $giftcard->isActive());
$this->assertEquals(false, $giftcard->isUpgradeable());
$this->assertEquals('ea7c5a55-1df5-45cc-868e-343947b6b3b4', $giftcard->getGiftcardProgram()->getUuid());
$this->assertEquals('My Giftcards', $giftcard->getGiftcardProgram()->getName());
}

/**
* @test
*
Expand All @@ -30,7 +66,7 @@ public function it_finds_a_giftcard_by_hash()
],
]);

$giftcard = $this->mockedClient->giftcards->findOneBy('GJ2P725oe');
$giftcard = $this->mockedClient->giftcards->get('123-123');

$this->assertEquals('123-123', $giftcard->getUuid());
$this->assertEquals('GJ2P725oe', $giftcard->getHash());
Expand Down

0 comments on commit 058a0e9

Please sign in to comment.