Skip to content
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"require-dev": {
"ext-openssl": "*",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpunit/phpunit": "^5.7.27 || ^9.6.10",
"phpunit/phpunit": "^5.7 || ^7.5 || ^8.5 || ^9.5",
"psx/cache": "^v1.0.2"
},
"autoload": {
Expand Down
24 changes: 24 additions & 0 deletions examples/Notifications/AllNotificationsExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use PSX\Cache\SimpleCache;
use Tpay\Example\ExamplesConfig;
use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment;
use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasRegister;
use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUnregister;
use Tpay\OpenApi\Model\Objects\NotificationBody\MarketplaceTransaction;
use Tpay\OpenApi\Model\Objects\NotificationBody\Tokenization;
use Tpay\OpenApi\Model\Objects\NotificationBody\TokenUpdate;
Expand Down Expand Up @@ -81,6 +83,28 @@ public function getVerifiedNotification()
// $marketplaceTransactionProcessor->process($notification)
exit('{"result":true}');
}
if ($notification instanceof BlikAliasRegister) {
// Notification about successful blik alias registered

$value = $notification->value->getValue();
// The above example will check the notification and return the value for future transactions,
// correlate this value with the payer/user of your system for subsequent payment handling
// You can access any notification field by $notification->fieldName

// $blikAliasRegisteredProcessor->process($notification)
exit('TRUE');
}

if ($notification instanceof BlikAliasUnregister) {
// Notification about successful blik alias unregistered

$value = $notification->value->getValue();
// The above example will check the notification and return the value of deleted token
// You can access any notification field by $notification->fieldName

// $blikAliasRegisteredProcessor->process($notification)
exit('TRUE');
}

// Ignore and silence other notification types if not expected
http_response_code(404);
Expand Down
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/BlikAlias/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\BlikAlias;

use Tpay\OpenApi\Model\Fields\Field;

class Event extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/BlikAlias/ExpirationDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\BlikAlias;

use Tpay\OpenApi\Model\Fields\Field;

class ExpirationDate extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/BlikAlias/Id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\BlikAlias;

use Tpay\OpenApi\Model\Fields\Field;

class Id extends Field
{
protected $name = __CLASS__;
protected $type = self::INT;
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/BlikAlias/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\BlikAlias;

use Tpay\OpenApi\Model\Fields\Field;

class Type extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/BlikAlias/Value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\BlikAlias;

use Tpay\OpenApi\Model\Fields\Field;

class Value extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Tpay\OpenApi\Model\Objects\NotificationBody\BlikAlias;

use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\ExpirationDate;
use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Type;
use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Value;
use Tpay\OpenApi\Model\Objects\Objects;

class BlikAliasRegisterItem extends Objects
{
const OBJECT_FIELDS = [
'value' => Value::class,
'type' => Type::class,
'expirationDate' => ExpirationDate::class,
];

/** @var Value */
public $value;

/** @var Type */
public $type;

/** @var ExpirationDate */
public $expirationDate;

public function getRequiredFields()
{
return [
$this->value,
$this->type,
$this->expirationDate,
];
}

public function toArray()
{
return [
'value' => $this->value->getValue(),
'type' => $this->type->getValue(),
'expirationDate' => $this->expirationDate->getValue(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Tpay\OpenApi\Model\Objects\NotificationBody\BlikAlias;

use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Type;
use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Value;
use Tpay\OpenApi\Model\Objects\Objects;

class BlikAliasUnregisterItem extends Objects
{
const OBJECT_FIELDS = [
'value' => Value::class,
'type' => Type::class,
];

/** @var Value */
public $value;

/** @var Type */
public $type;

public function getRequiredFields()
{
return [
$this->value,
$this->type,
];
}

public function toArray()
{
return [
'value' => $this->value->getValue(),
'type' => $this->type->getValue(),
];
}
}
40 changes: 40 additions & 0 deletions src/Model/Objects/NotificationBody/BlikAliasRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Tpay\OpenApi\Model\Objects\NotificationBody;

use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Event;
use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Id;
use Tpay\OpenApi\Model\Fields\Notification\Md5sum;
use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAlias\BlikAliasRegisterItem;
use Tpay\OpenApi\Model\Objects\Objects;

class BlikAliasRegister extends Objects
{
const OBJECT_FIELDS = [
'id' => Id::class,
'event' => Event::class,
'msg_value' => [BlikAliasRegisterItem::class],
'md5sum' => Md5sum::class,
];

/** @var Id */
public $id;

/** @var Event */
public $event;

/** @var BlikAliasRegisterItem */
public $msg_value;

/** @var Md5sum */
public $md5sum;

public function getRequiredFields()
{
return [
$this->id,
$this->event,
$this->msg_value,
];
}
}
40 changes: 40 additions & 0 deletions src/Model/Objects/NotificationBody/BlikAliasUnregister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Tpay\OpenApi\Model\Objects\NotificationBody;

use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Event;
use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Id;
use Tpay\OpenApi\Model\Fields\Notification\Md5sum;
use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAlias\BlikAliasUnregisterItem;
use Tpay\OpenApi\Model\Objects\Objects;

class BlikAliasUnregister extends Objects
{
const OBJECT_FIELDS = [
'id' => Id::class,
'event' => Event::class,
'msg_value' => [BlikAliasUnregisterItem::class],
'md5sum' => Md5sum::class,
];

/** @var Id */
public $id;

/** @var Event */
public $event;

/** @var BlikAliasUnregisterItem */
public $msg_value;

/** @var Md5sum */
public $md5sum;

public function getRequiredFields()
{
return [
$this->id,
$this->event,
$this->msg_value,
];
}
}
25 changes: 20 additions & 5 deletions src/Utilities/RequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

class RequestParser
{
/** @var null|string */
private $rawBody;

/** @return string */
public function getContentType()
{
return $_SERVER['CONTENT_TYPE'] ?: '';
return isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '';
}

/**
Expand All @@ -17,11 +20,14 @@ public function getContentType()
*/
public function getParsedContent()
{
if ('application/json' === $this->getContentType()) {
$body = file_get_contents('php://input');
if (false !== strpos($this->getContentType(), 'application/json')) {
$body = $this->getRawBody();
$jsonData = json_decode($body, true);

if (is_null($jsonData)) {
throw new TpayException('Invalid JSON body. Json Error: '.json_last_error_msg().' Body: '.$body);
throw new TpayException(
'Invalid JSON body. Json Error: '.json_last_error_msg().' Body: '.$body
);
}

return $jsonData;
Expand All @@ -33,7 +39,7 @@ public function getParsedContent()
/** @return string */
public function getPayload()
{
return file_get_contents('php://input');
return $this->getRawBody();
}

/**
Expand All @@ -50,4 +56,13 @@ public function getSignature()

return $jws;
}

private function getRawBody()
{
if (null === $this->rawBody) {
$this->rawBody = file_get_contents('php://input');
}

return $this->rawBody;
}
}
Loading