Documentation

Payment system preparation

Payment system preparation

Interface \Bitrix\Sale\PaySystem\Cashbox\ISupportPrintCheck

You need to indicate that your payment system supports printing of receipts.

To do it, you need to implement the interface ISupportPrintCheck that has a 1 single method getCashboxClass:

public static function getCashboxClass(): string;

The method must return a string with the class name [link=13888374]cash registers[/link], using it to print receipts.

Example:

class RoboxchangeHandler extends PaySystem\ServiceHandler implements PaySystem\Cashbox\ISupportPrintCheck
{
    //...

    public static function getCashboxClass(): string
    {
        return '\\'.Cashbox\CashboxRobokassa::class;
    }
}

Trait \Bitrix\Sale\PaySystem\Cashbox\CheckTrait

For convenient handling of products to be passed in query when creating a payment in an external system, there is an available trait CheckTrait.

Trait has the method buildCheckQuery:

private function buildCheckQuery(Sale\Payment $payment): Sale\PaySystem\ServiceResult

Using this method delegates the product retrieval to a [link=13888374]cash register[/link]. This guarantees that products and products with closing receipt to be printed - will be identical.

Example

class RoboxchangeHandler extends PaySystem\ServiceHandler implements PaySystem\Cashbox\ISupportPrintCheck
{
    // Use the trait
    use PaySystem\Cashbox\CheckTrait;

    public function initiatePay(Payment $payment, Request $request = null)
    {
        $receipt = null;
        
        // Check if receipt data can/must be retrieved
        if ($this->service->canPrintCheckSelf($payment))
        {
            $receiptResult = $this->getReceipt($payment);
            if (!$receiptResult->isSuccess())
            {
                $result = new PaySystem\ServiceResult();
                $result->addErrors($receiptResult->getErrors());
                return $result;
            }

            $receipt = self::encode($receiptResult->getData());

            PaySystem\Logger::addDebugInfo(__CLASS__.": receipt = {$receipt}");
        }

        // $receipt will contain data for receipt to be sent to payment gate
    }

    private function getReceipt(Payment $payment): PaySystem\ServiceResult
    {
        $result = new PaySystem\ServiceResult();

        // Use the method buildCheckQuery from the trait
        $checkQueryResult = $this->buildCheckQuery($payment);
        if ($checkQueryResult->isSuccess())
        {
            // $receiptData will contain receipt data, retrieved from cash register
            $receiptData = $checkQueryResult->getData();
            if (!empty($receiptData['items']) && !empty($receiptData['sno']))
            {
                $result->setData([
                    'sno' => $receiptData['sno'],
                    'items' => $receiptData['items'],
                ]);
            }
            else
            {
                $result->addError(PaySystem\Error::create('Error generating the receipt'));
            }
        }
        else
        {
            $result->addErrors($checkQueryResult->getErrors());
        }

        return $result;
    }

    //...

    // Return cash register name
    public static function getCashboxClass(): string
    {
        return '\\'.Cashbox\CashboxRobokassa::class;
    }
}


© «Bitrix24», 2001-2022
Up