OrderPaidSubscriber is not placing paid orders from onNotify()

Created on 3 July 2023, over 1 year ago

Describe your bug or feature request.

The Drupal\commerce_payment\EventSubscriber\OrderPaidSubscriber event subscriber places the paid orders if the payment gateway supports notifications. I'm getting some limitations due to using specific use cases in terms of:

  1. The onPaid() method checks if the order is not draft while we use a workflow in which the order status would have a different state before it is placed.
  2. The onPaid() method checks if the payment gateway is an instance of OffsitePaymentGatewayInterface while it is possible for a gateway to implement SupportsNotificationsInterface without being an offsite payment gateway.

Proposed solution

  1. Replace if ($order->getState()->getId() != 'draft') with if (!$order->getState()->isTransitionAllowed('place'))
  2. Replace if ($payment_gateway->getPlugin() instanceof OffsitePaymentGatewayInterface) with if ($payment_gateway->getPlugin() instanceof SupportsNotificationsInterface)
🐛 Bug report
Status

Needs review

Version

2.0

Component

Payment

Created by

🇯🇴Jordan mhawwari

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mhawwari
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    785 pass
  • 🇮🇱Israel jsacksick

    While I agree with the first change, I'm not sure about the second one:
    The onPaid() method checks if the payment gateway is an instance of OffsitePaymentGatewayInterface while it is possible for a gateway to implement SupportsNotificationsInterface without being an offsite payment gateway.

    The reason being that for non offsite gateways, you technically remain on the site, and completing checkout should place the order.

  • 🇯🇴Jordan mhawwari

    The reason being that for non offsite gateways, you technically remain on the site, and completing checkout should place the order.

    In our specific case, we have a new payment gateway that inherits the stripe onsite payment gateway to create intents and handle the checkout process as an onsite payment with the addition of an onNotify() method to listen to a webhook for the payment resolution from stripe to complete/cancel the payment since it takes a few days to be confirmed.

    It is possible to make this into an offsitePaymentGateway but there will be no need for any of the methods that the interface provides.

  • 🇯🇴Jordan mhawwari

    I understand this is not the conventional use of SupportsNotificationsInterface so the question here would be if SupportsNotificationsInterface should be allowed to be implemented separately from offsitePaymentGatewayInterface if it provides an endpoint that can be utilized with gateway webhooks. Or should a payment gateway always be considered an offsite gateway to integrate notifications.

Production build 0.71.5 2024