-
Notifications
You must be signed in to change notification settings - Fork 11
/
PaymentNotificationExample.php
42 lines (36 loc) · 1.46 KB
/
PaymentNotificationExample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Tpay\Example\Notifications;
use Tpay\Example\ExamplesConfig;
use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment;
use Tpay\OpenApi\Utilities\TpayException;
use Tpay\OpenApi\Webhook\JWSVerifiedPaymentNotification;
final class PaymentNotificationExample extends ExamplesConfig
{
/**
* Returns validated object with set parameters
*
* @return BasicPayment
*/
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 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
$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');
} catch (TpayException $exception) {
// handle your exception here
exit('FALSE');
}