Skip to content
OnCharge.io
View as Markdown
Developer docs

Magento 2 (beta)

The module adds OnCharge as a payment method to Magento Open Source and Adobe Commerce 2.4.4 or later (PHP 8.1+). It creates the checkout session for each order with its shipping address, shows the OnCharge checkout by redirect or embedded in a store page, updates orders from signed webhooks, reports shipment tracking so delivered orders are paid out, refunds online from credit memos, and serves the RUO compliance feed.

Install#

The module is a Composer package (oncharge/module-payments). Add the package source OnCharge gives you as a Composer repository, then:

Shell
composer require oncharge/module-payments:^1.0
bin/magento module:enable OnCharge_Payments
bin/magento setup:upgrade
bin/magento setup:di:compile                  # production mode only
bin/magento setup:static-content:deploy -f    # production mode only
bin/magento cache:flush

Magento's cron must run: the module uses it to process webhooks and resend pending tracking numbers.

Configure#

Stores → Configuration → Sales → Payment Methods → OnCharge

Setting
Enabled, Title, DescriptionWhat shoppers see at checkout.
API Key / API SecretFrom the OnCharge portal. The secret is stored encrypted and never reaches the browser.
EnvironmentProduction (https://app.oncharge.io). Use a custom base URL only if OnCharge support asks.
Payment ActionSale: the order is invoiced when OnCharge confirms the payment. Authorize: the payment is recorded and you create the invoice (Capture Online checks with OnCharge that the payment was captured).
Checkout DisplayRedirect to the OnCharge checkout page, or Embedded on a payment page in your store using the hosted script.
Callback Signing SecretRegister https://<your store>/oncharge/webhook as the store's webhook URL in the OnCharge portal and paste the oc_cbsec_… secret it shows once.
Countries, order total limits, sort order, debug loggingStandard payment method options.

Register your store's domain under Security → Domains in the OnCharge portal: OnCharge accepts return URLs and framing only on registered domains.

How it works#

In MagentoWith OnCharge
The customer places the orderThe order is created as Pending Payment.
The browser goes to /oncharge/checkout/startPOST /api/v1/checkout/sessions with the amount, the increment ID as order_id, the shipping address and line items, and an idempotency key; then the redirect or the embedded page.
The shopper returns to /oncharge/checkout/returnThe session status picks the page to show (success, or the cart restored). It never changes the order.
OnCharge calls /oncharge/webhookOnCharge-Signature is verified (legacy header only when it is absent) and event IDs are deduplicated. payment.captured invoices the order (Sale) or records the authorization (Authorize) after checking amount and currency; payment.refused and payment.cancelled cancel it; refund.succeeded confirms refunds; chargeback.opened puts the order on hold; delivery.confirmed adds a comment.
A shipment tracking number is savedPOST /api/v1/shipments; Magento carrier codes map to USPS, UPS, FedEx or DHL Express. The result is added as an order comment, and pending numbers are resent by cron every 15 minutes.
An online credit memoPOST /api/v1/refunds with an idempotency key.

RUO stores: compliance review#

The same settings page has a Compliance Review group:

  1. In the OnCharge portal, add your store host, choose Magento and set the base path to /oncharge/compliance. Paste the one-time connection code (occs_…) into Connection Code and save.
  2. Select Verify connection in the portal.
  3. Set up reviewer access: a separate customer account with the same access a verified buyer has. Enter its email, sign in as it once to check that it shows every product with its price, then set I Signed In as This Account to Yes.

The feed serves active CMS pages and every enabled product with its own page (including products hidden from search), up to 5,000 items, at:

Text
GET /oncharge/compliance/proof?challenge=<hex64>&ts=<unix>
GET /oncharge/compliance/content?cursor=<n>&limit=<n>      (signed)
GET /oncharge/compliance/reviewer-access                    (signed)

Building your own Magento integration#

If you prefer to integrate yourself, follow Custom & headless: create the session from your payment method's server-side code, render the checkout with the script tag, handle webhooks in a CSRF-exempt controller and report tracking from a sales_order_shipment_track_save_after observer. The PHP signing example works as-is.