Skip to content

Commit

Permalink
Notification update
Browse files Browse the repository at this point in the history
Added missing NotificationBody fields definitions
Updated names of NotificationBody fields
Added getNotificationAssociative() method in BasicPayment object
  • Loading branch information
piotrjozwiak committed Sep 17, 2019
1 parent ed826e3 commit 93fb46c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 19 deletions.
5 changes: 5 additions & 0 deletions Examples/Notifications/PaymentNotificationExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ public function checkPayment()
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']
12 changes: 12 additions & 0 deletions Model/Fields/Notification/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace tpaySDK\Model\Fields\Notification;

use tpaySDK\Model\Fields\Field;

class Email extends Field
{
protected $name = 'tr_email';

protected $type = self::STRING;

}
2 changes: 1 addition & 1 deletion Model/Fields/Notification/Md5sum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Md5sum extends Field
{
protected $name = __CLASS__;
protected $name = 'md5sum';

protected $type = self::STRING;

Expand Down
12 changes: 12 additions & 0 deletions Model/Fields/Notification/MerchantId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace tpaySDK\Model\Fields\Notification;

use tpaySDK\Model\Fields\Field;

class MerchantId extends Field
{
protected $name = 'id';

protected $type = self::INT;

}
2 changes: 1 addition & 1 deletion Model/Fields/Notification/TestMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class TestMode extends Field
{
protected $name = __CLASS__;
protected $name = 'test_mode';

protected $type = self::INT;

Expand Down
2 changes: 1 addition & 1 deletion Model/Fields/Notification/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Wallet extends Field
{
protected $name = __CLASS__;
protected $name = 'wallet';

protected $type = self::STRING;

Expand Down
24 changes: 20 additions & 4 deletions Model/Objects/NotificationBody/BasicPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use tpaySDK\Model\Fields\Notification\Description;
use tpaySDK\Model\Fields\Notification\Error;
use tpaySDK\Model\Fields\Notification\Md5sum;
use tpaySDK\Model\Fields\Notification\MerchantId;
use tpaySDK\Model\Fields\Notification\Paid;
use tpaySDK\Model\Fields\Notification\TestMode;
use tpaySDK\Model\Fields\Notification\TransactionAmount;
Expand All @@ -14,17 +15,16 @@
use tpaySDK\Model\Fields\Notification\TransactionId;
use tpaySDK\Model\Fields\Notification\TransactionStatus;
use tpaySDK\Model\Fields\Notification\Wallet;
use tpaySDK\Model\Fields\Person\Email;
use tpaySDK\Model\Fields\Notification\Email;
use tpaySDK\Model\Objects\ObjectHelper;
use tpaySDK\Model\Objects\Objects;
use tpaySDK\Model\Primitives\Id;

class BasicPayment extends Objects
{
use ObjectHelper;

const OBJECT_FIELDS = [
'id' => Id::class,
'id' => MerchantId::class,
'tr_id' => TransactionId::class,
'tr_date' => TransactionDate::class,
'tr_crc' => Crc::class,
Expand All @@ -42,7 +42,7 @@ class BasicPayment extends Objects
];

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

Expand Down Expand Up @@ -133,4 +133,20 @@ public function getRequiredFields()
];
}

/**
* Returns associative array containing all notification fields
* @return array
*/
public function getNotificationAssociative()
{
$notification = [];
foreach (static::OBJECT_FIELDS as $fieldName => $fieldClass) {
if (isset($this->$fieldName) && !is_null($this->$fieldName->getValue())) {
$notification[$fieldName] = $this->$fieldName->getValue();
}
}

return $notification;
}

}
12 changes: 0 additions & 12 deletions Model/Primitives/Id.php

This file was deleted.

0 comments on commit 93fb46c

Please sign in to comment.