Skip to content

Upa webhook flow - #553

Open
pratik-bharodiya wants to merge 6 commits into
developfrom
UPA-webhook-flow
Open

pratik-bharodiya wants to merge 6 commits into
developfrom
UPA-webhook-flow

Conversation

@pratik-bharodiya

Copy link
Copy Markdown
Collaborator

Description

  • Make a changes in UPA webhook flow as well make changes in existing logic for mark payment as done in magento side.
  • Order status and payment sync functionality are handle using dynamic webhook. Not relay on magento webhook setting.
  • Make existing Sync Order functionality work with UPA order as well.

Rollback procedure

default rollback procedure

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Existing configurations can omit required UPA webhooks, multi-store sync can use incorrect credentials, and the unit tests remain incompatible.

4 open findings
What changed in this PR

Moves UPA payment completion from the browser callback to dynamic webhooks and extends order synchronization for checkout sessions.

Changes:

  • Adds UPA dynamic webhook configuration and admin enforcement.
  • Resolves and persists charge IDs during webhook/manual synchronization.
  • Simplifies the UPA callback and centralizes the checkout endpoint.
File Description
view/​adminhtml/​web/​js/​upa-webhook-setting.js Synchronizes webhook controls with UPA configuration.
Plugin/​ConfigSectionPaymentPlugin.php Forces webhook settings when UPA is enabled.
Observer/​WebhookObserver/​WebhookCompleteObserver.php Persists UPA charge transaction identifiers.
Model/​SyncStatus.php Records charge identifiers after successful synchronization.
Model/​Config/​Config.php Defines the checkout-session endpoint.
Model/​Api/​CheckoutSession.php Retrieves the endpoint from configuration.
Helper/​OmiseHelper.php Resolves charge IDs from UPA sessions.
Gateway/​Request/​UPAPaymentDataBuilder.php Adds dynamic webhook URLs to UPA sessions.
etc/​adminhtml/​system.xml Adds custom webhook-setting renderers.
Controller/​Callback/​UPACallback.php Delegates payment processing to webhooks.
Block/​Adminhtml/​System/​Config/​Form/​Field/​UpaWebhookSetting.php Forces webhook controls for enabled UPA scopes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Controller/Callback/UPACallback.php Outdated
Comment on lines 63 to 67
try {
$payment = $order->getPayment();
$checkoutSession = $this->getCheckoutSession($payment);
$sessionPayments = $checkoutSession->payments;

if ($checkoutSession && !is_array($sessionPayments) || empty($sessionPayments)) {
$errorMessage = __('The payment session is invalid or no payment information was found. Please contact our support if you have any questions.');
return $this->redirectBackToCart($order, $errorMessage);
}

$sessionStatus = $checkoutSession->status;
$finalPayment = $this->getFinalPayment($sessionPayments, $sessionStatus);

if (!empty($finalPayment) && !empty($finalPayment['charge_id'])) {
$chargeId = $finalPayment['charge_id'];
$charge = $this->charge->find($chargeId);
} else {
$errorMessage = __('The payment session is invalid or no payment information was found. Please contact our support if you have any questions.');
return $this->redirectBackToCart($order, $errorMessage);
}

if (!$charge instanceof \Omise\Payment\Model\Api\BaseObject) {
throw new LocalizedException(
__('Couldn\'t retrieve charge transaction. Please contact administrator.')
);
}
if ($charge instanceof \Omise\Payment\Model\Api\Error) {
// restoring the cart
$this->checkoutSession->restoreQuote();
throw new LocalizedException(__($charge->getMessage()));
}
if ($charge->isFailed()) {
$this->handleFailure($charge);
return;
}

// Do not proceed if webhook is enabled
if ($this->config->isWebhookEnabled()) {
return $this->redirect(self::PATH_SUCCESS);
}

$payment->setTransactionId($charge->id);
$payment->setLastTransId($charge->id);
$payment->setAdditionalInformation('charge_id', $charge->id);

if ($charge->isSuccessful()) {
return $this->handleSuccess($order, $charge, $payment);
}

return $this->handlePending($order, $payment);
return $this->redirect(self::PATH_SUCCESS);
} catch (Exception $e) {
$this->cancel($order, $e->getMessage());
return $this->redirect(self::PATH_CART);
Comment on lines +121 to +124
if ($dynamicWebhookFlag && $webhookStatus) {
$webhookUrl = $store->getBaseUrl() . self::WEBHOOK_URI;
$payload['webhooks'] = [$webhookUrl];
}
Comment thread Helper/OmiseHelper.php
Comment on lines 235 to +238
public function __construct(
Config $config,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
OmiseCheckoutSession $omiseCheckoutSession
Comment thread Helper/OmiseHelper.php
Comment on lines +435 to +438
if ($order->getPayment()->getAdditionalInformation('session_id')){
$payment = $order->getPayment();
$sessionId = $payment->getAdditionalInformation('session_id');
$checkoutSession = $this->omiseCheckoutSession->getSessionInfo($sessionId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants