1. Go to this page and download the library: Download pronnect/lib-gpwebpay 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/ */
pronnect / lib-gpwebpay example snippets
use Pronnect\GpWebPay\Config;
use Pronnect\GpWebPay\ServiceProvider;
$config = new Config(
wsUri: 'https://test.3dsecure.gpwebpay.com/pay-ws/v1/PaymentService',
provider: ServiceProvider::CSOB,
merchantNumber: '123456789',
gpePublicKey: '/path/to/gpwebpay-pub.pem',
merchantPrivateKey: '/path/to/merchant.key',
merchantPrivateKeyPassword: 'secret',
);
use Pronnect\GpWebPay\Gateway;
use Pronnect\GpWebPay\DigestSigner;
use Pronnect\GpWebPay\Request\PaymentLinkRequest;
$gateway = new Gateway($config);
// Create a payment link
$request = (new PaymentLinkRequest())
->setPaymentNumber('ORDER-001')
->setAmount(10000) // in lowest currency unit (e.g. cents)
->setCurrencyCode(978) // ISO 4217 — 978 = EUR
->setCaptureFlag(true)
->setUrl('https://example.com/return');
$response = $gateway->createPaymentLink($request);
echo $response->getPaymentLink(); // redirect the cardholder here
// Step 1 — register a token during PaymentLink checkout
$request = (new PaymentLinkRequest())
->setPaymentNumber('ORDER-001')
->setAmount(10000)
->setCurrencyCode(978)
->setCaptureFlag(true)
->setUrl('https://example.com/return')
->setRegisterToken(true); // request token registration
$link = $gateway->createPaymentLink($request);
// Step 2 — use the token for a server-side payment (no cardholder present)
use Pronnect\GpWebPay\Request\CardOnFilePaymentRequest;
use SoapFault;
$cofRequest = (new CardOnFilePaymentRequest())
->setPaymentNumber('ORDER-002')
->setAmount(5000)
->setCurrencyCode(978)
->setCaptureFlag(1)
->setTokenData($tokenReceivedFromGateway)
->setReturnUrl('https://example.com/return');
try {
$response = $gateway->processCardOnFilePayment($cofRequest);
} catch (SoapFault $e) {
// Soft decline — cardholder must authenticate (3DS)
$authLink = $e->detail->cardOnFilePaymentFaultDetail->authenticationLink ?? null;
}
use Pronnect\GpWebPay\DigestSigner;
use Pronnect\GpWebPay\Http\HttpConfig;
use Pronnect\GpWebPay\Http\HttpGateway;
$config = new HttpConfig([
'isTestEnvironment' => true, // false for production
'merchantNumber' => '0123456789',
'GPEPublicKey' => file_get_contents('/path/to/gpe.pub.pem'),
'merchantPrivateKey' => file_get_contents('/path/to/merchant.key'),
'merchantPrivateKeyPassword' => 'secret',
'defaultLang' => 'CS', // optional; 2-letter ISO 639-1
]);
$rawSigner = new DigestSigner(
$config->getGPEPublicKey(),
$config->getMerchantPrivateKey(),
$config->getMerchantPrivateKeyPassword(),
);
// Always use the factory — it wraps DigestSigner in Base64DigestSigner automatically
$gateway = HttpGateway::create($config, $rawSigner);
use Pronnect\GpWebPay\Http\Request\CardPaymentRequest;
$request = new CardPaymentRequest(
orderNumber: 123456,
amount: 19900, // in lowest currency unit (e.g. hellers / cents)
currency: 203, // ISO 4217 — 203 = CZK
depositFlag: 1, // 1 = direct capture, 0 = pre-auth
url: 'https://myshop.cz/return',
);
$request->setDescription('Order #123456');
$request->setLang('CS');
// Redirect cardholder to GP Webpay
header('Location: ' . $gateway->getRedirectUrl($request));
exit;
use Pronnect\GpWebPay\Http\Request\AddInfo;
use Pronnect\GpWebPay\Http\Request\AddInfo\CardholderInfo;
$addInfo = (new AddInfo())
->setCardholderInfo((new CardholderInfo())->setAddrMatch('Y'));
$request->setAddInfo($addInfo->toXml());
$params = $gateway->getFormParams($request); // same as getRedirectUrl but returns array
use Pronnect\GpWebPay\Http\Exception\InvalidCallbackException;
use Pronnect\GpWebPay\Http\Exception\InvalidDigestException;
try {
$response = $gateway->processCallback($_GET);
if ($response->isSuccess()) {
// payment approved — fulfil the order
echo $response->getOrderNumber(); // the orderNumber you set in the request
echo $response->getPrCode(); // '0' = success
}
} catch (InvalidCallbackException $e) {
// DIGEST missing — not a GP Webpay callback
} catch (InvalidDigestException $e) {
// Signature verification failed — reject
}
use Pronnect\GpWebPay\ReturnUrlVerifier;
$verifier = new ReturnUrlVerifier(
gpePublicKey: $config->getGPEPublicKey(),
merchantNumber: $config->getMerchantNumber(),
merchantPrivateKey: $config->getMerchantPrivateKey(),
merchantPrivateKeyPassword: $config->getMerchantPrivateKeyPassword(),
);
if ($verifier->verify($_GET)) {
// DIGEST1 valid — callback is authentic
}
use Pronnect\GpWebPay\Http\Operation; // 'CREATE_ORDER'
use Pronnect\GpWebPay\Http\PayMethod; // 'CRD', 'MCM', 'CSH', …
use Pronnect\GpWebPay\Http\DepositFlag; // IMMEDIATE = 1, PREAUTH = 0
use Pronnect\GpWebPay\Http\ReturnCode; // OK = '0', DECLINED = '1', …
use Pronnect\GpWebPay\Http\UserParam1; // RECURRING_PAYMENT, CARD_ON_FILE, …
use Pronnect\GpWebPay\Http\VrCodeEncryptor;
// AES-128-CBC, 16-byte key from the bank, fixed zero IV, uppercase hex output
$encrypted = VrCodeEncryptor::encrypt('MY_VRCODE', $aes16ByteKey);
// 'B179802DFB94DE8AAA94D840CABBEC6A' (32 hex chars for ≤15 char input)
use Pronnect\GpWebPay\Http\Exception\HttpRequestException; // invalid request params
use Pronnect\GpWebPay\Http\Exception\InvalidDigestException; // bad DIGEST/DIGEST1
use Pronnect\GpWebPay\Http\Exception\InvalidCallbackException; // DIGEST missing
try {
$response = $gateway->processCallback($_GET);
} catch (InvalidCallbackException $e) { /* no DIGEST */ }
catch (InvalidDigestException $e) { /* bad sig */ }
use Pronnect\GpWebPay\ServiceException;
use SoapFault;
try {
$response = $gateway->createPaymentLink($request);
} catch (SoapFault $e) {
if ($e->detail->serviceException ?? null) {
/** @var ServiceException $ex */
$ex = $e->detail->serviceException;
echo $ex->getPrimaryReturnCode(); // e.g. "28"
echo $ex->getSecondaryReturnCode();
echo $ex->getMessage(); // human-readable from codes.xml
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.