When integrating 1C-Bitrix with Halyk Bank, developers often encounter errors in callback notification processing and incorrect caching of access tokens. This leads to lost orders and broken payment chains. Callbacks often arrive late or not at all, causing double charges and customer dissatisfaction. Our team has 5+ years of experience and 50+ successful Halyk Bank integrations. Let's examine how to properly set up the interaction and avoid common pitfalls.
Halyk Bank—Kazakhstan's largest bank—provides internet acquiring via the Halyk eCommerce payment gateway (formerly HomeBank). The gateway accepts Visa, Mastercard, American Express, and payments through the HalykPay mobile app. Integration with Bitrix is implemented using a standard payment module with PHP handlers. Our years of development experience with Bitrix and dozens of successful integration projects with payment gateways, including Halyk Bank, ensure correct handling of all statuses and refunds. We hold Bitrix certifications and have extensive experience developing modules.
This article thoroughly covers integration architecture, provides code examples for creating payments and handling callbacks, and offers recommendations for typical errors. You'll learn how to set up two-stage payments and refunds, and how to cache tokens for reliable operation.
Integration of 1C-Bitrix with Halyk Bank: from method selection to payment processing
What connection method should you choose?
Halyk Bank provides several connection options: Halyk eCommerce (redirect), Halyk API (direct processing), and HalykPay. Below is a comparison by key parameters:
| Method |
Complexity |
PCI DSS |
Implementation Time |
Cost Savings |
Recommendation |
| Halyk eCommerce (Redirect) |
Low |
Not required |
2-3 days |
Up to 0.5% of turnover |
For most stores |
| Halyk API (Direct) |
High |
Required |
5-7 days |
None |
For large platforms |
| HalykPay |
Medium |
Not required |
3-4 days |
Varies |
For mobile apps |
For 90% of Kazakhstani online stores, the redirect scheme is optimal. It removes the responsibility for storing card data and speeds up time-to-market by 2 times compared to direct processing. Savings on acquiring commission can reach 0.5% of turnover. The redirect scheme is 2 times faster to implement than direct processing, and saves up to 0.5% of turnover in commission fees.
Setting up the redirect scheme
Redirecting to the bank's payment form relieves the store of responsibility for storing card data—no need to undergo PCI DSS audit. Implementation time is reduced by 40-50% compared to direct processing. Additionally, this scheme simplifies support and updates of the payment module.
Integration architecture: step-by-step
- Obtain terminal ID, client_id, client_secret, and gateway URLs from Halyk Bank. For testing, use the test environment at https://test.epayment.halykbank.kz to simulate payments in Halyk Bank test mode.
- Implement token retrieval using OAuth2 client credentials.
- Create an invoice with necessary parameters (amount, order ID, callback URLs).
- Handle callback notifications by verifying with an additional API request.
- Set up token caching and refresh logic.
Obtaining an access token:
$tokenUrl = 'https://epayment.halykbank.kz/api/public/v1/auth/token';
$ch = curl_init($tokenUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'client_credentials',
'client_id' => $clientId,
'client_secret' => $clientSecret,
'scope' => 'webapi usermanagement email_send verification statement statistics payment',
'terminal' => $terminal,
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tokenData = json_decode(curl_exec($ch), true);
$accessToken = $tokenData['access_token'];
Creating a payment:
$orderId = $payment->getOrder()->getId();
$amount = $payment->getSum(); // in tenge
$invoiceData = [
'amount' => $amount,
'currency' => 'KZT',
'terminal' => $terminal,
'invoiceId' => $orderId,
'description' => 'Order No.' . $orderId,
'language' => 'rus',
'postLink' => $callbackUrl,
'failurePostLink' => $callbackUrl,
'backLink' => $returnUrl,
'failureBackLink' => $failUrl,
];
$ch = curl_init('https://epayment.halykbank.kz/api/public/v1/invoices/create');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken,
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($invoiceData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$invoice = json_decode(curl_exec($ch), true);
$invoiceId = $invoice['id'];
$paymentUrl = 'https://epayment.halykbank.kz/pay/invoices/' . $invoiceId;
// Redirect customer to $paymentUrl
Handling callback notifications
Halyk sends a POST to postLink on payment or error:
$rawBody = file_get_contents('php://input');
$data = json_decode($rawBody, true);
$invoiceId = $data['id']; // Halyk invoice ID
$orderId = $data['invoiceId']; // our orderId
$txStatus = $data['status']; // 'CHARGED', 'DECLINED', 'CANCELLED'
// Verification: request status via API
$verification = $this->httpGet(
'https://epayment.halykbank.kz/api/public/v1/check-transaction',
['invoiceId' => $orderId],
['Authorization: Bearer ' . $accessToken]
);
if ($verification['status'] === 'CHARGED') {
$order = \Bitrix\Sale\Order::loadByAccountNumber($orderId);
// setPaid('Y'), save()
}
http_response_code(200);
Statuses that may arrive:
| Status |
Meaning |
| CHARGED |
Successfully charged |
| DECLINED |
Declined by bank |
| CANCELLED |
Cancelled by customer |
| AUTHENTICATED |
Authorized (waiting for confirmation) |
Setting up two-stage payments
Halyk supports the "authorization + confirmation" scheme:
// Create invoice with parameter "preAuth": true
$invoiceData['preAuth'] = true;
// After order processing—confirm the charge
$confirmData = [
'invoice_id' => $halykInvoiceId,
'amount' => $amount,
];
$this->httpPost('https://epayment.halykbank.kz/api/public/v1/confirm', $confirmData, $headers);
// Or cancel the hold
$this->httpPost('https://epayment.halykbank.kz/api/public/v1/cancel', ['invoice_id' => $halykInvoiceId], $headers);
Processing refunds
$refundData = [
'invoice_id' => $halykInvoiceId,
'amount' => $refundAmount,
'reason' => 'Order refund',
];
$this->httpPost(
'https://epayment.halykbank.kz/api/public/v1/refund',
$refundData,
['Authorization: Bearer ' . $accessToken, 'Content-Type: application/json']
);
Refreshing the access token
The access token has a limited lifetime. We recommend implementing caching and automatic refresh. Upon receiving HTTP 401, re-request the token and retry the request. Save both invoice IDs: invoiceId (yours) and id (Halyk's internal) — they are needed for refunds and verification.
Common beginner mistakes and how to avoid them
Beginners often skip callback verification through an additional API request, leading to fake confirmations. The second mistake is not caching the token: requesting a new token on every call increases response time by 20-30%. The third is not handling the AUTHENTICATED status in two-stage schemes, causing money to be held but not charged. Our experience shows these issues occur in 70% of projects at the start.
What's included in the work?
- Analysis of current payment logic on Bitrix
- Design of integration scheme (redirect or direct)
- Module development with handlers for token, invoice, callback
- Setup of two-stage payments (if needed)
- Implementation of refunds and token caching
- Testing in test and production environments
- Documentation and training for your team
- 30-day warranty support
Additionally, we offer turnkey Halyk Bank integration with 1C-Bitrix, including full project management. Typical integration cost ranges from $1,500 to $3,000 depending on complexity.
Development timeline
| Task |
Time |
| Token retrieval + invoice creation + callback |
2–3 days |
| Two-stage payments |
+1 day |
| Refunds |
+1 day |
| Token caching + retry logic |
+0.5 day |
| Testing |
0.5–1 day |
Total timeline — 3 to 6 working days. Pricing is calculated individually after project assessment. Get a consultation—contact us to propose the best solution for your store. Order integration—we will audit your store and offer an optimal solution. Assess your project in 1 day—write to us.
Official Halyk Bank API documentation
How can you avoid typical mistakes when connecting payment systems on 1C-Bitrix?
The most common mistake during integration is forgetting about the callback. The customer paid for the order, the money was debited, but the status in b_sale_order did not update: the manager sees "Awaiting payment" and starts calling the client. The reason is an incorrect URL in the gateway settings or a handler that returns a 500 error for an atypical response structure. We offer services for connecting payment systems on 1C-Bitrix with full testing of all scenarios: successful payment, refusal, timeout, partial refund, duplicate callback.
Why are callbacks critical?
Each payment gateway sends a notification to your server. If the handler does not guarantee idempotency, a double call will lead to a double charge. We always implement a check by notification ID (external_id) and block repeated processing in \Bitrix\Sale\Order. It is also critical to set the callback URL in the aggregator's personal account – /bitrix/tools/sale_ps_result.php for the standard module. If you use a custom handler, we verify that it returns HTTP 200 even in case of parameter errors (the gateway should not repeat the request indefinitely).
Example of a simple callback handler with signature verification
use Bitrix\Sale\Order;
use Bitrix\Main\Application;
// Get notification data
$data = Application::getInstance()->getContext()->getRequest()->toArray();
// Check signature (depends on aggregator)
if (!checkSignature($data, 'SECRET_KEY')) {
die('FAIL');
}
// Find order by external ID
$order = Order::loadByExternalId((int)$data['order_number']);
if ($order && $order->isPaid() === false) {
$order->setField('PAYED', 'Y');
$order->save();
}
echo 'OK';
How do we optimize payment flow for higher conversion?
How to choose a payment aggregator for 1C-Bitrix?
The choice of aggregator depends on the geography of customers, average order value, and need for installments. For Russia, the basic set is YooKassa (all main methods, fiscalization out of the box) and CloudPayments (widget on the page without redirect, Apple Pay). If you work with large corporate clients, add Sberbank (SberPay, SBP). For international sales, use Stripe or PayPal. We often use a two-tier scheme: main aggregator + backup (auto-switching on failure).
What payment gateways and methods do we use?
YooKassa
One contract – all main methods: Visa/MasterCard/MIR cards, YooMoney, SberPay, internet banking, installments. Fiscalization under 54-FZ out of the box (via the sale module). The standard handler /bitrix/modules/sale/handlers/paysystem/yandexpay/ covers basic scenarios. For holding (two-stage payment), subscriptions, or split payments, custom integration via YooKassa API v3. Callback is configured to /bitrix/tools/sale_ps_result.php, we parse notification and update \Bitrix\Sale\Order via setField('PAYED', 'Y').
CloudPayments
Focused on conversion: the payment widget directly on the checkout page, without redirect to an external domain. The customer does not leave the site – the abandonment rate during payment drops. It supports recurring payments (card tokenization via cryptogram), Apple Pay, and Google Pay. 3D Secure with intelligent routing – requested only for high fraud risk. Integration with Bitrix – via CloudPayments REST API and a custom handler in the sale module.
Tinkoff Payment
API integration via TinkoffPaymentAPI (ready-made module or manual implementation). QR code for payment via the app, "Tinkoff Credit" installment – critical for expensive goods. Partial refunds via the Cancel method – without calling the bank, everything from the Bitrix admin panel.
Sberbank (SberPay and SBP)
SberPay – payment via push notification or QR, SBP – commission 0.4–0.7% vs 1.5–2.5% for cards. This is a significant savings on volume. Holding via registerPreAuth / deposit API. Note that SberPay requires a separate agreement with the bank.
Apple Pay and Google Pay
Payment in two clicks, without entering card data. They are connected through an aggregator (YooKassa, CloudPayments, Tinkoff). Important nuances:
- Apple Pay requires domain verification: the file
apple-developer-merchantid-domain-association in /.well-known/. Without it, the button will not appear.
- Button placement strictly according to Apple and Google guidelines – otherwise rejection in review.
- Fallback to the standard payment form if the device does not support contactless payment.
| Payment method |
Devices |
Browsers |
| Apple Pay |
iPhone, iPad, Mac |
Safari |
| Google Pay |
Android, Chrome |
Chrome, Firefox, Edge |
| Samsung Pay |
Samsung Galaxy |
Samsung Internet |
How do we handle installments, BNPL, and 54-FZ compliance?
If the average order value is above 30,000 RUB and conversion drops, installment removes the price barrier. We connect:
- Tinkoff Installment (3–24 months)
- Buy with Sber
- Mokka / Dolyami – BNPL: 4 payments, 0% for the buyer
Integration: widget with monthly payment calculation on the product card ("from 2,500 RUB/month"), order data transfer to the bank via API, status processing (approval, rejection, awaiting documents) in OnSaleStatusOrder handlers.
Fiscalization under 54-FZ is a mandatory requirement. The fine for a missing receipt is up to 100% of the payment amount. In accordance with Federal Law No. 54-FZ, an electronic receipt must be sent to the buyer. We connect ATOL Online, Orange Data, Module.Kassa, Evotor, Shtrikh-M. Setup in Bitrix – the "Cash Registers" section in the sale module:
- VAT rate, item and method of payment – an error in any field can lead to a fine during inspection.
- Receipts for prepayment and partial payment (two receipts: at payment and at shipment).
- Refund receipts upon cancellation via
\Bitrix\Sale\Cashbox\Cashbox::addChecks().
- Monitoring: if the receipt is not sent, an alert to the manager.
When selling shoes, clothing, or perfumes, it is mandatory to transfer marking codes in the receipt. Integration with "Chestny ZNAK", scanning DataMatrix during order assembly, automatic removal from circulation upon sale via \Bitrix\Catalog\Product\Marking.
Payment support: refunds, multicurrency, security
Refunds
Full and partial refund without calling the bank – via the aggregator API (refund / cancel). The refund receipt is generated automatically, the order status is updated, the amount is recalculated, and the customer is notified. Timeframes: e-wallets and SBP – 1–3 days, bank card – up to 30 business days (depends on the issuing bank).
Multicurrency
Price types in b_catalog_price for each currency, rates via the Central Bank API (\Bitrix\Currency\CurrencyManager::updateCBRFRates()) or manual input. Conversion at the catalog level – the customer sees prices in their currency. For accepting dollars/euros, we connect Stripe, PayPal. We take into account conversion fees when calculating margin.
Security
Card data is processed on the certified gateway side (PCI DSS) – the card number never passes through your server. Anti-fraud at the aggregator level. Logging all events in b_sale_order_change for audit. Anomaly monitoring: transaction spike, atypical geography – alert.
How we work and estimated timelines
- Analysis – what payment methods are needed, markets, transaction volume, current aggregator.
- Solution selection – sometimes two aggregators are better than one: YooKassa as the main, CloudPayments as backup – if one fails, traffic goes to the second.
- Integration – we test each scenario: successful payment, 3DS refusal, gateway timeout, double callback, partial refund.
- Fiscalization – online cash register, checking the correctness of receipts on test orders.
- Monitoring – alerts for gateway failures, conversion dashboard at the payment stage.
| Task |
Estimated timeframe |
| Connection of one payment system |
2–5 days |
| Comprehensive payment setup (multiple aggregators) |
1–2 weeks |
| Connection of online cash register (54-FZ) |
3–5 days |
| Installment integration |
3–5 days |
| Multicurrency setup |
1 week |
| Full payment infrastructure |
3–5 weeks |
What is included in the work
- Full setup of selected payment systems in 1C-Bitrix: modules, handlers, callbacks, testing.
- Integration documentation (gateway operation scheme, handler description, logic).
- Training your manager to work with payment modules and refunds.
- Technical support during launch and the first 2 weeks of operation.
- Monitoring – we set up alerts for errors and conversion drops.
All work is performed by certified 1C-Bitrix developers. We guarantee the operability of each scenario. For a quick assessment of your project, get a consultation – just leave a request on the website. Order turnkey payment system integration with fiscalization and data protection. Contact us to choose the optimal solution for your business – we will help with the aggregator selection and implement the full integration cycle.