| @@ -188,8 +188,16 @@ | ||
| 188 | 188 | $data = $request->get_json_params(); |
| 189 | 189 | |
| 190 | 190 | try { |
| 191 | 191 | $payment = $this->paymentService->createPayment($data); |
| 192 | + | |
| 193 | + // The service reports validation failures (unknown booking, invalid | |
| 194 | + // status) as ['success' => false]; answering 201 made the admin form | |
| 195 | + // redirect as if the payment had been saved. | |
| 196 | + if (is_array($payment) && isset($payment['success']) && !$payment['success']) { | |
| 197 | + return new WP_REST_Response($payment, 400); | |
| 198 | + } | |
| 199 | + | |
| 192 | 200 | return new WP_REST_Response($payment, 201); |
| 193 | 201 | } catch (\Exception $e) { |
| 194 | 202 | return new WP_Error('payment_creation_failed', $e->getMessage(), ['status' => 400]); |
| 195 | 203 | } |
| @@ -207,8 +215,12 @@ | ||
| 207 | 215 | $payment = $this->paymentService->updatePayment($id, $data); |
| 208 | 216 | |
| 209 | 217 | if (!$payment) { |
| 210 | 218 | return new WP_Error('payment_not_found', 'Payment not found', ['status' => 404]); |
| 219 | + } | |
| 220 | + | |
| 221 | + if (is_array($payment) && isset($payment['success']) && !$payment['success']) { | |
| 222 | + return new WP_REST_Response($payment, 400); | |
| 211 | 223 | } |
| 212 | 224 | |
| 213 | 225 | return new WP_REST_Response($payment, 200); |
| 214 | 226 | } catch (\Exception $e) { |