> For the complete documentation index, see [llms.txt](https://patryqhyper.gitbook.io/dpay-php-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://patryqhyper.gitbook.io/dpay-php-sdk/secure-part.md).

# "Secure" part

### Base namespace:

```php
use PatryQHyper\Dpay\Secure\ClassName();
```

### General operations

```php
$operations = $dpay->secure(new GeneralOperations());
```

```php
$operations->getLicenseNumber();
$operations->getPrivacyPolicyUrl();
$operations->getTermsUrl();
$operations->getRegulations();
```

### Paybylink payments operations

```php
$pblOperations = $dpay->secure(new PaybylinkPayment('serviceName', 'serviceHash'));;
```

Generate payment:

```php
//required parameters
$pblOperations->setAmount(15);
$pblOperations->setSuccessUrl('https://example.com');
$pblOperations->setFailUrl('https://example.com');
$pblOperations->setIpnUrl('https://webhook.site/78d28431-e5e6-418e-8605-871c138c0884');
//optional parameters
$pblOperations->setCustom('Custom');
$pblOperations->setInstallment(bool);
$pblOperations->setCreditCard(bool);
$pblOperations->setPaypal(bool);
$pblOperations->setPaysafecard(bool);
$pblOperations->setNoBanks(bool);
$pblOperations->setChannel('channelId');
$pblOperations->setEmail('client@example.com');
$pblOperations->setClientName('Jan');
$pblOperations->setClientSurname('Kowalski');
$pblOperations->setDescription('Payment for FOO');
$pblOperations->setStyle(new \PatryQHyper\Dpay\Secure\Styles\DefaultStyle()); //see below
$payment = $pblOperations->generate();
echo $payment->getTransactionId() . PHP_EOL;
echo $payment->getTransactionUrl() . PHP_EOL;
```

#### Setting style class

Available classes:

```php
new \PatryQHyper\Dpay\Secure\Styles\DefaultStyle();
new \PatryQHyper\Dpay\Secure\Styles\DarkStyle();
new \PatryQHyper\Dpay\Secure\Styles\GreenStyle();
new \PatryQHyper\Dpay\Secure\Styles\OrangeStyle();
```

### DirectBilling operations

Register payment:

```php
$registerDirectBillingPayment = $dpay->secure(new RegisterDirectBillingPayment('guid', 'hash'));
$registerDirectBillingPayment->setAmount(15);
$registerDirectBillingPayment->setFailUrl('https://gogoel.com');
$registerDirectBillingPayment->setSuccessUrl('https://gogoel.com');
$registerDirectBillingPayment->setCustom('Custom');
$dcbPayment = $registerDirectBillingPayment->generate();
echo $dcbPayment->getTransactionUrl() . PHP_EOL;
```

## Validate Instant Payment Notification

```php
$notification = $dpay->secure(new HandlePaymentNotification('serviceHash'));
```

You may call `verify()` function to verify parameters, http method and signature. On failure it throws `DpayNotificationException`.

```php
try {
    $notification->verify();
    
    // Your rest of code, for example finding transaction in database, validating price etc.
    
    $notification->responseOk();
}    
catch(\PatryQHyper\Dpay\Exceptions\DpayNotificationException $exception) {
    echo $exception->getMessage();
    die();
}
```

You may also verify notification by yourself, and only call function `generateSignature()` which returns string of generated signature, you have to manually verify it.

```php
if($notification->generateSignature() != $ipnPayload->signature) {
    die('bad signature');
}
```

You may also use specific getters:

```php
$notification->getId(); //string
$notification->getAmount(); //string
$notification->getEmail(); //string
$notification->getType(); //string
$notification->getAttempt(); //int
$notification->getVersion(); //int
$notification->getCustom(); //string
```

`responseOk` function

This function should be used everytime in notifications because of strange Dpay parsing responses, it sometimes contains blank spaces, which will fail IPN on dpay's side. I've received this solution from Dpay's staff.
