Repository navigation
Upa webhook flow - #553
Open
pratik-bharodiya wants to merge 6 commits into
Open
Upa webhook flow#553pratik-bharodiya wants to merge 6 commits into
pratik-bharodiya wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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 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 on lines
235
to
+238
| public function __construct( | ||
| Config $config, | ||
| ScopeConfigInterface $scopeConfig | ||
| ScopeConfigInterface $scopeConfig, | ||
| OmiseCheckoutSession $omiseCheckoutSession |
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Rollback procedure
default rollback procedure