4. Operation and Request
For creating request to GPWebPay API you are need create two objects. Operation and Request
The Operation
For basic operation must create OrderNumber, Amount and Currency objects with values of your payment order.
use Pixidos\GPWebPay\Data\Operation;
$operation = new Operation(
$orderNumber,
$amount,
$currency,
'czk', // optional, if you leave empty so will be use default
new ResponseUrl('http://example.com/proccess-gpw-response') // optional when you setup in config
);
more Parameters you can simple add by method addParam(IParam $param)
For example:
$operation->addParam(new PayMethods(PayMethod::CARD(), PayMethod::GOOGLE_PAY()));
Request and Rendering
Request you create by RequestFactory
$request = $requestFactory->create($operation);
And render the payment button
echo sprintf('<a href="%s">This is pay link</a>', $request->getRequestUrl());
or you can render form for post method
<form action="<?= $request->getRequestUrl(true) ?>">
<?php
/** @var IParam $param */
foreach ($request->getParams() as $param) {
echo sprintf('<input type=hidden value="%s" name="%s">%s', $param->getValue(), $param->getParamName(), "\n\r");
}
?>
<input type="submit" value="Pay">
</form>
Parameters
OrderNumber
Ordinal number of the order. Every request from a merchant has to contain a unique order number.
Warning
Is not your order number! For specify you order number use MerOrderNum parameter
You are have two ways how specify this.
// you can create on time base on any other integer unique generator.
$orderNumber = new OrderNumber(time());
Amount
Because the amount is the smallest units of the relevant currency For CZK = in hellers, for EUR = in cents.
You are have two ways how specify this.
// The conversion will make Amount self
$amount = new Amount(1000.00);
// or create the conversion by yourself
$amount = new Amount(100000, false);
Warning
It will be deprecated in next major version. Please replace for AmountInPennies
AmountInPennies
Amount of order
$amount = new AmountInPennies(100000); // represent 1000.00 Kč|Euro
Currency
Currency identifier according to ISO 4217 (see Addendum ISO 4217).
You are simple create this, because in class
Pixidos\GPWebPay\Enum\Currency you are have all constants with ISO code
and methods for create the enum.
use Pixidos\GPWebPay\Enum\Currency as CurrencyEnum;
$currency = new Currency(CurrencyEnum::CZK())
MerOrderNum
Order identification for the merchant. If not specified, the OrderNumber value is used
use Pixidos\GPWebPay\Param\MerOrderNum;
$merOrderNum = new MerOrderNum(123455);