dpay-php-sdk
  • Introduction
  • "Secure" part
  • "Panel" part
Powered by GitBook
On this page
  • Base namespace:
  • General operations
  • Paybylink payments operations
  • DirectBilling operations
  • Validate Instant Payment Notification

"Secure" part

Base namespace:

use PatryQHyper\Dpay\Secure\ClassName();

General operations

$operations = $dpay->secure(new GeneralOperations());
$operations->getLicenseNumber();
$operations->getPrivacyPolicyUrl();
$operations->getTermsUrl();
$operations->getRegulations();

Paybylink payments operations

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

Generate payment:

//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:

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:

$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

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

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

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.

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

You may also use specific getters:

$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.

PreviousIntroductionNext"Panel" part

Last updated 2 years ago