Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 2.18 KB

notifications.md

File metadata and controls

65 lines (45 loc) · 2.18 KB

Notifications

If state of the payment changes you will get a notification to a specified url. Please set up default value in administration:

settings

This value may be overridden for each payment in CreatePaymentParams by setNotifUrl() function.

There are three query parameters added to notifications url:

In most cases you want to check the state of payment after getting notification:

See how to make TheClient

$uid = $_GET["payment_uid"];
$projectId = $_GET["project_id"];

$merchantId = '86a3eed0-95a4-11ea-ac9f-371f3488e0fa';
$apiPassword = 'secret';
$apiUrl = 'https://demo.api.thepay.cz/'; // production: 'https://api.thepay.cz/'
$gateUrl = 'https://demo.gate.thepay.cz/'; // production: 'https://gate.thepay.cz/'

$config = new \ThePay\ApiClient\TheConfig($merchantId, $projectId, $apiPassword, $apiUrl, $gateUrl);

/** @var \ThePay\ApiClient\Service\ApiService $apiService */
$thePayClient = new \ThePay\ApiClient\TheClient($config, $apiService);

$payment = $thePayClient->getPayment($uid);
if ($payment->getState() === 'paid') {
    // send email to customer
}

You can save server resources by filtering notification type to only certain types:

$uid = $_GET["payment_uid"];
$projectId = $_GET["project_id"];
$type = $_GET["type"];

// handle only state changed notifications
if ($type === "state_changed") {
    $merchantId = '86a3eed0-95a4-11ea-ac9f-371f3488e0fa';
    $apiPassword = 'secret';
    $apiUrl = 'https://demo.api.thepay.cz/'; // production: 'https://api.thepay.cz/'
    $gateUrl = 'https://demo.gate.thepay.cz/'; // production: 'https://gate.thepay.cz/'

    $config = new \ThePay\ApiClient\TheConfig($merchantId, $projectId, $apiPassword, $apiUrl, $gateUrl);

    /** @var \ThePay\ApiClient\Service\ApiService $apiService */
    $thePayClient = new \ThePay\ApiClient\TheClient($config, $apiService);

    $payment = $thePayClient->getPayment($uid);
    if ($payment->getState() === 'paid') {
        // send email to customer
    }
}