← All changes
|
inc/rest-api/v1/frontend/class-lp-rest-gateway-webhook-controller.php
+2
-45
4.4.2
→
4.4.9.1
View file →
| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | * @param WP_REST_Request $request |
| 53 | 53 | * |
| 54 | 54 | * @return Response |
| 55 | 55 | * @since 4.3.7 |
| 56 | - * @version 1.0.1 | |
| 56 | + * @version 1.0.2 | |
| 57 | 57 | */ |
| 58 | 58 | public function listen_subscription_webhook( WP_REST_Request $request ): Response { |
| 59 | 59 | $response = new Response(); |
| 60 | 60 | $gateway_id = sanitize_key( (string) $request->get_param( 'gateway' ) ); |
| @@ -78,8 +78,9 @@ | ||
| 78 | 78 | /** |
| 79 | 79 | * @var LP_Gateway_Paypal|LP_Gateway_Stripe $gateway |
| 80 | 80 | */ |
| 81 | 81 | $gateway->capture_subscription_webhook( $request ); |
| 82 | + $response->status = Response::STATUS_SUCCESS; | |
| 82 | 83 | } catch ( Throwable $e ) { |
| 83 | 84 | LP_Debug::log_to_comment( 'Webhook error: ' . $gateway_id . ' - ' . $e->getMessage() ); |
| 84 | 85 | LP_Debug::error_log( $e ); |
| 85 | 86 | $response->message = $e->getMessage(); |
| @@ -85,51 +86,7 @@ | ||
| 85 | 86 | $response->message = $e->getMessage(); |
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | return $response; |
| 89 | - } | |
| 90 | - | |
| 91 | - /** | |
| 92 | - * Build sanitized REST error response for public webhook endpoint. | |
| 93 | - * | |
| 94 | - * Internal provider error details are logged server-side, while API | |
| 95 | - * response returns a generic/safe message by status class. | |
| 96 | - * | |
| 97 | - * @param Throwable $error | |
| 98 | - * | |
| 99 | - * @return WP_REST_Response | |
| 100 | - */ | |
| 101 | - protected function build_error_response( Throwable $error ): WP_REST_Response { | |
| 102 | - $status = absint( $error->getCode() ); | |
| 103 | - if ( $status < 100 || $status > 599 ) { | |
| 104 | - $status = 400; | |
| 105 | - } | |
| 106 | - | |
| 107 | - $error_code = 'lp_subscription_webhook_error'; | |
| 108 | - $private_message = (string) $error->getMessage(); | |
| 109 | - $public_message = __( 'Invalid webhook request.', 'learnpress' ); | |
| 110 | - | |
| 111 | - if ( 429 === $status ) { | |
| 112 | - $public_message = __( 'Too many webhook requests.', 'learnpress' ); | |
| 113 | - } elseif ( 413 === $status ) { | |
| 114 | - $public_message = __( 'Webhook payload too large.', 'learnpress' ); | |
| 115 | - } | |
| 116 | - | |
| 117 | - error_log( | |
| 118 | - sprintf( | |
| 119 | - 'LP subscription webhook error [%s]: %s', | |
| 120 | - $error_code, | |
| 121 | - $private_message | |
| 122 | - ) | |
| 123 | - ); | |
| 124 | - | |
| 125 | - return new WP_REST_Response( | |
| 126 | - array( | |
| 127 | - 'status' => 'error', | |
| 128 | - 'code' => $error_code, | |
| 129 | - 'message' => $public_message, | |
| 130 | - ), | |
| 131 | - $status | |
| 132 | - ); | |
| 133 | 90 | } |
| 134 | 91 | } |
| 135 | 92 | } |