1. Go to this page and download the library: Download italiamultimedia/xpay library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
italiamultimedia / xpay example snippets
final class SimplePaymentService extends AbstractSimplePaymentService implements SimplePaymentServiceInterface
{
protected function createCancelUrl(string $orderId): string
{
...
}
protected function createNotificationUrl(string $orderId): string
{
...
}
protected function createReturnUrl(string $orderId): string
{
...
}
}
final class RequestInputService extends AbstractRequestInputService implements RequestInputServiceInterface
{
public const KEY_LANGUAGE = 'lang';
public const KEY_ORDER_ID = 'orderId';
protected function getValidationRule(string $key): string
{
return match ($key) {
self::KEY_ORDER_ID => '/^[a-f0-9]{42}$/',
default => parent::getValidationRule($key),
};
}
protected function validateInput(string $key, string $value): bool
{
if ($key === self::KEY_LANGUAGE) {
return $this->validateLanguageCode($value);
}
return parent::validateInput($key, $value);
}
private function validateLanguageCode(string $value): bool
{
if (!in_array($value, ['en', 'it'], true)) {
throw new UnexpectedValueException('Invalid data.');
}
return true;
}
}
// Validate order (get info from storage)
...
/**
* Special situation: "mac" can be missing from the request.
* Eg. try to pay already paid transaction.
* In that situation we don't want to have a transaction error, however we also can not trust the request.
* Simply do not process transaction.
*/
$processTransaction = true;
try {
// Try to get mac
$requestInputService->getValidatedString(RequestInput::MAC);
} catch (OutOfBoundsException) {
$processTransaction = false;
}
if ($processTransaction) {
// Validate transaction. Uses input data (_GET or _POST).
$requestInputService->validateInputMac();
// Store transaction result.
...
}
// Redirect back to website.
...
final class RecurringPaymentService extends AbstractRecurringPaymentService implements RecurringPaymentServiceInterface
{
protected function createCancelUrl(string $orderId): string
{
...
}
protected function createNotificationUrl(string $orderId): string
{
...
}
protected function createReturnUrl(string $orderId): string
{
...
}
}