PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 All 142 releases
← All changes | inc/rest-api/v1/frontend/class-lp-rest-gateway-webhook-controller.php +6 -66 4.3.7 → 4.4.10 View file →
@@ -52,15 +52,15 @@
52 52 * @param WP_REST_Request $request
53 53 *
54 54 * @return Response
55 55 * @since 4.3.7
56 - * @version 1.0.0
56 + * @version 1.0.2
57 57 */
58 58 public function listen_subscription_webhook( WP_REST_Request $request ): Response {
59 - $response = new Response();
59 + $response = new Response();
60 + $gateway_id = sanitize_key( (string) $request->get_param( 'gateway' ) );
60 61
61 62 try {
62 - $gateway_id = sanitize_key( (string) $request->get_param( 'gateway' ) );
63 63 if ( empty( $gateway_id ) ) {
64 64 throw new Exception( __( 'Gateway is required.', 'learnpress' ), 400 );
65 65 }
66 66
@@ -72,81 +72,21 @@
72 72 if ( ! $gateway->is_enabled() ) {
73 73 throw new Exception( __( 'Gateway is not enable.', 'learnpress' ), 404 );
74 74 }
75 75
76 - LP_Debug::log_to_comment( 'Webhook payload: ' . json_encode( $request->get_body(), JSON_UNESCAPED_UNICODE ) );
76 + //LP_Debug::log_to_comment( 'Webhook payload: ' . json_encode( $request->get_body(), JSON_UNESCAPED_UNICODE ) );
77 77
78 - // Test
79 - if ( isset( $_GET['pay'] ) ) {
80 - /** @var LP_Gateway_Paypal $gateway */
81 - $plan = $gateway->get_plan( 'P-8N4379132G8477049NIFPNJY' );
82 -
83 - $data_pay = [
84 - 'lp_order_id' => 94,
85 -// 'plan_id' => 'P-8N4379132G8477049NIFPNJY', // Not setup fee, trial 10 day
86 -// 'plan_id' => 'P-13E70519U63465016NIGWAMI', // Not fee, Not trial
87 -// 'plan_id' => 'P-4FB01122917417635NIHNBWI', // Fee, trial
88 - 'plan_id' => 'P-2MM29025B1701164HNIH4WGA', // Plan one day
89 - ];
90 - $g = $gateway->pay_via_subscription( $data_pay );
91 - $m = 2;
92 - return $response;
93 - }
94 - // End test
95 -
96 78 /**
97 79 * @var LP_Gateway_Paypal|LP_Gateway_Stripe $gateway
98 80 */
99 81 $gateway->capture_subscription_webhook( $request );
82 + $response->status = Response::STATUS_SUCCESS;
100 83 } catch ( Throwable $e ) {
84 + LP_Debug::log_to_comment( 'Webhook error: ' . $gateway_id . ' - ' . $e->getMessage() );
101 85 LP_Debug::error_log( $e );
102 86 $response->message = $e->getMessage();
103 87 }
104 88
105 89 return $response;
106 - }
107 -
108 - /**
109 - * Build sanitized REST error response for public webhook endpoint.
110 - *
111 - * Internal provider error details are logged server-side, while API
112 - * response returns a generic/safe message by status class.
113 - *
114 - * @param Throwable $error
115 - *
116 - * @return WP_REST_Response
117 - */
118 - protected function build_error_response( Throwable $error ): WP_REST_Response {
119 - $status = absint( $error->getCode() );
120 - if ( $status < 100 || $status > 599 ) {
121 - $status = 400;
122 - }
123 -
124 - $error_code = 'lp_subscription_webhook_error';
125 - $private_message = (string) $error->getMessage();
126 - $public_message = __( 'Invalid webhook request.', 'learnpress' );
127 -
128 - if ( 429 === $status ) {
129 - $public_message = __( 'Too many webhook requests.', 'learnpress' );
130 - } elseif ( 413 === $status ) {
131 - $public_message = __( 'Webhook payload too large.', 'learnpress' );
132 - }
133 -
134 - error_log(
135 - sprintf(
136 - 'LP subscription webhook error [%s]: %s',
137 - $error_code,
138 - $private_message
139 - )
140 - );
141 -
142 - return new WP_REST_Response(
143 - array(
144 - 'status' => 'error',
145 - 'code' => $error_code,
146 - 'message' => $public_message,
147 - ),
148 - $status
149 - );
150 90 }
151 91 }
152 92 }