### Plain card payment example Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Example from examples/payment.php showing a plain card payment setup. ```php $transaction = new BeGateway\PaymentOperation(); $transaction->card->setCardNumber('4200000000000000'); $transaction->card->setCardHolder('JOHN DOE'); $transaction->card->setCardExpMonth('01'); $transaction->card->setCardExpYear(2030); $transaction->card->setCardCvc('123'); $transaction->card->setSkip3D(true); ``` -------------------------------- ### Usage example: amount-first workflow Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/money.md Shows how to set an amount in major units and currency, then retrieve cents and amount. The cents value (1057) is what gets sent to the gateway. ```php $m = new BeGateway\Money(); $m->setAmount(10.57); $m->setCurrency('EUR'); $m->getCents(); // 1057 — what gets sent to the gateway $m->getAmount(); // 10.57 ``` -------------------------------- ### Query by payment token example Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/query-operations.md Example usage of QueryByPaymentToken from examples/query_by_payment_token.php. It queries a checkout by token and prints the checkout status. Transport exceptions propagate and are caught here for logging. ```php $query = new BeGateway\QueryByPaymentToken; $query->setToken($token); // from a previous ResponseCheckout try { $query_response = $query->submit(); // ResponseCheckout if ($query_response->isSuccess()) { echo 'Checkout status: ' . $query_response->getResponse()->checkout->status . PHP_EOL; } else { echo $query_response->getMessage(); } } catch (\Exception $e) { // transport failure — propagates for this class error_log($e->getMessage()); } ``` -------------------------------- ### Usage Examples Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Usage examples for the Card value object in payment and tokenization flows. ```APIDOC ## Plain Card Payment ### Description Example of setting card fields for a direct payment operation. ### Code ```php $transaction = new BeGateway\PaymentOperation(); $transaction->card->setCardNumber('4200000000000000'); $transaction->card->setCardHolder('JOHN DOE'); $transaction->card->setCardExpMonth('01'); $transaction->card->setCardExpYear(2030); $transaction->card->setCardCvc('123'); $transaction->card->setSkip3D(true); ``` ``` ```APIDOC ## Payment by Card Token with CVC ### Description Example of using a card token obtained from a previous tokenization, along with a CVC. ### Code ```php $token = new BeGateway\CardToken(); // ... $token->card->setCardNumber(...) etc. $response = $token->submit(); $transaction = new BeGateway\PaymentOperation(); $transaction->card->setCardToken($response->card->getCardToken()); $transaction->card->setCardCvc('123'); ``` ``` ```APIDOC ## Working with ResponseCardToken ### Description Example of reading card data from a tokenization response. ### Code ```php $response = $token->submit(); if ($response->isSuccess()) { $card = $response->card; echo $card->getCardToken(); // string token echo $card->getBrand(); // e.g. 'visa' echo $card->getFirst_1(); // e.g. '4' echo $card->getLast_4(); // e.g. '0000' } ``` ``` -------------------------------- ### Query by UID example Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/query-operations.md Example usage of QueryByUid from examples/query_by_uid.php. It queries a transaction by UID after a successful payment operation and prints status, payment method, or a not-found message. ```php $payment = new BeGateway\PaymentOperation; // ... configure and submit ... $response = $payment->submit(); if ($response->isSuccess()) { $query = new BeGateway\QueryByUid; $query->setUid($response->getUid()); $query_response = $query->submit(); if ($query_response->getUid()) { echo 'Found. Status: ' . $query_response->getStatus() . PHP_EOL; echo 'Payment method: ' . $query_response->getPaymentMethod() . PHP_EOL; if ($query_response->isTest()) { echo 'Test transaction' . PHP_EOL; } } else { echo 'Not found in any endpoint: ' . $query_response->getMessage() . PHP_EOL; } } ``` -------------------------------- ### Create token and pay with it (examples/card_token.php) Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card-token.md Usage example from examples/card_token.php. Creates a token, then uses it in a PaymentOperation. Shows success and failure handling. ```php $token = new BeGateway\CardToken; $token->card->setCardNumber('4200000000000000'); $token->card->setCardHolder('John Doe'); $token->card->setCardExpMonth('01'); $token->card->setCardExpYear(2029); $response = $token->submit(); if ($response->isSuccess()) { echo 'Card token: ' . $response->card->getCardToken() . PHP_EOL; $transaction = new BeGateway\PaymentOperation; $transaction->money->setAmount(1.00); $transaction->money->setCurrency('EUR'); $transaction->setDescription('test'); $transaction->card->setCardCvc('123'); $transaction->card->setCardToken($response->card->getCardToken()); $transaction->setTestMode(true); $transaction->customer->setEmail('john@example.com'); $pay_response = $transaction->submit(); if ($pay_response->isSuccess()) { echo 'Transaction UID: ' . $pay_response->getUid() . PHP_EOL; } } else { echo 'Tokenization failed: ' . $response->getMessage() . PHP_EOL; } ``` -------------------------------- ### Usage example with PaymentOperation Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/api-abstract.md Example usage of PaymentOperation with language, timeouts, headers, and submit(). The response is always a Response object even on transport errors. ```php $transaction = new BeGateway\PaymentOperation(); $transaction->setLanguage('ru'); // falls back to 'en' for unsupported codes $transaction->setTimeout(45); // curl CURLOPT_TIMEOUT $transaction->setConnectTimeout(5); // curl CURLOPT_CONNECTTIMEOUT $transaction->setRequestHeaders(['X-Custom-Header: abc']); $response = $transaction->submit(); // always a Response, even on transport errors if ($response->isSuccess()) { echo $response->getUid(); } ``` -------------------------------- ### Payment by card token with CVC Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Example from examples/card_token.php showing payment by card token with CVC. ```php $token = new BeGateway\CardToken(); // ... $token->card->setCardNumber(...) etc. $response = $token->submit(); $transaction = new BeGateway\PaymentOperation(); $transaction->card->setCardToken($response->card->getCardToken()); $transaction->card->setCardCvc('123'); ``` -------------------------------- ### Query by tracking id example Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/query-operations.md Example usage of QueryByTrackingId from examples/query_by_tracking_id.php. It queries a transaction by the merchant's tracking id and prints the UID on success or an error message on failure. ```php $query = new BeGateway\QueryByTrackingId; $query->setTrackingId('my_custom_variable'); $query_response = $query->submit(); if ($query_response->isSuccess()) { echo 'UID: ' . $query_response->getUid() . PHP_EOL; } elseif ($query_response->isError()) { echo 'Lookup error: ' . $query_response->getMessage() . PHP_EOL; } ``` -------------------------------- ### Usage example for overridden submit() with try/catch Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/api-abstract.md Example for operations that override submit() without try/catch, such as GetPaymentToken. These may throw exceptions on transport failure. ```php $checkout = new BeGateway\GetPaymentToken(); // ... configure ... try { $response = $checkout->submit(); // ResponseCheckout — may throw } catch (\Exception $e) { // transport failure } ``` -------------------------------- ### Retrieve supported and default language codes Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/settings.md Example usage of Language::getSupportedLanguages() to build a language selector and Language::getDefaultLanguage() to get the default 'en' code. Unsupported codes silently fall back to 'en'. ```php $codes = BeGateway\Language::getSupportedLanguages(); // list for building a selector $default = BeGateway\Language::getDefaultLanguage(); // 'en' ``` -------------------------------- ### Basic checkout with BeGateway\GetPaymentToken Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/get-payment-token.md Basic checkout example from examples/get_payment_token.php. Sets up a BeGateway\GetPaymentToken transaction with amount, currency, description, tracking ID, language, test mode, and URLs, then submits and handles the response by redirecting on success or printing the error message. ```php $transaction = new BeGateway\GetPaymentToken; $transaction->money->setAmount(1.00); $transaction->money->setCurrency('EUR'); $transaction->setDescription('test'); $transaction->setTrackingId('my_custom_variable'); $transaction->setLanguage('en'); $transaction->setTestMode(true); $transaction->setNotificationUrl('http://www.example.com/notify'); $transaction->setSuccessUrl('http://www.example.com/success'); $transaction->setDeclineUrl('http://www.example.com/decline'); $transaction->setFailUrl('http://www.example.com/fail'); $transaction->setCancelUrl('http://www.example.com/cancel'); $transaction->setExpiryDate(date('Y-m-d H:i:s', time() + 86400)); // ISO 8601 conversion applied $transaction->customer->setFirstName('John'); $transaction->customer->setLastName('Doe'); $transaction->customer->setCountry('LV'); $transaction->customer->setAddress('Demo str 12'); $transaction->customer->setCity('Riga'); $transaction->customer->setZip('LV-1082'); $transaction->customer->setEmail('john@example.com'); $transaction->customer->setBirthDate('1970-01-12'); try { $response = $transaction->submit(); } catch (\Exception $e) { // transport failure — propagates } if ($response->isSuccess()) { header('Location: ' . $response->getRedirectUrl()); } else { echo 'Checkout error: ' . $response->getMessage(); } ``` -------------------------------- ### setCity($city) / getCity() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer city. ```APIDOC ## setCity($city) / getCity() ### Description Sets or gets the customer city. ### Method setCity($city) / getCity() ### Parameters - **$city** (string) - Required - The customer city. ### Returns - **string|null** - The stored city or null if not set. ### Example ```php $customer->setCity('Riga'); $city = $customer->getCity(); ``` ``` -------------------------------- ### GetPaymentToken Usage Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/get-payment-token.md Example of creating a payment token with basic checkout parameters and submitting the transaction. ```APIDOC ## GetPaymentToken ### Description Creates a payment token for a checkout transaction. ### Method submit() ### Parameters #### Money - **amount** (float) - Required - Transaction amount. - **currency** (string) - Required - Currency code (e.g., 'EUR'). #### Transaction - **description** (string) - Required - Transaction description. - **tracking_id** (string) - Optional - Custom tracking identifier. - **language** (string) - Optional - Language code (e.g., 'en'). - **test_mode** (boolean) - Optional - Enable test mode. - **notification_url** (string) - Optional - URL for notifications. - **success_url** (string) - Optional - URL for successful payment. - **decline_url** (string) - Optional - URL for declined payment. - **fail_url** (string) - Optional - URL for failed payment. - **cancel_url** (string) - Optional - URL for cancelled payment. - **expiry_date** (string) - Optional - Expiry date in ISO 8601 format. #### Customer - **first_name** (string) - Optional - Customer first name. - **last_name** (string) - Optional - Customer last name. - **country** (string) - Optional - Customer country code. - **address** (string) - Optional - Customer address. - **city** (string) - Optional - Customer city. - **zip** (string) - Optional - Customer ZIP code. - **email** (string) - Optional - Customer email. - **birth_date** (string) - Optional - Customer birth date (YYYY-MM-DD). ### Request Example ```php $transaction = new BeGateway\GetPaymentToken; $transaction->money->setAmount(1.00); $transaction->money->setCurrency('EUR'); $transaction->setDescription('test'); $transaction->setTrackingId('my_custom_variable'); $transaction->setLanguage('en'); $transaction->setTestMode(true); $transaction->setNotificationUrl('http://www.example.com/notify'); $transaction->setSuccessUrl('http://www.example.com/success'); $transaction->setDeclineUrl('http://www.example.com/decline'); $transaction->setFailUrl('http://www.example.com/fail'); $transaction->setCancelUrl('http://www.example.com/cancel'); $transaction->setExpiryDate(date('Y-m-d H:i:s', time() + 86400)); $transaction->customer->setFirstName('John'); $transaction->customer->setLastName('Doe'); $transaction->customer->setCountry('LV'); $transaction->customer->setAddress('Demo str 12'); $transaction->customer->setCity('Riga'); $transaction->customer->setZip('LV-1082'); $transaction->customer->setEmail('john@example.com'); $transaction->customer->setBirthDate('1970-01-12'); $response = $transaction->submit(); ``` ### Response #### Success Response - **isSuccess()** (boolean) - Indicates if the transaction was successful. - **getRedirectUrl()** (string) - URL to redirect the customer to for payment. - **getMessage()** (string) - Error message if not successful. #### Response Example ```php if ($response->isSuccess()) { header('Location: ' . $response->getRedirectUrl()); } else { echo 'Checkout error: ' . $response->getMessage(); } ``` ### Inherited Methods - **setTimeout()** - Set timeout. - **setConnectTimeout()** - Set connection timeout. - **setRequestHeaders()** - Set request headers (X-Api-Version: 2 is default). ``` -------------------------------- ### Run tests with PHPUnit Source: https://github.com/begateway/begateway-api-php/blob/master/Readme.md Run the test suite for the library. Requires PHPUnit to be installed via Composer. ```bash ./vendor/bin/phpunit ``` -------------------------------- ### Usage example: cents-first workflow Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/money.md Shows how to set cents directly, useful when coming from a gateway response. For JPY, which has no decimal power, the amount equals the cents. ```php $m = new BeGateway\Money(0, 'JPY'); $m->setCents(2550); $m->getAmount(); // 2550 — JPY has no decimal power $m->getCents(); // 2550 ``` -------------------------------- ### setPhone($phone) / getPhone() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer phone number. ```APIDOC ## setPhone($phone) / getPhone() ### Description Sets or gets the customer phone number. ### Method setPhone($phone) / getPhone() ### Parameters - **$phone** (string) - Required - The customer phone number. ### Returns - **string|null** - The stored phone number or null if not set. ### Example ```php $customer->setPhone('+371 12345678'); $phone = $customer->getPhone(); ``` ``` -------------------------------- ### Set and get description Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/credit-operation.md Sets and retrieves the description for the credit operation. ```php public function setDescription($description) public function getDescription() ``` -------------------------------- ### BeGateway\Money Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/money.md Documentation for the BeGateway\Money value object, including constructor, methods, and usage examples. ```APIDOC ## BeGateway\Money ### Description Value object for amounts and currencies used by every operation (`money` public property). Stores either an amount in major units or cents; whichever was set last wins. ### Constructor ```php public function __construct($amount = 0, $currency = 'USD') ``` | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `$amount` | number | `0` | Initial amount in major units (decimal allowed) | | `$currency` | string | `'USD'` | ISO 4217 currency code | ### Methods #### `setAmount($amount)` / `getAmount()` ```php public function setAmount($amount) public function getAmount() ``` - `setAmount`: sets major-unit amount and clears any stored cents. - `getAmount`: returns `floatval(strval($amount))` — the stored major-unit amount, or `cents / multiplier` when cents were set. `strval`/`floatval` round-tripping avoids float artifacts (e.g. `151.2` → `151.2`). #### `setCents($cents)` / `getCents()` ```php public function setCents($cents) public function getCents() ``` - `setCents`: stores `intval($cents)` and clears the stored amount. - `getCents`: returns stored cents, or `intval(strval($amount * multiplier))` when an amount was set. #### `setCurrency($currency)` / `getCurrency()` ```php public function setCurrency($currency) public function getCurrency() ``` - `setCurrency`: sets the ISO 4217 code and thereby the cent multiplier used by the conversions above. ### Currency power table `_currency_power()` selects the decimal exponent: default `2`, `0` for `BIF, BYR, CLF, CLP, CVE, DJF, GNF, IDR, IQD, IRR, ISK, JPY, KMF, KPW, KRW, LAK, LBP, MMK, PYG, RWF, SLL, STD, UYI, VND, VUV, XAF, XOF, XPF`, `1` for `MOP`, `3` for `BHD, JOD, KWD, LYD, OMR, TND`. The multiplier is `10^power`. ### Usage ```php $m = new BeGateway\Money(); $m->setAmount(10.57); $m->setCurrency('EUR'); $m->getCents(); // 1057 — what gets sent to the gateway $m->getAmount(); // 10.57 ``` Cents-first variant (e.g. when coming from a gateway response): ```php $m = new BeGateway\Money(0, 'JPY'); $m->setCents(2550); $m->getAmount(); // 2550 — JPY has no decimal power $m->getCents(); // 2550 ``` Inside an operation the object is pre-instantiated as the public `money` property: ```php $transaction = new BeGateway\PaymentOperation(); $transaction->money->setAmount(1.00); // major units, e.g. EUR $transaction->money->setCurrency('EUR'); // serialized as request.amount = 100 ``` Typical gotcha: setting `setCents` after `setAmount` (or vice versa) discards the other value because both setters null out the alternative. ``` -------------------------------- ### setZip($zip) / getZip() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer zip/postal code. ```APIDOC ## setZip($zip) / getZip() ### Description Sets or gets the customer zip/postal code. ### Method setZip($zip) / getZip() ### Parameters - **$zip** (string) - Required - The customer zip/postal code. ### Returns - **string|null** - The stored zip code or null if not set. ### Example ```php $customer->setZip('LV-1082'); $zip = $customer->getZip(); ``` ``` -------------------------------- ### Usage example: inside an operation Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/money.md Shows how the money object is pre-instantiated as the public 'money' property of an operation. Setting amount and currency serializes as request.amount = 100. ```php $transaction = new BeGateway\PaymentOperation(); $transaction->money->setAmount(1.00); // major units, e.g. EUR $transaction->money->setCurrency('EUR'); // serialized as request.amount = 100 ``` -------------------------------- ### setFirstName($first_name) / getFirstName() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer first name. Serialized under billing_address.first_name. ```APIDOC ## setFirstName($first_name) / getFirstName() ### Description Sets or gets the customer first name. Serialized under `billing_address.first_name`. ### Method setFirstName($first_name) / getFirstName() ### Parameters - **$first_name** (string) - Required - The customer first name. ### Returns - **string|null** - The stored first name or null if not set. ### Example ```php $customer->setFirstName('John'); $firstName = $customer->getFirstName(); ``` ``` -------------------------------- ### Create payment token for hosted payment page Source: https://github.com/begateway/begateway-api-php/blob/master/Readme.md Create a payment token for the hosted payment page. Sets up transaction details, customer information, and redirects the user to the payment page on success. Requires the library to be installed and configured. ```php setLogLevel(BeGateway\Logger::INFO); $transaction = new BeGateway\GetPaymentToken; $transaction->money->setAmount(1.00); $transaction->money->setCurrency('EUR'); $transaction->setDescription('test'); $transaction->setTrackingId('my_custom_variable'); $transaction->setLanguage('en'); $transaction->setNotificationUrl('http://www.example.com/notify'); $transaction->setSuccessUrl('http://www.example.com/success'); $transaction->setDeclineUrl('http://www.example.com/decline'); $transaction->setFailUrl('http://www.example.com/fail'); $transaction->setCancelUrl('http://www.example.com/cancel'); $transaction->customer->setFirstName('John'); $transaction->customer->setLastName('Doe'); $transaction->customer->setCountry('LV'); $transaction->customer->setAddress('Demo str 12'); $transaction->customer->setCity('Riga'); $transaction->customer->setZip('LV-1082'); $transaction->customer->setIp('127.0.0.1'); $transaction->customer->setEmail('john@example.com'); $response = $transaction->submit(); if ($response->isSuccess() ) { header("Location: " . $response->getRedirectUrl() ); } ``` -------------------------------- ### ResponseCardToken usage example Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Working with a ResponseCardToken object; the response's public card is a Card instance prefilled (lib/ResponseCardToken.php:13-24). ```php $response = $token->submit(); if ($response->isSuccess()) { $card = $response->card; echo $card->getCardToken(); // string token echo $card->getBrand(); // e.g. 'visa' echo $card->getFirst_1(); // e.g. '4' echo $card->getLast_4(); // e.g. '0000' } ``` -------------------------------- ### Usage: Add CreditCard and CreditCardHalva Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/payment-methods.md Example from examples/get_payment_token_halva.php. Adds a CreditCard and a CreditCardHalva payment method to the transaction. The halva method name serializes as 'halva' and has no parameters. ```php $cc = new \BeGateway\PaymentMethod\CreditCard; $halva = new \BeGateway\PaymentMethod\CreditCardHalva; $transaction->addPaymentMethod($cc); $transaction->addPaymentMethod($halva); // name serializes as 'halva'; no params section for it ``` -------------------------------- ### Customer setter/getter signature example Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Shows the common signature shape shared by all Customer setters and getters. Every setter stores null when given an empty string, and every getter returns the stored value or null. ```php public function setEmail($email) public function getEmail() ``` -------------------------------- ### setIP($ip) / getIP() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer IP address. The IP is serialized as customer.ip in direct payments. ```APIDOC ## setIP($ip) / getIP() ### Description Sets or gets the customer IP address. The IP is serialized as `customer.ip` in direct payments. ### Method setIP($ip) / getIP() ### Parameters - **$ip** (string) - Required - The customer IP address. ### Returns - **string|null** - The stored IP address or null if not set. ### Example ```php $customer->setIP('127.0.0.1'); $ip = $customer->getIP(); ``` ``` -------------------------------- ### setLanguage() and getLanguage() signatures Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/api-abstract.md Method signatures for setting and getting the language. Unsupported codes fall back to 'en'. ```php public function setLanguage($language_code) public function getLanguage() ``` -------------------------------- ### Adding Payment Methods Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/get-payment-token.md Example of adding multiple payment methods (Credit Card and ERIP) to a transaction. ```APIDOC ## Adding Payment Methods ### Description Add payment methods to the transaction, such as Credit Card and ERIP. ### Methods - **addPaymentMethod($method)** - Add a payment method object. ### Payment Method: CreditCard - No additional parameters. ### Payment Method: Erip - **order_id** (integer) - Required - Order identifier. - **account_number** (string) - Required - Account number. - **service_no** (string) - Required - Service number. - **service_info** (array) - Optional - Service information (e.g., ['Order 1234']). ### Request Example ```php $cc = new \BeGateway\PaymentMethod\CreditCard; $erip = new \BeGateway\PaymentMethod\Erip([ 'order_id' => 1234, 'account_number' => '1234', 'service_no' => '99999999', 'service_info' => ['Order 1234'], ]); $transaction->addPaymentMethod($cc); $transaction->addPaymentMethod($erip); $transaction->money->setCurrency('BYN'); $transaction->setLanguage('ru'); ``` ``` -------------------------------- ### setState($state) / getState() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer state. getState() returns null unless the country is 'US' or 'CA'. ```APIDOC ## setState($state) / getState() ### Description Sets or gets the customer state. `getState()` returns `null` unless the country is `'US'` or `'CA'`. ### Method setState($state) / getState() ### Parameters - **$state** (string) - Required - The customer state. ### Returns - **string|null** - The stored state or null if not set or if country is not US/CA. ### Example ```php $customer->setCountry('US'); $customer->setState('BE'); $state = $customer->getState(); // 'BE' ``` ``` -------------------------------- ### Authorization with AuthorizationOperation (two-step flow) Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/authorization-operation.md Uses AuthorizationOperation instead of PaymentOperation for a two-step flow, where the returned UID is passed to CaptureOperation or VoidOperation. Configuration is identical to the basic payment example. ```php $auth = new BeGateway\AuthorizationOperation; // ... identical configuration ... $response = $auth->submit(); if ($response->isSuccess()) { $uid = $response->getUid(); // pass to CaptureOperation / VoidOperation } ``` -------------------------------- ### Create a pay link with BeGateway\Product Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/product.md Creates a basic product with amount, currency, name, description, and test mode, then submits it. On success, prints the product ID, pay link, and pay URL; on failure, prints the error message. ```php $product = new BeGateway\Product; $product->money->setAmount(25.00); $product->money->setCurrency('EUR'); $product->setName('name'); $product->setDescription('test'); $product->setTestMode(true); $response = $product->submit(); if ($response->isSuccess()) { echo 'Product Id: ' . $response->getId() . PHP_EOL; echo 'Link to pay: ' . $response->getPayLink() . PHP_EOL; // {checkoutBase}/v2/confirm_order/{id}/{shopId} echo 'URL for website: ' . $response->getPayUrl() . PHP_EOL; // {apiBase}/products/{id}/pay } else { echo 'Product creation error: ' . $response->getMessage() . PHP_EOL; } ``` -------------------------------- ### Usage: Combine credit card and ERIP Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/payment-methods.md Example from examples/get_payment_token_erip.php. Combines credit card and ERIP payment methods on a single checkout, sets transaction details, and submits to get a payment token. ```php $transaction = new BeGateway\GetPaymentToken; $cc = new \BeGateway\PaymentMethod\CreditCard; $erip = new \BeGateway\PaymentMethod\Erip([ 'order_id' => 1234, 'account_number' => '1234', 'service_no' => '99999999', 'service_info' => ['Order 1234'], ]); $transaction->addPaymentMethod($cc); $transaction->addPaymentMethod($erip); $transaction->money->setAmount(150.00); $transaction->money->setCurrency('BYN'); $transaction->setDescription('Тестовая оплата'); $transaction->setLanguage('ru'); $transaction->setTestMode(true); $transaction->setExpiryDate(date('Y-m-d', 3 * 24 * 3600 + time()) . 'T00:00:00+03:00'); $transaction->customer->setEmail('john@example.com'); $response = $transaction->submit(); if ($response->isSuccess()) { echo 'Token: ' . $response->getToken() . PHP_EOL; } ``` -------------------------------- ### Basic payment with PaymentOperation (examples/payment.php) Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/authorization-operation.md Creates a PaymentOperation, sets amount, currency, description, tracking ID, test mode, language, card details, and customer details, then submits and handles the response. Prints status and UID on success or failure, and reason on failure. ```php $transaction = new BeGateway\PaymentOperation; $transaction->money->setAmount(1.00); $transaction->money->setCurrency('EUR'); $transaction->setDescription('test'); $transaction->setTrackingId('my_custom_variable'); $transaction->setTestMode(true); $transaction->setLanguage('en'); $transaction->card->setCardNumber('4200000000000000'); $transaction->card->setCardHolder('JOHN DOE'); $transaction->card->setCardExpMonth('01'); $transaction->card->setCardExpYear(2030); $transaction->card->setCardCvc('123'); $transaction->customer->setFirstName('John'); $transaction->customer->setLastName('Doe'); $transaction->customer->setCountry('LV'); $transaction->customer->setAddress('Demo str 12'); $transaction->customer->setCity('Riga'); $transaction->customer->setZip('LV-1082'); $transaction->customer->setIp('127.0.0.1'); $transaction->customer->setEmail('john@example.com'); $response = $transaction->submit(); if ($response->isSuccess()) { print("Status: " . $response->getStatus() . PHP_EOL); print("Transaction UID: " . $response->getUid() . PHP_EOL); } elseif ($response->isFailed()) { print("Status: " . $response->getStatus() . PHP_EOL); print("Transaction UID: " . $response->getUid() . PHP_EOL); print("Reason: " . $response->getMessage() . PHP_EOL); } else { print("Status: error" . PHP_EOL); print("Reason: " . $response->getMessage() . PHP_EOL); } ``` -------------------------------- ### Token-based payment with PaymentOperation (examples/card_token.php) Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/authorization-operation.md Creates a PaymentOperation using a previously tokenized card. Sets amount, currency, description, card CVC, card token from a token response, and customer email, then submits. ```php $transaction = new BeGateway\PaymentOperation; $transaction->money->setAmount(1.00); $transaction->money->setCurrency('EUR'); $transaction->setDescription('test'); $transaction->card->setCardCvc('123'); $transaction->card->setCardToken($tokenResponse->card->getCardToken()); $transaction->customer->setEmail('john@example.com'); $response = $transaction->submit(); ``` -------------------------------- ### Refund a payment (examples/refund.php) Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/child-transaction.md Shows how to refund a payment using RefundOperation, setting the parent UID, amount, and a reason, then submitting and checking the response. Source: examples/refund.php. ```php $refund = new BeGateway\RefundOperation; $refund->setParentUid($payment_response->getUid()); $refund->money->setAmount($payment->money->getAmount()); $refund->setReason('customer request'); $refund_response = $refund->submit(); if ($refund_response->isSuccess()) { echo 'Refunded. UID ' . $refund_response->getUid() . PHP_EOL; } else { echo 'Problem to refund: ' . $refund_response->getMessage() . PHP_EOL; } ``` -------------------------------- ### Create a limited or timed product with BeGateway\Product Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/product.md Creates a limited product with a quantity of 10 and an expiry date, sets customer email and additional metadata, then submits. On success, redirects to the pay link; on transport errors, logs the exception. ```php $limited = new BeGateway\Product; $limited->money->setAmount(9.99); $limited->money->setCurrency('USD'); $limited->setName('Limited offer'); $limited->setQuantity(10); // infinite becomes false; quantity = 10 $limited->setExpiryDate('2024-12-31T23:59:59+00:00'); // immortal becomes false $limited->customer->setEmail('buyer@example.com'); $limited->additional_data->setMeta(['campaign' => 'winter']); try { $res = $limited->submit(); // ResponseApiProduct; transport errors throw if ($res->isSuccess()) { header('Location: ' . $res->getPayLink()); } } catch (\Exception $e) { error_log($e->getMessage()); } ``` -------------------------------- ### Void an authorization (examples/void.php) Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/child-transaction.md Shows how to void an authorization using VoidOperation, setting the parent UID and amount, then submitting and checking the response. Source: examples/void.php. ```php $void = new BeGateway\VoidOperation; $void->setParentUid($auth_response->getUid()); $void->money->setAmount($authorize->money->getAmount()); $void_response = $void->submit(); if ($void_response->isSuccess()) { echo 'Voided. UID ' . $void_response->getUid() . PHP_EOL; } ``` -------------------------------- ### BeGateway\Settings::$apiBase Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/settings.md Static property for the product API base URL. ```APIDOC ## `BeGateway\Settings::$apiBase` ### Description Static property for the product API base URL. ### Type string ### Default `'https://api.begateway.com'` ### Usage ```php BeGateway\Settings::$apiBase = 'https://api.begateway.com'; ``` ``` -------------------------------- ### GET {gatewayBase}/v2/transactions/tracking_id/{tracking_id} Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/endpoints.md Queries a transaction by its tracking ID. ```APIDOC ## GET {gatewayBase}/v2/transactions/tracking_id/{tracking_id} ### Description Queries a transaction by its tracking ID. ### Method GET ### Endpoint {gatewayBase}/v2/transactions/tracking_id/{tracking_id} ### Parameters #### Path Parameters - **tracking_id** (string) - Required - The tracking ID of the transaction. ### Response #### Success Response - **transaction** (object) - Transaction details. ### Error Handling Transport exceptions are converted into an error `Response` by `ApiAbstract::submit()`. ``` -------------------------------- ### GET {gatewayBase}/v2/transactions/tracking_id/{tracking_id} Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/endpoints.md Queries a transaction by its tracking ID. ```APIDOC ## GET {gatewayBase}/v2/transactions/tracking_id/{tracking_id} ### Description Queries a transaction by its tracking ID. ### Method GET ### Endpoint {gatewayBase}/v2/transactions/tracking_id/{tracking_id} ### Path Parameters - **tracking_id** (string) - Required - The tracking ID to query. ### Authentication HTTP Basic auth using `Settings::$shopId` as username and `Settings::$shopKey` as password. ### Headers - `Accept: application/json` ### Response Returns a `Response` object. ``` -------------------------------- ### GET {checkoutBase}/ctp/api/checkouts/{token} Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/endpoints.md Queries a checkout by its payment token. ```APIDOC ## GET {checkoutBase}/ctp/api/checkouts/{token} ### Description Queries a checkout by its payment token. ### Method GET ### Endpoint {checkoutBase}/ctp/api/checkouts/{token} ### Path Parameters - **token** (string) - Required - The payment token to query. ### Authentication HTTP Basic auth using `Settings::$shopId` as username and `Settings::$shopKey` as password. ### Headers - `Accept: application/json` ### Response Returns a `ResponseCheckout` object. ``` -------------------------------- ### Configure BeGateway\Settings static properties Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/settings.md Sets the global static configuration values for the BeGateway library. Without $shopId and $shopKey set, outgoing requests fail at the gateway due to empty HTTP Basic auth credentials. Values come from your payment processor. ```php BeGateway\Settings::$shopId = 361; BeGateway\Settings::$shopKey = 'b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d'; BeGateway\Settings::$shopPubKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...'; BeGateway\Settings::$gatewayBase = 'https://demo-gateway.begateway.com'; BeGateway\Settings::$checkoutBase = 'https://checkout.begateway.com'; BeGateway\Settings::$apiBase = 'https://api.begateway.com'; ``` -------------------------------- ### Configure BeGateway\Logger singleton Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/configuration.md Configure the BeGateway\Logger singleton before making requests. Set log level, output file, a callback for forwarding log lines, and optionally disable PAN filtering (masking) which is enabled by default. ```php BeGateway\Logger::getInstance()->setLogLevel(BeGateway\Logger::DEBUG); // default level: INFO BeGateway\Logger::getInstance()->setOutputFile('/var/log/begateway.log'); // default output: php://stderr BeGateway\Logger::getInstance()->setOutputCallback(function ($message) { // forward log lines somewhere }); BeGateway\Logger::getInstance()->setPANfitering(false); // disable card number masking (default: true) ``` -------------------------------- ### POST {apiBase}/products Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/endpoints.md Creates a product on the BeGateway product API. ```APIDOC ## POST {apiBase}/products ### Description Creates a product on the BeGateway product API. ### Method POST ### Endpoint {apiBase}/products ### Authentication HTTP Basic auth using `Settings::$shopId` as username and `Settings::$shopKey` as password. ### Headers - `Accept: application/json` - `Content-type: application/json` (when request body is non-empty) ### Request Body JSON payload as defined by the `Product` class. ### Response Returns a `ResponseApiProduct` object. ``` -------------------------------- ### setCountry($country) / getCountry() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer country code. ```APIDOC ## setCountry($country) / getCountry() ### Description Sets or gets the customer country code. ### Method setCountry($country) / getCountry() ### Parameters - **$country** (string) - Required - The customer country code (e.g., 'LV', 'US'). ### Returns - **string|null** - The stored country code or null if not set. ### Example ```php $customer->setCountry('LV'); $country = $customer->getCountry(); ``` ``` -------------------------------- ### setAddress($address) / getAddress() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer street address. ```APIDOC ## setAddress($address) / getAddress() ### Description Sets or gets the customer street address. ### Method setAddress($address) / getAddress() ### Parameters - **$address** (string) - Required - The customer street address. ### Returns - **string|null** - The stored address or null if not set. ### Example ```php $customer->setAddress('Demo str 12'); $address = $customer->getAddress(); ``` ``` -------------------------------- ### POST {apiBase}/products Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/endpoints.md Creates a product for payment. ```APIDOC ## POST {apiBase}/products ### Description Creates a product for payment. ### Method POST ### Endpoint {apiBase}/products ### Request Body - **name** (string) - Required - Product name. - **description** (string) - Required - Product description. - **amount** (number) - Required - Product amount. - **currency** (string) - Required - Currency code. - **quantity** (number) - Optional - Quantity. - **infinite** (boolean) - Required - Whether the product is infinite. - **immortal** (boolean) - Required - Whether the product is immortal. - **expired_at** (string) - Optional - Expiration date. - **language** (string) - Required - Language code. - **URLs** (object) - Required - URLs for success, failure, etc. - **visible** (boolean) - Required - Visibility flag. - **test** (boolean) - Required - Test mode flag. - **transaction_type** (string) - Required - Transaction type. - **additional_data** (object) - Required - Additional data. ### Response #### Success Response - **id** (string) - Present on success; used to build payment links. ### Error Handling Transport exceptions propagate; application errors surface via `isError()`/`getMessage()`. ``` -------------------------------- ### setLastName($last_name) / getLastName() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer last name. ```APIDOC ## setLastName($last_name) / getLastName() ### Description Sets or gets the customer last name. ### Method setLastName($last_name) / getLastName() ### Parameters - **$last_name** (string) - Required - The customer last name. ### Returns - **string|null** - The stored last name or null if not set. ### Example ```php $customer->setLastName('Doe'); $lastName = $customer->getLastName(); ``` ``` -------------------------------- ### setEmail($email) / getEmail() Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/customer.md Sets or gets the customer email address. ```APIDOC ## setEmail($email) / getEmail() ### Description Sets or gets the customer email address. ### Method setEmail($email) / getEmail() ### Parameters - **$email** (string) - Required - The customer email address. ### Returns - **string|null** - The stored email address or null if not set. ### Example ```php $customer->setEmail('john@example.com'); $email = $customer->getEmail(); ``` ``` -------------------------------- ### Set and get card CVC Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Sets and retrieves the card CVC. ```php public function setCardCvc($cvc) public function getCardCvc() ``` -------------------------------- ### Configure BeGateway settings Source: https://github.com/begateway/begateway-api-php/blob/master/Readme.md Configure the BeGateway library with shop credentials and gateway endpoints. Required before using any library classes. The shopId and shopKey are provided by the payment processor. ```php BeGateway\Settings::$shopId = 361; BeGateway\Settings::$shopKey = 'b8647b68898b084b836474ed8d61ffe117c9a01168d867f24953b776ddcb134d'; BeGateway\Settings::$gatewayBase = 'https://demo-gateway.begateway.com'; BeGateway\Settings::$checkoutBase = 'https://checkout.begateway.com'; ``` -------------------------------- ### Set and get card holder Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Sets and retrieves the card holder name. ```php public function setCardHolder($holder) public function getCardHolder() ``` -------------------------------- ### Set and get card number Source: https://github.com/begateway/begateway-api-php/blob/master/_autodocs/api-reference/card.md Stores the PAN without validation in the library. ```php public function setCardNumber($number) public function getCardNumber() ```