Skip to main content
Version: 2.0.0

Developer / API

Plugin API

yui\barion\Plugin implements yStore's yui\craft\base\collector\PaymentMethodRegistryInterface and registers itself with the store's PaymentMethodRegistry once all plugins have loaded (Plugins::EVENT_AFTER_LOAD_PLUGINS). The methods below are the contract yStore calls into; they are not normally called directly from custom code, but are useful to know when debugging a checkout integration.

use yui\barion\Plugin;

$details = Plugin::$plugin->getDetails();
MethodPurpose
getDetails(): arrayReturns the payment method descriptor yStore uses to list Barion at checkout: name, code/handle (barion), type (online), instructions, price, enabled, plus url, logo, and description for the CP/checkout UI. Returns [] and logs on error.
placeOrder(array $data, array $items, ?string $code = null): arrayBuilds and sends the Barion payment request for an order. Returns ['extra' => [...], 'redirectUrl' => ...] on success (see below), or [] if the order data/items are invalid or Barion returned an error.
postValidate(?array $params): arrayCalled on the checkout return/callback. Reads paymentId from the current request, fetches the Barion payment state, and returns ['success' => bool, 'paid' => float, 'status' => string]. success is only true when Barion's status is Succeeded.
getPaymentRetryUrl(array $order, array $items): ?stringAlways returns null in this plugin version — Barion payment retry is not implemented as a distinct URL; the customer restarts checkout instead.
getApi(): ApiServiceReturns the plugin's ApiService component (Plugin::$plugin->get('api')).
getLicense(): LicenseServiceReturns the plugin's license service component, shared with the CP License page.

placeOrder() success payload

[
'extra' => [
'paymentId' => $results->PaymentId,
'paymentRequestId' => $results->PaymentRequestId,
'paymentStatus' => $results->Status,
'qUrl' => $results->QRUrl,
'resurrectedResults' => $results->RecurrenceResult,
'paymentRedirectUrl' => $results->PaymentRedirectUrl,
],
'redirectUrl' => $results->PaymentRedirectUrl,
];

redirectUrl is what the storefront sends the customer's browser to — Barion's hosted payment page.

ApiService

yui\barion\services\ApiService (Plugin::$plugin->get('api') / Plugin::$plugin->getApi()) wraps the barion/barion-web-php SDK (BarionClient). It's only instantiated with a live BarionClient when the plugin is enabled; the environment (BarionEnvironment::Prod vs ::Test) is chosen from Enable SandboxMode at construction time.

MethodPurpose
prepare(array $data, array $items): selfBuilds the Barion transaction + payment request models from raw order $data (via DataHelper::extractOrderData()) and $items (via DataHelper::extractOrderItems()). Chainable — call ->send() next. Throws if $data or $items is empty.
send()Sends the prepared payment request to Barion (BarionClient::PreparePayment) and returns the PreparePaymentResponseModel, or logs and returns nothing on error.
getPaymentDetails(?string $identifier)Calls BarionClient::GetPaymentState($identifier) and returns the PaymentStateResponseModel, or false on error.
testCredentials(): boolCalls getPaymentDetails('test') and checks whether Barion responds with an AuthenticationFailed error — used by the settings page's Test Credentials action.

BARION_API_VERSION is fixed at 2.

DataHelper

yui\barion\helpers\DataHelper prepares data for ApiService::prepare() and is not normally called directly, but its output shape is useful for integration debugging:

  • extractOrderData(array $data): array — validates order_id, increment_id, email, and grand_total are present, then returns the normalized order array (total, comment, transaction_id, payment_request_id, redirectUrl, callbackUrl, …) consumed by ApiService. Throws yii\db\Exception when required order fields are missing.
  • extractOrderItems(array $items): array — maps yStore order line items (Craft element objects with toArray()) to the name/description/qty/ unit/price/rowTotal/handle shape Barion's ItemModel expects. Prices are divided by 100 (yStore stores minor units) and formatted to two decimal places.
  • generateTransactionId() / generatePaymentRequestId() — build a TRANSACTION-{site_id}-{order_id}-{random} / PAYMENT-{site_id}-{order_id}-{random} string and AES-256-ECB encrypt it (keyed by the plugin handle) before it's sent to Barion as POSTransactionId/PaymentRequestId.
  • getPaymentStatusList(): array — returns the full list of Barion payment statuses with human-readable labels and descriptions; see Payment statuses below.

Payment statuses

DataHelper::getPaymentStatusList() documents every status Barion can return for a payment (PaymentStateResponseModel->Status):

StatusMeaning
PreparedPayment is prepared; can still be completed unless the payment time window expires.
StartedPayer has started the payment with a funding source.
InProgressBarion is currently communicating with the bank card processing system; the payment cannot be altered.
WaitingPaid by bank transfer, result not yet known (Payment Buttons scenarios).
ReservedCompleted by the payer but the amount is still reserved; must be finished before the reservation period expires.
AuthorizedCompleted by the payer but not yet charged; must be finished before the authorization period expires.
CanceledExplicitly cancelled/rejected by the payer. Final.
SucceededFully completed. Final. This is the only status Plugin::postValidate() treats as a successful, paid order.
FailedFailed for unknown reasons (bank-transfer scenarios).
PartiallySucceededSome transactions in a complex reservation payment finished, others didn't; becomes Succeeded once all finish.
ExpiredThe payment expired.

Only Succeeded marks an order as paid in this plugin version — if you build custom logic that needs to react to Reserved/Authorized (delayed-capture-style flows), call ApiService::getPaymentDetails() directly rather than relying on postValidate().

Control panel routes

Registered on UrlManager::EVENT_REGISTER_CP_URL_RULES, all under barion/*:

  • barion/settings — settings page (SettingsController::actionIndex).
  • barion/settings/test — runs ApiService::testCredentials() and redirects back with a success/error flash (SettingsController::actionTest).
  • barion/license, barion/license/redeem, barion/license/activate, barion/license/revoke, barion/license/delete, barion/license/copy-token — license management, shared AbstractLicenseController flow used by other YUI plugins.

There are no anonymous/site-facing routes registered by this plugin directly — the checkout redirect to Barion and the return callback are driven through yStore's own checkout controllers calling Plugin::placeOrder() / Plugin::postValidate(), not through Barion-specific URLs.

Extensibility

This plugin version does not register its own Craft events, permissions, or MCP tools — extension points are the public Plugin/ApiService methods above. To react to a Barion payment outside the standard checkout flow (for example, a delayed-capture reconciliation job), call Plugin::$plugin->getApi()->getPaymentDetails($paymentId) directly and branch on the status table above.