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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"psr/log": "^1 || ^2 || ^3"
},
"require-dev": {
"ext-openssl": "*",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpunit/phpunit": "^5.7.27 || ^9.6.10"
},
Expand Down
85 changes: 85 additions & 0 deletions examples/Notifications/AllNotificationsExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Tpay\Example\Notifications;

use Tpay\Example\ExamplesConfig;
use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment;
use Tpay\OpenApi\Model\Objects\NotificationBody\MarketplaceTransaction;
use Tpay\OpenApi\Model\Objects\NotificationBody\Tokenization;
use Tpay\OpenApi\Model\Objects\NotificationBody\TokenUpdate;
use Tpay\OpenApi\Model\Objects\Objects;
use Tpay\OpenApi\Utilities\TpayException;
use Tpay\OpenApi\Webhook\JWSVerifiedPaymentNotification;

final class AllNotificationsExample extends ExamplesConfig
{
/**
* Returns validated object with set parameters
*
* @return Objects
*/
public function getVerifiedNotification()
{
// if isProd == false -> use sandbox credentials.
$isProd = true;
$NotificationWebhook = new JWSVerifiedPaymentNotification(self::MERCHANT_CONFIRMATION_CODE, $isProd);

return $NotificationWebhook->getNotification();
}
}

try {
// if there is no exception - notification is checked and ready to use.
$notification = (new AllNotificationsExample())->getVerifiedNotification();
if ($notification instanceof BasicPayment) {
// Notification about successful payment

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

$notificationArray = $notification->getNotificationAssociative();
// The above method will get the notification as an associative array.
// You can access notification field value by $notificationArray['fieldName']

// $successfulPaymentProcessor->process($notification)
exit('TRUE');
}
if ($notification instanceof Tokenization) {
// Notification about successful card tokenization

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

// $tokenizationProcessor->process($notification)
exit('{"result":true}');
}
if ($notification instanceof TokenUpdate) {
// Notification about card token update

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

// $tokenUpdateProcessor->process($notification)
exit('{"result":true}');
}
if ($notification instanceof MarketplaceTransaction) {
// Notification about successful marketplace payment

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

// $marketplaceTransactionProcessor->process($notification)
exit('{"result":true}');
}

// Ignore and silence other notification types if not expected
http_response_code(404);
exit('FALSE');
} catch (TpayException $exception) {
// handle your exception here
exit('FALSE');
}
22 changes: 14 additions & 8 deletions examples/Notifications/PaymentNotificationExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ public function getVerifiedNotification()
try {
// if there is no exception - notification is checked and ready to use.
$notification = (new PaymentNotificationExample())->getVerifiedNotification();
var_dump($notification->tr_id->getValue());
// The above example will check the notification and print the value of received tr_id field
// You can access any notification field by $notification->fieldName
if ($notification instanceof BasicPayment) {
var_dump($notification->tr_id->getValue());
// The above example will check the notification and print the value of received tr_id field
// You can access any notification field by $notification->fieldName

$notificationArray = $notification->getNotificationAssociative();
var_dump($notificationArray);
// The above method will get the notification as an associative array and print its contents.
// You can access notification field value by $notificationArray['fieldName']
exit('TRUE');
$notificationArray = $notification->getNotificationAssociative();
var_dump($notificationArray);
// The above method will get the notification as an associative array and print its contents.
// You can access notification field value by $notificationArray['fieldName']
exit('TRUE');
}

// Ignore and silence other notification types if not expected
http_response_code(404);
exit('FALSE');
} catch (TpayException $exception) {
// handle your exception here
exit('FALSE');
Expand Down
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/CardBrand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class CardBrand extends Field
{
protected $name = 'tokenPaymentData_cardBrand';
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/CardExpiryDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class CardExpiryDate extends Field
{
protected $name = 'tokenPaymentData_cardExpiryDate';
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/CardTrail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class CardTrail extends Field
{
protected $name = 'tokenPaymentData_cardTail';
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/InitialTransactionId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class InitialTransactionId extends Field
{
protected $name = 'tokenPaymentData_initialTransactionId';
protected $type = self::STRING;
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/Marketplace/CardToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

class TransactionPaidAmount extends Field
{
protected $name = 'transactionPaidAmount';
protected $type = self::STRING;
}
12 changes: 12 additions & 0 deletions src/Model/Fields/Notification/Marketplace/TransactionStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

class TransactionStatus extends Field
{
protected $name = 'transactionStatus';
protected $type = self::STRING;
protected $enum = ['correct'];
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/Marketplace/TransactionTitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

class TransactionTitle extends Field
{
protected $name = 'transactionTitle';
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/TokenValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class TokenValue extends Field
{
protected $name = 'tokenPaymentData_tokenValue';
protected $type = self::STRING;
}
12 changes: 12 additions & 0 deletions src/Model/Fields/Notification/Tokenization/CardBrand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

class CardBrand extends Field
{
protected $name = 'cardBrand';
protected $type = self::STRING;
protected $enum = ['Mastercard', 'Visa'];
}
13 changes: 13 additions & 0 deletions src/Model/Fields/Notification/Tokenization/CardTail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

class CardTail extends Field
{
protected $name = 'cardTail';
protected $type = self::STRING;
protected $minLength = 4;
protected $maxLength = 4;
}
13 changes: 13 additions & 0 deletions src/Model/Fields/Notification/Tokenization/Token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

class Token extends Field
{
protected $name = 'token';
protected $type = self::STRING;
protected $minLength = 64;
protected $maxLength = 64;
}
13 changes: 13 additions & 0 deletions src/Model/Fields/Notification/Tokenization/TokenExpiryDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

class TokenExpiryDate extends Field
{
protected $name = 'tokenExpiryDate';
protected $type = self::STRING;
protected $minLength = 4;
protected $maxLength = 4;
}
11 changes: 11 additions & 0 deletions src/Model/Fields/Notification/Tokenization/TokenizationId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

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

use Tpay\OpenApi\Model\Fields\Field;

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

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

use Tpay\OpenApi\Model\Fields\Field;

class Type extends Field
{
protected $name = 'type';
protected $type = self::STRING;
protected $enum = ['tokenization', 'tokenization_eisop'];
}
Loading
Loading