-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
516 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Api\v1; | ||
|
||
use zaporylie\Vipps\Api\ApiBase; | ||
use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; | ||
use zaporylie\Vipps\Model\EPayment\v1\CancelModificationRequest; | ||
use zaporylie\Vipps\Model\EPayment\v1\CaptureModificationRequest; | ||
use zaporylie\Vipps\Model\EPayment\v1\CreatePaymentRequest; | ||
use zaporylie\Vipps\Model\EPayment\v1\CreatePaymentResponse; | ||
use zaporylie\Vipps\Model\EPayment\v1\GetPaymentResponse; | ||
use zaporylie\Vipps\Model\EPayment\v1\PaymentAdjustResponse; | ||
use zaporylie\Vipps\Model\EPayment\v1\RefundModificationRequest; | ||
use zaporylie\Vipps\Model\Webhook\v1\GetWebhooksResponse; | ||
use zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookRequest; | ||
use zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookResponse; | ||
use zaporylie\Vipps\Resource\EPayment\v1\CapturePayment; | ||
use zaporylie\Vipps\Resource\EPayment\v1\CreatePayment; | ||
use zaporylie\Vipps\Resource\EPayment\v1\GetPayment; | ||
use zaporylie\Vipps\Resource\EPayment\v1\GetPaymentEvents; | ||
use zaporylie\Vipps\Resource\EPayment\v1\CancelPayment; | ||
use zaporylie\Vipps\Resource\EPayment\v1\RefundPayment; | ||
use zaporylie\Vipps\Resource\IdempotencyKeyFactory; | ||
use zaporylie\Vipps\Resource\Webhook\v1\DeleteWebhook; | ||
use zaporylie\Vipps\Resource\Webhook\v1\GetWebhooks; | ||
use zaporylie\Vipps\Resource\Webhook\v1\RegisterWebhook; | ||
use zaporylie\Vipps\VippsInterface; | ||
|
||
/** | ||
* Class Webhook | ||
* | ||
* @package Vipps\Api | ||
*/ | ||
class Webhook extends ApiBase implements WebhookInterface | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $merchantSerialNumber; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $version; | ||
|
||
/** | ||
* Gets merchantSerialNumber value. | ||
* | ||
* @return string | ||
*/ | ||
public function getMerchantSerialNumber() | ||
{ | ||
if (empty($this->merchantSerialNumber)) { | ||
throw new InvalidArgumentException('Missing merchant serial number'); | ||
} | ||
return $this->merchantSerialNumber; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getVersion() | ||
{ | ||
return $this->version; | ||
} | ||
|
||
/** | ||
* Webhook constructor. | ||
* | ||
* Webhook API needs one extra param - merchant serial number. | ||
* | ||
* @param \zaporylie\Vipps\VippsInterface $app | ||
* @param string $subscription_key | ||
* @param $merchant_serial_number | ||
*/ | ||
public function __construct( | ||
VippsInterface $app, | ||
$subscription_key, | ||
$merchant_serial_number | ||
) { | ||
parent::__construct($app, $subscription_key); | ||
$this->merchantSerialNumber = $merchant_serial_number; | ||
$this->version = 'v1'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function registerWebhook(RegisterWebhookRequest $request): RegisterWebhookResponse | ||
{ | ||
$resource = new RegisterWebhook($this->app, $this->getSubscriptionKey(), $request); | ||
return $resource->call(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getWebhooks(): GetWebhooksResponse | ||
{ | ||
$resource = new GetWebhooks($this->app, $this->getSubscriptionKey()); | ||
return $resource->call(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function deleteWebhook(string $reference): void | ||
{ | ||
$resource = new DeleteWebhook($this->app, $this->getSubscriptionKey(), $reference); | ||
$resource->call(); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Api\v1; | ||
|
||
use zaporylie\Vipps\Model\EPayment\v1\CancelModificationRequest; | ||
use zaporylie\Vipps\Model\EPayment\v1\CaptureModificationRequest; | ||
use zaporylie\Vipps\Model\EPayment\v1\CreatePaymentRequest; | ||
use zaporylie\Vipps\Model\EPayment\v1\CreatePaymentResponse; | ||
use zaporylie\Vipps\Model\EPayment\v1\GetPaymentResponse; | ||
use zaporylie\Vipps\Model\EPayment\v1\PaymentAdjustResponse; | ||
use zaporylie\Vipps\Model\EPayment\v1\RefundModificationRequest; | ||
use zaporylie\Vipps\Model\Webhook\v1\GetWebhooksResponse; | ||
use zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookRequest; | ||
use zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookResponse; | ||
|
||
interface WebhookInterface | ||
{ | ||
|
||
/** | ||
* @param \zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookRequest $request | ||
* | ||
* @return \zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookResponse | ||
*/ | ||
public function registerWebhook(RegisterWebhookRequest $request) : RegisterWebhookResponse; | ||
|
||
/** | ||
* @return \zaporylie\Vipps\Model\Webhook\v1\GetWebhooksResponse | ||
*/ | ||
public function getWebhooks() : GetWebhooksResponse; | ||
|
||
/** | ||
* @param string $reference | ||
* | ||
* @return void | ||
*/ | ||
public function deleteWebhook(string $reference) : void; | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Model\Webhook\v1; | ||
|
||
use JMS\Serializer\Annotation as Serializer; | ||
|
||
/** | ||
* Class RegisterWebhookResponse | ||
* | ||
* @package Vipps\Model\Webhook | ||
*/ | ||
class GetWebhooksResponse | ||
{ | ||
|
||
/** | ||
* @var \zaporylie\Vipps\Model\Webhook\v1\Webhook[] | ||
* @Serializer\Type("array<zaporylie\Vipps\Model\Webhook\v1\Webhook>") | ||
*/ | ||
protected $webhooks; | ||
|
||
/** | ||
* Gets webhooks value. | ||
* | ||
* @return \zaporylie\Vipps\Model\Webhook\v1\Webhook[] | ||
*/ | ||
public function getWebhooks(): array { | ||
return $this->webhooks; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Model\Webhook\v1; | ||
|
||
use JMS\Serializer\Annotation as Serializer; | ||
|
||
/** | ||
* Class RegisterWebhookRequest | ||
* | ||
* @package Vipps\Model\Webhook | ||
*/ | ||
class RegisterWebhookRequest | ||
{ | ||
|
||
/** | ||
* @var string | ||
* @Serializer\Type("string") | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* @var array | ||
* @Serializer\Type("array<string>") | ||
*/ | ||
protected $events; | ||
|
||
/** | ||
* Sets url variable. | ||
* | ||
* @param string $url | ||
* | ||
* @return $this | ||
*/ | ||
public function setUrl(string $url) { | ||
$this->url = $url; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets events variable. | ||
* | ||
* @param array $events | ||
* | ||
* @return $this | ||
*/ | ||
public function setEvents(array $events) { | ||
$this->events = $events; | ||
return $this; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Model\Webhook\v1; | ||
|
||
use JMS\Serializer\Annotation as Serializer; | ||
|
||
/** | ||
* Class RegisterWebhookResponse | ||
* | ||
* @package Vipps\Model\Webhook | ||
*/ | ||
class RegisterWebhookResponse | ||
{ | ||
|
||
/** | ||
* @var string | ||
* @Serializer\Type("string") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
* @Serializer\Type("string") | ||
*/ | ||
protected $secret; | ||
|
||
/** | ||
* Gets id value. | ||
* | ||
* @return string | ||
*/ | ||
public function getId(): string { | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Gets secret value. | ||
* | ||
* @return string | ||
*/ | ||
public function getSecret(): string { | ||
return $this->secret; | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Model\Webhook\v1; | ||
|
||
use JMS\Serializer\Annotation as Serializer; | ||
|
||
/** | ||
* Class Webhook | ||
* | ||
* @package Vipps\Model\Webhook | ||
*/ | ||
class Webhook | ||
{ | ||
|
||
/** | ||
* @var string | ||
* @Serializer\Type("string") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
* @Serializer\Type("string") | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* @var array | ||
* @Serializer\Type("array<string>") | ||
*/ | ||
protected $events; | ||
|
||
/** | ||
* Gets id value. | ||
* | ||
* @return string | ||
*/ | ||
public function getId(): string { | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Gets url value. | ||
* | ||
* @return string | ||
*/ | ||
public function getUrl(): string { | ||
return $this->url; | ||
} | ||
|
||
/** | ||
* Gets events value. | ||
* | ||
* @return array | ||
*/ | ||
public function getEvents(): array { | ||
return $this->events; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
namespace zaporylie\Vipps\Resource\Webhook\v1; | ||
|
||
use zaporylie\Vipps\Model\Authorization\ResponseGetToken; | ||
use zaporylie\Vipps\Model\EPayment\v1\EventLog; | ||
use zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookRequest; | ||
use zaporylie\Vipps\Model\Webhook\v1\RegisterWebhookResponse; | ||
use zaporylie\Vipps\Model\Webhook\v1\Webhook; | ||
use zaporylie\Vipps\Resource\AuthorizedResourceBase; | ||
use zaporylie\Vipps\Resource\ResourceBase; | ||
use zaporylie\Vipps\Resource\HttpMethod; | ||
use zaporylie\Vipps\VippsInterface; | ||
|
||
/** | ||
* Class Webhook | ||
* | ||
* @package Vipps\Resource\Webhook | ||
*/ | ||
class DeleteWebhook extends AuthorizedResourceBase | ||
{ | ||
|
||
/** | ||
* @var \zaporylie\Vipps\Resource\HttpMethod; | ||
*/ | ||
protected $method = HttpMethod::DELETE; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $path = '/webhooks/v1/webhooks/{id}'; | ||
|
||
/** | ||
* GetToken constructor. | ||
* | ||
* @param \zaporylie\Vipps\VippsInterface $vipps | ||
* @param string $subscription_key | ||
* @param $reference | ||
*/ | ||
public function __construct(VippsInterface $vipps, $subscription_key, $reference) | ||
{ | ||
parent::__construct($vipps, $subscription_key); | ||
$this->id = $reference; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function call() | ||
{ | ||
$response = $this->makeCall(); | ||
$body = $response->getBody()->getContents(); | ||
return $body; | ||
} | ||
} |
Oops, something went wrong.