Integration of 1C-Bitrix with the Alfa-Bank acquiring payment system

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1173
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    745
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Integration of 1C-Bitrix with Alfa-Bank Payment System

Alfa-Bank is one of the most common payment gateways for Russian online stores. It provides a REST API for accepting card payments with support for 3-D Secure, hold, and refunds.

How the Integration Works

Standard payment scenario:

  1. Customer selects card payment and clicks "Pay"
  2. Bitrix creates an order, calls the order registration method in Alfa-Bank API
  3. API returns orderId and formUrl (payment form URL)
  4. Customer is redirected to Alfa-Bank payment form
  5. After payment — redirect to store returnUrl
  6. Alfa-Bank sends callback to failUrl/returnUrl or via separate webhook
  7. Bitrix checks status via API, confirms payment

Connection: What You Need to Get From the Bank

  • Login and password for test and production gateway (or token instead of login/password)
  • Gateway URL — test (https://alfa.rbsuat.com/payment/rest/) and production (https://pay.alfabank.ru/payment/rest/)
  • Access to personal account for transaction monitoring

Implementing a Payment System Handler

Alfa-Bank is connected as a payment system of the sale module. Handler files structure in /local/php_interface/include/sale_payment/alfa_bank/:

handler.php        — handler class
.description.php   — metadata
.settings.php      — settings: login, password, gateway URL, mode (test/live)
template/          — button template

Handler class inherits from \Bitrix\Sale\PaySystem\ServiceHandler. Key methods:

initiatePay — order registration and form URL retrieval:

public function initiatePay(\Bitrix\Sale\Payment $payment, \Bitrix\Main\Request $request = null)
{
    $order = $payment->getOrder();
    $sum   = $payment->getSum();

    $params = [
        'userName'   => $this->getBusinessValue($payment, 'ALFA_LOGIN'),
        'password'   => $this->getBusinessValue($payment, 'ALFA_PASSWORD'),
        'orderNumber'=> $order->getId(),
        'amount'     => (int)($sum * 100),   // in kopecks
        'currency'   => 643,                 // RUB
        'returnUrl'  => $this->getReturnUrl($payment),
        'failUrl'    => $this->getReturnUrl($payment) . '?fail=1',
        'description'=> 'Payment for order #' . $order->getId(),
    ];

    $response = $this->apiRequest('register.do', $params);

    if (!empty($response['errorCode']) && $response['errorCode'] !== '0') {
        return \Bitrix\Sale\PaySystem\ServiceResult::createError($response['errorMessage']);
    }

    // Save Alfa-Bank orderId for later verification
    $this->saveAlfaOrderId($payment, $response['orderId']);

    return \Bitrix\Sale\PaySystem\ServiceResult::createRedirect($response['formUrl']);
}

processRequest — process customer return and status verification:

public function processRequest(\Bitrix\Sale\Payment $payment, \Bitrix\Main\Request $request)
{
    $alfaOrderId = $this->getAlfaOrderId($payment);
    if (!$alfaOrderId) {
        return \Bitrix\Sale\PaySystem\ServiceResult::createError('Alfa orderId not found');
    }

    $status = $this->apiRequest('getOrderStatus.do', [
        'userName' => $this->getBusinessValue($payment, 'ALFA_LOGIN'),
        'password' => $this->getBusinessValue($payment, 'ALFA_PASSWORD'),
        'orderId'  => $alfaOrderId,
    ]);

    // orderStatus: 2 = paid
    if (isset($status['orderStatus']) && $status['orderStatus'] == 2) {
        $payment->setPaid('Y');
        return \Bitrix\Sale\PaySystem\ServiceResult::create();
    }

    return \Bitrix\Sale\PaySystem\ServiceResult::createError('Payment not confirmed');
}

Two-Stage Payments (Hold)

Alfa-Bank supports a two-stage scheme: first hold (registerPreAuth.do), then confirmation (deposit.do) or reversal (reverse.do). For stores with payment after verifying product availability, this is the correct scheme.

// Hold
$response = $this->apiRequest('registerPreAuth.do', $params);

// Confirmation (when shipping goods)
$this->apiRequest('deposit.do', [
    'userName' => $login,
    'password' => $password,
    'orderId'  => $alfaOrderId,
    'amount'   => (int)($sum * 100),
]);

Refunds

Alfa-Bank API supports full and partial refunds via the refund.do method:

$this->apiRequest('refund.do', [
    'userName' => $login,
    'password' => $password,
    'orderId'  => $alfaOrderId,
    'amount'   => (int)($refundAmount * 100),  // partial refund
]);

Refund is initiated from Bitrix code when canceling an order. Add a handler for the OnSaleOrderCanceled event:

AddEventHandler('sale', 'OnSaleOrderCanceled', function(\Bitrix\Main\Event $event) {
    $order = $event->getParameter('ENTITY');
    // Find payment with the needed payment system, call refund.do
});

Fiscalization (FZ-54)

For online stores required to issue receipts, Alfa-Bank supports passing receipt data in the order registration request via the taxSystem parameter and the orderBundle object with order items. Items are taken from Bitrix basket ($order->getBasket()), VAT rates from catalog settings.

Testing

In Alfa-Bank test environment, use card 4111111111111111, expiry 12/26, any CVV. Test should include full cycle: registration → form → payment → return to site → status check → payment update in Bitrix.

Development Timeline

Task Duration
Basic handler: registration + status check 2–3 days
Two-stage payments +1–2 days
Refunds from Bitrix +1 day
Fiscalization (receipts) +2–3 days
Full cycle testing 1 day