diff --git a/frontend/controllers/RefundController.php b/frontend/controllers/RefundController.php index 740d7ed34..5c9417183 100755 --- a/frontend/controllers/RefundController.php +++ b/frontend/controllers/RefundController.php @@ -78,7 +78,7 @@ public function actionCreate($storeUuid, $orderUuid) { $restaurant = Yii::$app->accountManager->getManagedAccount($storeUuid); - $order = Order::find()->where(['order_uuid' => $orderUuid])->exists(); + $order = Order::find()->where(['order_uuid' => $orderUuid])->one(); if ($restaurant && $order) { @@ -105,7 +105,14 @@ public function actionCreate($storeUuid, $orderUuid) { if (array_key_exists('errors', $response->data)) { - $model->addError('refund_amount', $response->data['errors'][0]['description']); + Yii::error([ + 'message' => 'Tap refund creation failed', + 'order_uuid' => $order->order_uuid, + 'refund_amount' => $model->refund_amount, + 'errors' => $response->data['errors'], + ], __METHOD__); + + $model->addError('refund_amount', 'Unable to create the refund right now. Please try again later.'); return $this->render('create', [ 'model' => $model, diff --git a/tests/check-frontend-refund-create-guard.sh b/tests/check-frontend-refund-create-guard.sh new file mode 100644 index 000000000..711cf32da --- /dev/null +++ b/tests/check-frontend-refund-create-guard.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +target="frontend/controllers/RefundController.php" + +grep -Fq "Order::find()->where(['order_uuid' => \$orderUuid])->one()" "$target" +grep -Fq "'Tap refund creation failed'" "$target" +grep -Fq "'Unable to create the refund right now. Please try again later.'" "$target" + +if grep -Fq "Order::find()->where(['order_uuid' => \$orderUuid])->exists()" "$target"; then + echo "refund create still stores order existence as a boolean before dereferencing payment" >&2 + exit 1 +fi + +if grep -Fq "addError('refund_amount', \$response->data['errors'][0]['description'])" "$target"; then + echo "refund create still exposes raw Tap refund errors to the form" >&2 + exit 1 +fi + +echo "Frontend refund create guard passed."