EU Withdrawal API
What it does
The API is part of Pro. It comes as two packages:
- EU Withdrawal API adds REST calls. A headless checkout, such as a PWA or a mobile app, uses them to show the digital-content waiver and record the customer's answer. Your own system uses one more call to report when a customer starts using digital content.
- EU Withdrawal GraphQL adds the same waiver as a GraphQL query and mutation.
You need the API if you sell digital items through a headless checkout, or if your system reports the start of performance for products you flagged. A store that sells only on the Luma, Breeze or Hyvä storefront does not need it. See What Pro adds.
Before you start
- Pro is installed and active. See Activate Pro.
- The digital-content waiver is set up. See Digital content.
- For GraphQL: Magento's GraphQL modules are on.
Steps
Install the packages
Run the commands in your Magento root folder. If you followed Activate Pro, both packages are already installed.
For REST only:
composer require mageme/module-eu-withdrawal-api
bin/magento module:enable MageMe_EUWithdrawalApi
bin/magento setup:upgrade
bin/magento cache:flush
For GraphQL, install both packages:
composer require mageme/module-eu-withdrawal-api mageme/module-eu-withdrawal-graph-ql
bin/magento module:enable MageMe_EUWithdrawalApi MageMe_EUWithdrawalGraphQl
bin/magento setup:upgrade
bin/magento cache:flush
Neither package has settings.
Record the waiver in a headless checkout
With Enforce Waiver on API / Headless Orders on Yes, the default, Magento refuses an API order with a digital item until the customer has accepted the waiver for each digital item. Your checkout records that acceptance before it places the order:
- Set the billing address of the cart. The texts depend on the store view's language and the billing country.
- Get the texts. The answer has
required, the consent text, the acknowledgment text, atext_hash, the locale and the cart items that need the waiver. Ifrequiredis false, the cart needs no waiver. - Show both texts to the customer, each with its own checkbox.
- When the customer has ticked both, send the acceptance with the
text_hashyou got and both values set to true. The acceptance covers every digital item of the cart. - Place the order.
The records are the same as from the storefront waiver step, so the order check accepts them. The customer gets the waiver confirmation email after the order, as with the storefront checkout.
Let your system report the start of performance
For a product with Start of Performance Reported by Integration (Art. 16(m)) set to Yes, your system reports when the customer gets access to the content. Until then the item can be withdrawn. See Reporting the start of performance from your system.
- Go to System → Extensions → Integrations and create an integration for your system, or open the one it has.
- On the API tab, give it the permission Report Start of Performance (API) under EU Withdrawal (ACL
resource
MageMe_EUWithdrawalApi::performance_report). - When the customer gets access, your system calls the start-of-performance route below with the integration's access token and the ID of the order item.
The waiver calls
REST
| Cart | Get the texts | Send the acceptance |
|---|---|---|
| Logged-in customer | GET /V1/carts/mine/eu-withdrawal/digital-waiver | POST /V1/carts/mine/eu-withdrawal/digital-waiver |
| Guest (masked cart ID) | GET /V1/guest-carts/:cartId/eu-withdrawal/digital-waiver | POST /V1/guest-carts/:cartId/eu-withdrawal/digital-waiver |
The POST body has textHash, consentExpress and lossAcknowledged. Each item in the answer has
quote_item_id, sku, name and accepted.
GraphQL
- Query
euWithdrawalDigitalWaiver(cart_id)returns the texts. - Mutation
acceptEuWithdrawalDigitalWaiver(input: {cart_id, text_hash, consent_express, loss_acknowledged})records the acceptance.
Each item in the answer has cart_item_id, sku, name and accepted.
Who can call them
The waiver can only come from the customer: the call uses the customer's own session or guest cart. There is no call for the admin or for an integration. Over GraphQL, an integration or admin token is refused.
When the acceptance is refused
- "The customer must tick both digital content waiver checkboxes." One of the two values was false.
- "The digital content waiver texts have changed. Load them again and show them to the customer." The texts changed
after you loaded them, for example because the billing country or the store view changed. Load the texts again,
show them and send the new
text_hash.
The start-of-performance call
The call is POST /V1/eu-withdrawal/order-items/:orderItemId/performance-started. It needs an integration with the
permission Report Start of Performance (API).
The module records the time of its own server, not a time your system sends. The answer is that time, in UTC. A second call for the same item changes nothing and returns the first time.
The call is refused with one of these messages:
- "The order item does not exist."
- "This item is not set up for a start of performance reported by your integration."
- "The customer has not given the digital content waiver for this item."
- "The waiver confirmation email for this item has not been sent yet."
- "A withdrawal request already covers this item, so a start of performance can no longer be recorded for it."
Without the API
The free module keeps the parts that do not need the API:
- the product flag Start of Performance Reported by Integration (Art. 16(m)), with the waiver step and the order check for flagged products;
- a PHP service your developer can call from their own Magento module to record a start;
- the warning on the request page while a flagged item has no reported start;
- the setting Enforce Waiver on API / Headless Orders.
Without the API, the waiver can be given only on the storefront waiver step. With Enforce Waiver on API / Headless Orders on Yes, every API order with a digital item is then refused. A headless store without Pro sets it to No, or does not sell digital items through the API. The Luma checkout also places its orders through the REST API, so No removes the check there as well. See An order placed outside the storefront is blocked.
What you should see
The GET call or the query returns the two texts and the digital items of the cart. After the acceptance, each item
shows accepted as true, and the order is placed. A start-of-performance call returns a time in UTC.
Limits
- The API covers the waiver and the start of performance only. There are no calls for withdrawal requests.
- The module does not check what your system reports. It records the time of the report.
- GraphQL needs both packages and Magento's GraphQL modules.
Troubleshooting
- An API order with a digital item is refused. The waiver is missing or out of date for an item. See An order placed outside the storefront is blocked.
- The GraphQL query is unknown. Install and enable both packages, and check that Magento's GraphQL modules are on.
- The start-of-performance call is refused with an access error. The integration lacks the permission Report Start of Performance (API), or its token is not active.
What's next
- Digital content: which products need the waiver.
- Digital content and the checkout waiver: what the customer sees on the storefront.
- Settings: Digital Waiver: Enforce Waiver on API / Headless Orders.