Setting up the sale of electronic certificates on 1C-Bitrix

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
    1177
  • 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
    747
  • 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

Setting Up Electronic Certificate Sales in 1C-Bitrix

Gift certificates in an online store on 1C-Bitrix are not just a product with a nice picture. Behind them lies unique code generation, PDF formation, automatic delivery to the buyer, and an activation mechanism through the coupon system of the sale module. Let's cover the implementation from product creation to partial balance redemption.

Certificate as a Catalog Product

An electronic certificate is created as a regular element of a catalog infoblock, but with specific features:

  • Product type — simple product without inventory tracking (quantity is unlimited, the "Quantitative accounting" checkbox is unchecked)
  • Trade offers — create SKUs by denominations: 1000, 2000, 5000 rubles. Each offer has its own price equal to the denomination
  • "Delivery type" property — set the value to "Electronic delivery" so the address is not requested during checkout

In the product card, add an infoblock property "Certificate Denomination" (type — number). This will be needed by the processor when generating the coupon.

Unique Code Generation

Upon successful order payment, the OnSalePayOrder event handler generates a unique certificate code. The code is formed via Bitrix\Main\Security\Random::getString(12) — 12 characters from the set A-Z, 0-9.

Handler logic:

  1. Check that the order contains a product from the "Certificates" section (by section ID of the infoblock)
  2. Generate the code
  3. Create a coupon via the API Bitrix\Sale\Internals\DiscountCouponTable::add() with binding to a cart rule
  4. Save the code and denomination in order properties (custom fields UF_CERTIFICATE_CODE, UF_CERTIFICATE_AMOUNT)

The coupon is created with the type "For a series of orders" and maximum usage count — this ensures partial usage.

PDF Formation

To generate a PDF certificate, use the mPDF or Dompdf library connected via Composer. The certificate template is an HTML file with variable substitution:

  • Certificate code
  • Denomination
  • Issue date and expiration date
  • QR code for quick activation (generated via chillerlan/php-qrcode or similar)

The HTML template is stored in /local/templates/certificate/ and contains inline styles (mPDF doesn't fully support external CSS). The background image is set via CSS background-image with an absolute path to the file on the server.

The result is saved in /upload/certificates/ with a name based on the certificate code. Access to the directory is closed via .htaccess — the file is served only through a PHP script with authorization verification.

Email Delivery

The mail event CERTIFICATE_CREATED is created in the Settings → Mail events section. The letter template contains:

Macro Value
#CODE# Certificate code
#AMOUNT# Denomination
#VALID_UNTIL# Expiration date
#PDF_LINK# Link to download PDF

Sending is initiated from the same OnSalePayOrder handler after PDF generation. The letter is sent to the buyer's email from the order. If a separate recipient email is specified in the order (the "Certificate recipient email" field) — the letter is also sent there.

Activation and Cart Rules

The certificate redemption mechanism works through the sale.discount module. When creating a coupon, a cart rule is created:

  • Discount type — fixed amount equal to the certificate denomination
  • Binding — a coupon whose code matches the certificate code
  • Scope of application — the entire order (or specific catalog sections if the certificate is category-specific)

The buyer enters the certificate code in the "Coupon" field during checkout. The system applies a discount for the denomination amount.

Partial Usage and Balance

The standard Bitrix coupon system doesn't support coupon balance out of the box. For partial redemption, additional development is required:

  • The OnSaleOrderPaid handler checks whether the certificate coupon was used in the paid order
  • If the order amount is less than the denomination — calculates the remaining balance
  • Updates the cart rule: new discount amount = remaining balance
  • Records usage history in a separate table (custom table b_certificate_usage)

If the order amount is greater than or equal to the denomination — the coupon is deactivated via DiscountCouponTable::update() with the ACTIVE field = N.

The certificate balance is displayed in the buyer's personal account through a custom component that reads data from b_certificate_usage and the current cart rule.

Expiration Date

The period is set in the cart rule via the ACTIVE_FROM and ACTIVE_TO fields. The standard period is 12 months from the purchase date. After the period expires, the coupon automatically stops applying, and the certificate is displayed in the personal account as "Expired".

A working implementation of certificates will require creating a module or at least a set of handlers in init.php, a custom table for history, and a PDF template. The scope of work is 20–30 hours depending on design requirements and business logic.