diff --git a/plugins/cipf_plugin/js/paypal/on_approve.js b/plugins/cipf_plugin/js/paypal/on_approve.js index ff73786..9f70a98 100644 --- a/plugins/cipf_plugin/js/paypal/on_approve.js +++ b/plugins/cipf_plugin/js/paypal/on_approve.js @@ -34,8 +34,11 @@ export async function onApprove(data, actions) { throw new Error(`${errorDetail.description} (${orderData.debug_id})`); } else if (!orderData.purchase_units) { + // Check if error was a server-side issue but PayPal confirmed payment if (orderData.ERROR_TREATMENT) { - console.log("Capture result",orderData); + console.log("Capture result - Server processing error, but payment may be valid:",orderData); + // Display problem message - payment succeeded on PayPal but failed locally + // User stays on page to see the message resultMessage(PLGNTLS_data.paypal_message_problem); } else { @@ -48,15 +51,14 @@ export async function onApprove(data, actions) { const transaction = orderData?.purchase_units?.[0]?.payments?.captures?.[0] || orderData?.purchase_units?.[0]?.payments?.authorizations?.[0]; - console.log("Capture result",orderData); + console.log("Capture result - Success:",orderData); resultMessage(PLGNTLS_data.paypal_message_success); actions.redirect(PLGNTLS_data.paypal_redirection_success); } } catch (error) { - console.error(error); + console.error("Payment approval error:", error); resultMessage(PLGNTLS_data.paypal_message_failure); actions.redirect(PLGNTLS_data.paypal_redirection_failure); } } - diff --git a/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php b/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php index 3e70a1f..35ec02f 100644 --- a/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php +++ b/plugins/cipf_plugin/php/paypal/route_api_orders_capture.php @@ -18,10 +18,6 @@ function handle_orders_capture_request_CIPF($request) { /* - * ask paypal about the finished order - * update the client situation - * and return the response of paypal - * * capture status : https://developer.paypal.com/docs/api/orders/v2/#definition-order_status * - COMPLETED * - DECLINED @@ -32,11 +28,11 @@ function handle_orders_capture_request_CIPF($request) { * */ try { - $response_json = capture_order_cipf($order_id); + $response_json = capture_order_CIPF($order_id); $http_status_code = $response_json['http_status_code']; $json_response = $response_json['json_response']; - update_user_post_capture_CIPF($json_response, 'end'); + update_user_post_capture_CIPF($json_response); return new WP_REST_Response($json_response, $http_status_code); } diff --git a/plugins/cipf_plugin/php/paypal/update_user_payment.php b/plugins/cipf_plugin/php/paypal/update_user_payment.php index ccf3717..d907056 100644 --- a/plugins/cipf_plugin/php/paypal/update_user_payment.php +++ b/plugins/cipf_plugin/php/paypal/update_user_payment.php @@ -98,8 +98,17 @@ function update_user_post_capture_CIPF($message) { if ($user_id_to_update === false) { throw new HttpException('cannot find user with this order_id', 502); } - if ($status === 'COMPLETED') { - // proceed to validate payment for user + /* + * PayPal capture status: https://developer.paypal.com/docs/api/orders/v2/#definition-order_status + * - COMPLETED: Payment captured successfully + * - PENDING: Payment authorized, awaiting capture (valid for some payment methods) + * - DECLINED: Payment was declined + * - PARTIALLY_REFUNDED: Order partially refunded + * - REFUNDED: Order fully refunded + * - FAILED: Order failed + */ + if ($status === 'COMPLETED' || $status === 'PENDING') { + // proceed to validate payment for user (both COMPLETED and PENDING are successful) success_payment_for_user_CIPF($user_id_to_update, $order_id); } else {