Skip to content
 Magento 2 · 25–35 min · advanced

Integrating Perfect Day into Magento 2.

Magento doesn't have a built-in webhook function—you'll need a small custom module that listens for the order event. This guide is intended for vendors with their own Magento developer or agency. If you don't have a developer, we recommend our setup service.

Required beforehand: Go once the general preparation This involves creating a coupon, obtaining the application password, and providing the webhook URL. It takes approximately five minutes and applies to all shop systems.

Three routes at a glance

  1. Which path suits you best?

    • Custom module Writing it yourself — around 2–3 hours of Magento development. Described in this guide.
    • Webhook extension Use from the Magento Marketplace + configure JSON mapping.
    • Hosted Bridge via Make.com / Zapier — no custom code required.

Option 1 — Custom module (for Magento developers)

  1. Create the attribute "pfd_coupon_id" for each product.

    Magento Admin → Stores → Attributes → Product„Add New Attribute". Attribute Code pfd_coupon_id, Input Type „Text Field", Required „No". Then under Stores → Attribute Set Assign the attribute to the appropriate group. Enter the ID for each coupon product in the product editor.

  2. Create a module structure

    The custom module consists of a few files:

    Directory structure
    app/code/DigElite/PerfectDayConnector/ ├── etc/ │ ├── module.xml │ └── events.xml ├── Observer/ │ └── OrderPaidObserver.php └── registration.php
  3. registration.php + module.xml

    The registration and module definition files are Magento standard. registration.php The module registers, etc/module.xml declares it with setup_version 1.0.0.

  4. events.xml — listen for the order-paid event

    Link the Observer to the Magento event sales_order_payment_pay:

    View full code — XML · etc/events.xml
    XML · etc/events.xml
  5. OrderPaidObserver.php — the actual shipping

    The observer collects the coupon IDs from the order items, constructs the payload, and sends it to the Perfect-Day webhook. Enter your username and application password into the constants.

    View full code — PHP · Observer/OrderPaidObserver.php
    PHP · Observer/OrderPaidObserver.php
    getEvent()->getPayment()->getOrder(); if (!$order) return; $items = []; foreach ($order->getAllItems() as $it) { $couponId = (int) $it->getProduct()->getData('pfd_coupon_id'); if ($couponId <= 0) continue; $items[] = ['coupon_id' => $couponId, 'count' => (int)$it->getQtyOrdered()]; } if (empty($items)) return; $payload = [ 'shop_order_id' => (string) $order->getIncrementId(), 'shop_type' => 'magento', 'shop_domain' => parse_url($order->getStore()->getBaseUrl(), PHP_URL_HOST), 'customer' => [ 'email' => $order->getCustomerEmail(), 'name' => trim($order->getCustomerFirstname() . ' ' . $order->getCustomerLastname()), 'locale' => substr($order->getStore()->getLocaleCode() ?: 'de', 0, 2), ], 'items' => $items, 'order_total_cents' => (int) round((float) $order->getGrandTotal() * 100), 'currency' => $order->getOrderCurrencyCode(), 'placed_at' => $order->getCreatedAt(), ]; $this->curl->setHeaders([ 'Content-Type' => 'application/json', 'Authorization' => 'Basic ' . base64_encode(self::PFD_USER . ':' . self::PFD_PWD), ]); $this->curl->post(self::PFD_URL, json_encode($payload)); } }
  6. Activate module

    Via CLI on the server:

    Bash
    bin/magento module:enable DigElite_PerfectDayConnector bin/magento setup:upgrade bin/magento cache:flush

Way 2 — Marketplace Extension + Mapping

  1. Configure webhook extension

    Using a commercial webhook extension: Trigger on Order Status Change → Paid set URL https://plattform.deinperfectday.de/wp-json/perfectday/shop/webhook/order, Header Authorization: Basic. Recreate the JSON format in the body mapping, and the custom attribute in the item mapping. pfd_coupon_id on items[*].coupon_id link them. Most webhook extensions can do this without any additional code.

Test order

  1. Place and check order

    Place a test order, pay, then in the platform back office under Perfect Day → Shop orders the entry with shop_type=magento Check. Check the customer mailbox for the brand email.

If something is stuck

Troubleshooting.

The Observer is not firing

Cache after setup:upgrade Not emptied? bin/magento cache:flush carry out.

Custom attribute remains empty

The attribute pfd_coupon_id is not assigned to any attribute set. Under Stores → Attribute Set catch up.

HTTP calls hang/block checkout

The Magento cron is blocking it. Move the HTTP call to a queue using... Magento\Framework\MessageQueue\PublisherInterface, instead of executing it synchronously in the Observer.

HTTP 401 / 403 / 400

Same error codes as in the other shops: 401 = Auth incorrect, 403 = Coupon ID does not belong to your account, 400 = invalid JSON body (often missing customer email).

Setup service

Would you prefer us to set it up for you?

Magento is the most complex of the supported shop systems. If you don't have developer access, we'll handle the custom module development — or we can host a bridge where you only need to provide Magento API access.

Frequently Asked Questions

Still questions?

Do I absolutely need a developer?
For option 1 (custom module), yes — it's true Magento development. Option 3 (hosted bridge via Make.com/Zapier) works without any custom code. Or you can use our setup service.
Why not just use a ready-made plugin?
Magento extensions must be very closely tailored to the specific Magento version and theme. A generic plugin would be more prone to errors than a lean custom module or a bridge. If there is sufficient demand, we will consider developing an official module.

Shop connected — and now what?

Once the webhook is running, all orders will automatically appear in your back office. If you need another connection, each additional shop can be set up in just a few minutes.

Go to shop overview