CoolCMS API

OrderPaymentManager
in package

FinalYes

Creates the System payment for an order and links it through `cms_mod_eshop_order_payments`.

The payment is always created after the order (the reverse order would allow paying for something that does not exist) and its amount comes only from the stored order (roundedTotalPriceWithVat); no number is accepted from the client.

paymentCallbackId points to the cms_system_payment_callbacks row with the key self::CALLBACK_KEY, which must target EshopPaymentHook::handlePayment(). The wiring is verified before a payment is created (checkCallbackWiring()): if the callback pointed elsewhere, a paid order would stay "awaiting payment" forever and nobody would notice. Refusing to create the order is safer than paying blindly.

Tags
phpstan-import-type

TOrderGraph from OrderCalculator

Table of Contents

Constants

CALLBACK_KEY  : string = 'ESHOP_ORDER'
EXPECTED_CLASS  : string = \App\UI\Api\Eshop\Models\Managers\EshopPaymentH...
EXPECTED_METHOD  : string = 'handlePayment'
ORDER_DONE_PAGE_SLUG  : int = \App\Core\Routers\PageId::ESHOP_ORDER_DONE
Fixed id of the order return page (`cms_system_pages`).
ORDER_PAYMENTS_TABLE  : string = 'cms_mod_eshop_order_payments'

Properties

$em  : EntityManagerInterface
$linkGenerator  : LinkGenerator
$paymentCallbackManager  : PaymentCallbackManager
$paymentManager  : PaymentManager

Methods

__construct()  : mixed
checkCallbackWiring()  : array{success: false, errorCode: string, message: string}|null
Verifies that the `ESHOP_ORDER` callback targets {@see EshopPaymentHook}; called before creating an order that needs a payment gateway.
createForOrder()  : Result
Creates the payment for an order and inserts the `order_payments` row (a repeated call is a no-op: the primary key is the orderId and paymentId pair).
callbackId()  : int|null
orderReturnUrl()  : string|null
Returns the absolute URL of the order return page (front `OrderDone`).

Constants

EXPECTED_CLASS

private string EXPECTED_CLASS = \App\UI\Api\Eshop\Models\Managers\EshopPaymentHook::class

ORDER_DONE_PAGE_SLUG

Fixed id of the order return page (`cms_system_pages`).

private int ORDER_DONE_PAGE_SLUG = \App\Core\Routers\PageId::ESHOP_ORDER_DONE

ORDER_PAYMENTS_TABLE

private string ORDER_PAYMENTS_TABLE = 'cms_mod_eshop_order_payments'

Properties

Methods

checkCallbackWiring()

Verifies that the `ESHOP_ORDER` callback targets {@see EshopPaymentHook}; called before creating an order that needs a payment gateway.

public checkCallbackWiring() : array{success: false, errorCode: string, message: string}|null
Return values
array{success: false, errorCode: string, message: string}|null —

null = wiring OK

createForOrder()

Creates the payment for an order and inserts the `order_payments` row (a repeated call is a no-op: the primary key is the orderId and paymentId pair).

public createForOrder(TOrderGraph $order, int $paymentGateId) : Result
Parameters
$order : TOrderGraph
$paymentGateId : int
Return values
Result —

success data: array{paymentId: int}

orderReturnUrl()

Returns the absolute URL of the order return page (front `OrderDone`).

private orderReturnUrl(int $orderId) : string|null

A link generation failure must not fail the payment creation; the customer then lands on the generic system page instead of the order detail.

Parameters
$orderId : int
Return values
string|null
On this page

Search results