-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ContactSubscriptions, SubscriptionTypes and LoyaltyTokens to Regi…
…ster resources (#28) * Add ContactSubscriptions, SubscriptionTypes and LoyaltyTokens to Register resources * Remove ununsed getId()
- Loading branch information
Showing
10 changed files
with
184 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Piggy\Api\Resources\Register; | ||
|
||
use Piggy\Api\Resources\Shared\BaseContactSubscriptionsResource; | ||
|
||
class ContactSubscriptionsResource extends BaseContactSubscriptionsResource | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $resourceUri = '/api/v3/register/contact-subscriptions'; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Resources/Register/Loyalty/Tokens/LoyaltyTokensResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Piggy\Api\Resources\Register\Loyalty\Tokens; | ||
|
||
use Piggy\Api\Exceptions\PiggyRequestException; | ||
use Piggy\Api\Mappers\Loyalty\Receptions\CreditReceptionMapper; | ||
use Piggy\Api\Models\Loyalty\Receptions\CreditReception; | ||
use Piggy\Api\Resources\BaseResource; | ||
|
||
class LoyaltyTokensResource extends BaseResource | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $resourceUri = '/api/v3/register/loyalty-tokens'; | ||
|
||
/** | ||
* @throws PiggyRequestException | ||
*/ | ||
public function claim(string $version, string $uniqueId, int $timestamp, string $hash, string $contactUuid, ?int $credits = null, ?string $unitName = null, ?float $unitValue = null, ?int $shopId = null, ?string $shopUuid = null): CreditReception | ||
{ | ||
$inputValues = [ | ||
'version' => $version, | ||
'shop_id' => $shopId, | ||
'shop_uuid' => $shopUuid, | ||
'unique_id' => $uniqueId, | ||
'timestamp' => $timestamp, | ||
'hash' => $hash, | ||
'contact_uuid' => $contactUuid, | ||
'credits' => $credits, | ||
'unit_name' => $unitName, | ||
'unit_value' => $unitValue, | ||
]; | ||
|
||
$response = $this->client->post($this->resourceUri, $inputValues); | ||
|
||
$mapper = new CreditReceptionMapper(); | ||
|
||
return $mapper->map($response->getData()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Piggy\Api\Resources\Register; | ||
|
||
use Piggy\Api\Resources\Shared\BaseSubscriptionTypesResource; | ||
|
||
class SubscriptionTypesResource extends BaseSubscriptionTypesResource | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $resourceUri = '/api/v3/register/subscription-types'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Piggy\Api\Resources\Shared; | ||
|
||
use Piggy\Api\Exceptions\PiggyRequestException; | ||
use Piggy\Api\Mappers\Contacts\SubscriptionMapper; | ||
use Piggy\Api\Mappers\Contacts\SubscriptionsMapper; | ||
use Piggy\Api\Models\Contacts\Subscription; | ||
use Piggy\Api\Resources\BaseResource; | ||
|
||
abstract class BaseContactSubscriptionsResource extends BaseResource | ||
{ | ||
/** | ||
* @return Subscription[] | ||
* | ||
* @throws PiggyRequestException | ||
*/ | ||
public function list(string $contactUuid): array | ||
{ | ||
$response = $this->client->get("$this->resourceUri/$contactUuid", [ | ||
'contact_uuid' => $contactUuid, | ||
]); | ||
|
||
$mapper = new SubscriptionsMapper(); | ||
|
||
return $mapper->map($response->getData()); | ||
} | ||
|
||
/** | ||
* @throws PiggyRequestException | ||
*/ | ||
public function subscribe(string $contactUuid, string $subscriptionTypeUuid): Subscription | ||
{ | ||
$response = $this->client->put("$this->resourceUri/$contactUuid/subscribe", [ | ||
'subscription_type_uuid' => $subscriptionTypeUuid, | ||
]); | ||
|
||
$mapper = new SubscriptionMapper(); | ||
|
||
return $mapper->map($response->getData()); | ||
} | ||
|
||
/** | ||
* @throws PiggyRequestException | ||
*/ | ||
public function unsubscribe(string $contactUuid, string $subscriptionTypeUuid): Subscription | ||
{ | ||
$response = $this->client->put("$this->resourceUri/$contactUuid/unsubscribe", [ | ||
'subscription_type_uuid' => $subscriptionTypeUuid, | ||
]); | ||
|
||
$mapper = new SubscriptionMapper(); | ||
|
||
return $mapper->map($response->getData()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Piggy\Api\Resources\Shared; | ||
|
||
use Piggy\Api\Exceptions\PiggyRequestException; | ||
use Piggy\Api\Mappers\Contacts\SubscriptionTypesMapper; | ||
use Piggy\Api\Models\Contacts\SubscriptionType; | ||
use Piggy\Api\Resources\BaseResource; | ||
|
||
abstract class BaseSubscriptionTypesResource extends BaseResource | ||
{ | ||
/** | ||
* @return SubscriptionType[] | ||
* | ||
* @throws PiggyRequestException | ||
*/ | ||
public function list(): array | ||
{ | ||
$response = $this->client->get($this->resourceUri); | ||
|
||
$mapper = new SubscriptionTypesMapper(); | ||
|
||
return $mapper->map($response->getData()); | ||
} | ||
} |