-
Notifications
You must be signed in to change notification settings - Fork 17
Dev Events
The Mollie plugin provides a few events that you can use to customize the behaviour of specific parts in the payment flow on your own.
- Payment Status Update
- Order Status Update
- Apple Pay Direct Shippings
- Apple Pay Direct Update Shipping
- Webhook Received
Please note, all customizations in this area lead to a matching LOG entry if something has been changed on your side. This is important to differ between Mollie default behaviour and custom modifications.
If you want to listen to updates of the payment status by Mollie, you can use the custom event for this. The arguments give you access to the suggested status, along with the Mollie status and the affected order.
Set a new custom status ID of from the database table s_core_states
if you
somehow need to use a different status.
public static function getSubscribedEvents()
{
return [
Events::UPDATE_ORDER_PAYMENT_STATUS => 'onUpdateOrderPaymentStatus',
];
}
public function onUpdateOrderPaymentStatus(\Enlight_Event_EventArgs $args)
{
/** @var string $molliePaymentStatus */
$molliePaymentStatus = $args->get('molliePaymentStatus');
/** @var Order $order */
$order = $args->get('order');
/** @var int $targetPaymentStatus */
$targetPaymentStatus = $args->getReturn();
# set payment status to ID #4
$args->setReturn(4);
}
If you want to listen to updates of the order status by Mollie, you can use the custom event for this. Please note that this is only fired if you turned on the feature in the plugin configuration.
The arguments give you access to the suggested status, along with the Mollie payment status and the affected order.
Set a new custom status ID of from the database table s_core_states
if you
somehow need to use a different status.
public static function getSubscribedEvents()
{
return [
Events::UPDATE_ORDER_STATUS => 'onUpdateOrderStatus',
];
}
public function onUpdateOrderStatus(\Enlight_Event_EventArgs $args)
{
/** @var string $mollieOrderStatus */
$mollieOrderStatus = $args->get('mollieOrderStatus');
/** @var Order $order */
$order = $args->get('order');
/** @var int $targetOrderStatus */
$targetOrderStatus = $args->getReturn();
# set order status to ID #4
$args->setReturn(4);
}
You might want to control the possible shipping options individually for your Apple Pay Direct method. You the custom event to modify the list of shippings that the user will see.
public static function getSubscribedEvents()
{
return [
Events::APPLEPAY_DIRECT_GET_SHIPPINGS => 'onApplePayDirectGetShippings',
];
}
public function onApplePayDirectGetShippings(\Enlight_Event_EventArgs $args)
{
/** @var string $userCountryIso2 */
$userCountryIso2 = $args->get('country');
/** @var array $shippings */
$shippings = $args->getReturn();
# ...
# adjust shippings list
# ...
# assign new shippings to event
$args->setReturn($shippings);
}
If you want to overwrite the used shipping method of the Apple Pay Direct customer, you can easily listen to that event too. It will give you access to modify the shipping identifier which is the shipping ID of Shopware.
public static function getSubscribedEvents()
{
return [
Events::APPLEPAY_DIRECT_SET_SHIPPING => 'onApplePayDirectUpdateShipping',
];
}
public function onApplePayDirectUpdateShipping(\Enlight_Event_EventArgs $args)
{
/** @var string $shippingIdentifier */
$shippingIdentifier = $args->getReturn();
# search for the appropriate identifier (id)
$shippingIdentifier = "12";
# set the new shipping method
$args->setReturn($shippingIdentifier);
}
If you want to listen to received webhooks, Mollie provides a special event for that too. You will get every information that you need to do your custom handling on webhooks of an order.
public static function getSubscribedEvents()
{
return [
Events::WEBHOOK_RECEIVED => 'onWebhookReceived',
];
}
public function onWebhookReceived(\Enlight_Event_EventArgs $args)
{
$orderId = $args->get('orderId');
$orderNumber = $args->get('orderNumber');
$paymentMethod = $args->get('paymentMethod');
$molliePaymentId = $args->get('molliePaymentId');
$molliePaymentStatus = $args->get('molliePaymentStatus');
}
German Support: [email protected] | International Support: [email protected]