1. Go to this page and download the library: Download italiamultimedia/xpay-web 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-web example snippets
use ItaliaMultimedia\XPayWeb\DataTransfer\Configuration;
use ItaliaMultimedia\XPayWeb\DataTransfer\PaymentSystemSettings;
$apiKey = (string) getenv('XPAY_API_KEY');
$environment = (string) (getenv('XPAY_ENVIRONMENT') ?: Configuration::ENVIRONMENT_TEST);
$paymentSystemSettings = new PaymentSystemSettings($apiKey, $environment);
$paymentSystemSettings = new PaymentSystemSettings($apiKey, 'test');
use Http\Client\Curl\Client;
use ItaliaMultimedia\XPayWeb\Container\DependencyContainer;
use ItaliaMultimedia\XPayWeb\Factory\Service\PaymentServiceFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
$dependencyContainer = new DependencyContainer($paymentSystemSettings);
$paymentServiceFactory = new PaymentServiceFactory($dependencyContainer);
$psr17Factory = new Psr17Factory();
$simplePaymentService = $paymentServiceFactory->createSimplePaymentService(
new Client(),
$psr17Factory,
$psr17Factory,
);
$recurringPaymentService = $paymentServiceFactory->createRecurringPaymentService(
new Client(),
$psr17Factory,
$psr17Factory,
);
$hostedPaymentResultService = $paymentServiceFactory->createHostedPaymentResultService();
use ItaliaMultimedia\XPayWeb\DataTransfer\Configuration;
use ItaliaMultimedia\XPayWeb\DataTransfer\Request\CreateHostedPaymentPageOptions;
use ItaliaMultimedia\XPayWeb\DataTransfer\Request\CreateHostedPaymentPageRequest;
$request = new CreateHostedPaymentPageRequest(
$correlationId,
$orderId,
1000,
Configuration::CURRENCY,
'ITA',
'https://example.com/payment/result',
'https://example.com/payment/cancel',
new CreateHostedPaymentPageOptions(description: 'Order description'),
);
$response = $simplePaymentService->createHostedPaymentPage($request);
// Store this with your local order if you use hosted payment notifications.
$securityToken = $response->securityToken;
header(sprintf('Location: %s', $response->hostedPage));
exit;
$request = new CreateHostedPaymentPageRequest(
$correlationId,
$orderId,
1000,
Configuration::CURRENCY,
'ITA',
'https://example.com/payment/result',
'https://example.com/payment/cancel',
new CreateHostedPaymentPageOptions(
notificationUrl: 'https://example.com/payment/notification',
description: 'Order description',
),
);
use ItaliaMultimedia\XPayWeb\DataTransfer\Request\RetrieveOrderStatusRequest;
$response = $simplePaymentService->retrieveOrderStatus(
new RetrieveOrderStatusRequest($correlationId, $orderId),
);
foreach ($response->operations as $operation) {
// Inspect operationResult, operationType, operationId, operationTime, etc.
}