The last checkout page: Payment instructions with entity 12345, a nine-digit reference and the amount, 59,90 €.
The Payment information pane at checkout with MB WAY chosen and the mobile number 912345678 entered right below it, above the note that the payment is finalized in the MB WAY app.
The end of checkout with the request status on: Confirm the payment in the MB WAY app, the request sent to 912 345 678, a ring with 3:12 left to confirm in the app, the number and the amount, 59,90 €, and Wrong number? Change number.
The Multibanco gateway settings: Reference generation set to Offline (entity/sub-entity) instead of API (MB Key), with entity 12345 and sub-entity 123.
Referências Multibanco, MB WAY e cartões de crédito

Commerce ifthenpay adds the payment methods Portuguese shoppers expect to a Drupal Commerce store, through ifthenpay: Multibanco references paid at an ATM or in home banking, MB WAY payments approved on the phone, and credit cards. When ifthenpay confirms a payment, it calls the site and the order is marked as paid, with no one checking bank statements.

Features

  • 🏦 Multibanco references. At the end of checkout the customer gets an entity, a reference and the amount, to pay at any ATM or in home banking. References come from the ifthenpay API with your MB Key, with an optional expiry date the customer sees, or are computed from your entity and sub-entity with no call to ifthenpay.
  • 🔒 Payments confirmed by ifthenpay. When a payment arrives, ifthenpay calls the site and the order is marked as paid. Every callback must carry your anti-phishing key, a Multibanco callback must match its payment's entity and amount, and an MB WAY notification must be signed with your MB WAY key, so a forged or mismatched call pays nothing.
  • 🧩 MB WAY sub-module. The customer enters a mobile number at checkout and approves the payment in the MB WAY app. The request goes through the ifthenpay MB WAY API, which tells the site whether it was paid, declined in the app or expired, and each payment records the outcome. A repeated request for the same order within 90 seconds is refused, so a double submit does not send the customer two. An option on the gateway shows the field for the number right below the MB WAY option at checkout, instead of after every payment method, and another keeps a single MB WAY option when the customer comes back to the payment step, with the number they gave in the field.
  • ⏱️ MB WAY request status. With one option on the gateway, the end of checkout counts down the four minutes the customer has to accept the request in the app, turns to paid as soon as the payment arrives, says so at once when the customer declines the request in the app, and then, or once the request expires, sends it again, to the same number or another one. The time left comes from the site, so a reload does not restart it.
  • 🔗 Payment links. A signed link, for a reminder email the site sends, opens a page where the customer pays an unpaid order by MB WAY without signing in. It shows the order and the number masked, never the email, sends nothing when opened, and expires after seven days or the days set on the gateway.
  • 📱 MB WAY requests sent again. Staff can send a new request from the order, and a storefront can let customers do it through a POST endpoint, limited to the order's owner or a payment link, protected by a CSRF token and rate limited. Older pending requests are voided once ifthenpay accepts the new one.
  • 🧩 Credit card sub-module. The customer pays on ifthenpay's card page and comes back to the store, where the return is checked against a signature made with your card key before the payment is completed.
  • 💰 Refunds through ifthenpay. With the backoffice key ifthenpay sends when the contract is signed, MB WAY and credit card payments are refunded in full or in part from the order's Payments tab. The payment changes only when ifthenpay confirms the refund; a refusal, or a balance too low to cover it, leaves the payment as it was and says why.
  • 🛒 Managed from the order. On the order's Payments tab, staff can add a Multibanco reference or an MB WAY request, mark a payment as received, and void one. With Commerce Core's Commerce Log module, each reference generated through the API, and each callback whose amount does not match, is written to the order's activity log.

 Payment instructions with entity 12345, a nine-digit reference and the amount, 59,90 €.

Quick start

composer require drupal/commerce_ifthenpay
drush en commerce_ifthenpay
  1. At Commerce > Configuration > Payment gateways, click Add payment gateway, give it a Name and pick Ifthenpay - Multibanco as the Plugin.
  2. Under Reference generation, choose API (MB Key) - recommended and paste the MB Key ifthenpay assigned you, or Offline (entity/sub-entity) with your Multibanco - Entidade and Multibanco - Subentidade. Fill in the Chave AntiPhishing and save.
  3. In the ifthenpay backoffice, register the callback URL the README gives for your mode, with the gateway's machine name in it.
  4. Place an order and choose Multibanco: the last checkout page shows the entity, the reference and the amount, and the order is marked as paid when ifthenpay calls back.

The Payment information pane at checkout with MB WAY chosen and the mobile number 912345678 entered right below it, above the note that the payment is finalized in the MB WAY app.

MB WAY at checkout: the customer enters a mobile number and approves the payment on the phone.

12 left to confirm in the app, the number and the amount, 59,90 €, and Wrong number? Change number.

The request status: the time left to accept the request in the app, counted by the site.

 Reference generation set to Offline (entity/sub-entity) instead of API (MB Key), with entity 12345 and sub-entity 123.

The two ways to generate Multibanco references, each with its trade-off stated in the form.

Good to know

  • Multibanco and card payments are confirmed automatically only once the callback URL of each method is registered in the ifthenpay backoffice, or activated by ifthenpay support. Until then, orders stay unpaid. Each MB WAY request carries the site's notification URL itself, so ifthenpay can reach any site that is public over HTTPS; when a notification does not arrive, the site asks ifthenpay once the request's time is up.
  • In offline mode, order IDs above 9999 are mapped to four digits, so two orders can get the same reference. The callback is then matched to a payment by amount and state, and the collision is logged; the API mode has no collisions.
  • What goes to ifthenpay: for a Multibanco reference from the API, the MB Key, the order ID and the amount; for MB WAY, the MB WAY key, the order ID, the amount, the customer's mobile number and the site's notification URL; for a card payment, the order ID, the amount and the return URLs; for a refund, the backoffice key, the payment's request ID and the amount. No name or email address is sent.
  • ifthenpay pays refunds out of the account balance, which holds only the payments received since 8 PM the previous day and not yet transferred, so a refund the balance cannot cover has to be tried again later. The refund API has no sandbox: every refund reaches the production account.
  • The request status and the payment link page come with plain markup and little CSS, for the theme to style. Without the request status, the MB WAY resend endpoint has no button of its own: a theme or a front end calls it.
  • Test the API mode with Use sandbox endpoint ticked: ifthenpay warns that abuse of its production API can lock the account.

Additional requirements

  • Drupal 10 or 11.
  • Commerce Core 2 or 3, with its Payment module, and its Cart module for MB WAY.
  • An ifthenpay account with the credentials of each method: an MB Key or an entity and sub-entity for Multibanco, an MB WAY key, a card key, and the backoffice key for refunds.

Recommended modules/libraries

  • ChatGPT Ads: its Conversions API sub-module reports a purchase when the order is paid, so an order paid by Multibanco or MB WAY hours after checkout still counts as a conversion of ads in ChatGPT.

Community documentation

  • README: the two reference modes, the callback URL to register for each method, the MB WAY status notifications and request status, payment links and resend endpoint, refunds, and troubleshooting.

Supporting this module

Developed and maintained by Bloomidea. Bloomidea offers support and custom development for this module.

Supporting organizations: 
Development and maintenance

Project information

Releases