PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
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 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | inc/gateways/subscriptions/class-lp-subscription-manager.php +265 -253 4.3.7 → 4.4.9 View file →
@@ -55,173 +55,174 @@
55 55 * order_id?:int,
56 56 * renewal_order_id?:int,
57 57 * message?:string
58 58 * }
59 + * @deprecated 4.3.8 Use LP_Gateway_Abstract::capture_subscription_webhook() instead.
59 60 */
60 - public function process_webhook_event( LP_Gateway_Abstract $gateway, array $event ): array {
61 - $gateway_id = $gateway->get_id();
62 - $event_id = sanitize_text_field( (string) ( $event['event_id'] ?? '' ) );
63 - $event_type = sanitize_key( (string) ( $event['event_type'] ?? '' ) );
61 +// public function process_webhook_event( LP_Gateway_Abstract $gateway, array $event ): array {
62 +// $gateway_id = $gateway->get_id();
63 +// $event_id = sanitize_text_field( (string) ( $event['event_id'] ?? '' ) );
64 +// $event_type = sanitize_key( (string) ( $event['event_type'] ?? '' ) );
65 +//
66 +// if ( empty( $event_id ) ) {
67 +// $event_id = md5( wp_json_encode( $event ) );
68 +// }
69 +//
70 +// $response = array(
71 +// 'status' => 'ignored',
72 +// 'event_id' => $event_id,
73 +// 'event_type' => $event_type,
74 +// 'status_code' => 200,
75 +// );
76 +//
77 +// try {
78 +// $order_subscription_id = $this->resolve_parent_order_id( $event );
79 +// $order_subscription = $order_subscription_id ? learn_press_get_order( $order_subscription_id ) : false;
80 +// $this->validate_parent_subscription_binding( $order_subscription, $event );
81 +//
82 +// if ( $this->is_event_already_handled( $event_type, $event_id, $order_subscription, $event ) ) {
83 +// return array(
84 +// 'status' => 'duplicate',
85 +// 'event_id' => $event_id,
86 +// 'event_type' => $event_type,
87 +// 'status_code' => 200,
88 +// );
89 +// }
90 +//
91 +// if ( $order_subscription ) {
92 +// $this->sync_subscription_meta( $order_subscription->get_id(), $event );
93 +// }
94 +//
95 +// switch ( $event_type ) {
96 +// case 'subscription_activated':
97 +// if ( ! $order_subscription ) {
98 +// throw new Exception( __( 'Order not found.', 'learnpress' ) );
99 +// }
100 +//
101 +// $this->update_subscription_status( $order_subscription->get_id(), 'active' );
102 +// // Team convention: activated means the subscription order becomes completed.
103 +// $this->mark_parent_payment_completed( $order_subscription, $event );
104 +// $order_subscription->add_note( __( 'Subscription activated.', 'learnpress' ) );
105 +// do_action( 'learn-press/subscription/activated', $order_subscription->get_id(), $event, $gateway_id );
106 +//
107 +// $response['status'] = 'success';
108 +// $response['order_id'] = $order_subscription->get_id();
109 +// break;
110 +// case 'initial_payment_succeeded':
111 +// if ( ! $order_subscription ) {
112 +// throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
113 +// }
114 +//
115 +// $this->update_subscription_status( $order_subscription->get_id(), 'active' );
116 +// $this->mark_parent_payment_completed( $order_subscription, $event );
117 +// $order_subscription->add_note( __( 'Initial subscription payment succeeded.', 'learnpress' ) );
118 +// do_action( 'learn-press/subscription/initial-payment-succeeded', $order_subscription->get_id(), $event, $gateway_id );
119 +//
120 +// $response['status'] = 'success';
121 +// $response['order_id'] = $order_subscription->get_id();
122 +// break;
123 +// case 'renewal_payment_succeeded':
124 +// if ( ! $order_subscription ) {
125 +// throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
126 +// }
127 +//
128 +// $this->update_subscription_status( $order_subscription->get_id(), 'active' );
129 +// /*
130 +// * PayPal may report the first successful charge as PAYMENT.SALE.COMPLETED.
131 +// * If the parent subscription order is still not completed, treat this as
132 +// * the initial payment instead of creating a renewal order.
133 +// */
134 +// if ( 'paypal' === $gateway_id && ! $order_subscription->is_completed() ) {
135 +// $this->mark_parent_payment_completed( $order_subscription, $event );
136 +// $order_subscription->add_note( __( 'Initial subscription payment succeeded.', 'learnpress' ) );
137 +// do_action( 'learn-press/subscription/initial-payment-succeeded', $order_subscription->get_id(), $event, $gateway_id );
138 +//
139 +// $response['status'] = 'success';
140 +// $response['order_id'] = $order_subscription->get_id();
141 +// break;
142 +// }
143 +//
144 +// $order_renew = $this->create_renewal_order( $order_subscription, $event, LP_ORDER_COMPLETED );
145 +// $order_subscription->add_note( __( 'Subscription renewal payment succeeded.', 'learnpress' ) );
146 +// do_action( 'learn-press/subscription/renewal-order-created', $order_renew->get_id(), $order_subscription->get_id(), $event, $gateway_id );
147 +// do_action( 'learn-press/subscription/renewed', $order_subscription->get_id(), $order_renew->get_id(), $event, $gateway_id );
148 +//
149 +// $response['status'] = 'success';
150 +// $response['order_id'] = $order_subscription->get_id();
151 +// $response['renewal_order_id'] = $order_renew->get_id();
152 +// break;
153 +// case 'renewal_payment_failed':
154 +// if ( ! $order_subscription ) {
155 +// throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
156 +// }
157 +//
158 +// $this->update_subscription_status( $order_subscription->get_id(), 'past_due' );
159 +// $order_renew = $this->create_renewal_order( $order_subscription, $event, LP_ORDER_FAILED );
160 +// $order_subscription->add_note( __( 'Subscription renewal payment failed.', 'learnpress' ) );
161 +// do_action( 'learn-press/subscription/renewal-order-created', $order_renew->get_id(), $order_subscription->get_id(), $event, $gateway_id );
162 +// do_action( 'learn-press/subscription/payment-failed', $order_subscription->get_id(), $order_renew->get_id(), $event, $gateway_id );
163 +//
164 +// $response['status'] = 'failed';
165 +// $response['order_id'] = $order_subscription->get_id();
166 +// $response['renewal_order_id'] = $order_renew->get_id();
167 +// break;
168 +// case 'subscription_cancelled':
169 +// if ( ! $order_subscription ) {
170 +// throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
171 +// }
172 +//
173 +// $this->update_subscription_status( $order_subscription->get_id(), 'cancelled' );
174 +// $order_subscription->add_note( __( 'Subscription cancelled.', 'learnpress' ) );
175 +// do_action( 'learn-press/subscription/cancelled', $order_subscription->get_id(), $event, $gateway_id );
176 +//
177 +// $response['status'] = 'cancelled';
178 +// $response['order_id'] = $order_subscription->get_id();
179 +// break;
180 +// case 'subscription_suspended':
181 +// if ( ! $order_subscription ) {
182 +// throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
183 +// }
184 +//
185 +// $this->update_subscription_status( $order_subscription->get_id(), 'suspended' );
186 +// $order_subscription->add_note( __( 'Subscription suspended.', 'learnpress' ) );
187 +// do_action( 'learn-press/subscription/suspended', $order_subscription->get_id(), $event, $gateway_id );
188 +//
189 +// $response['status'] = 'suspended';
190 +// $response['order_id'] = $order_subscription->get_id();
191 +// break;
192 +// case 'subscription_expired':
193 +// if ( ! $order_subscription ) {
194 +// throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
195 +// }
196 +//
197 +// $this->update_subscription_status( $order_subscription->get_id(), 'expired' );
198 +// $order_subscription->add_note( __( 'Subscription expired.', 'learnpress' ) );
199 +// do_action( 'learn-press/subscription/expired', $order_subscription->get_id(), $event, $gateway_id );
200 +//
201 +// $response['status'] = 'expired';
202 +// $response['order_id'] = $order_subscription->get_id();
203 +// break;
204 +// case 'subscription_updated':
205 +// if ( $order_subscription ) {
206 +// $order_subscription->add_note( __( 'Subscription updated.', 'learnpress' ) );
207 +// $response['order_id'] = $order_subscription->get_id();
208 +// }
209 +// $response['status'] = 'updated';
210 +// break;
211 +// default:
212 +// $response['status'] = 'ignored';
213 +// break;
214 +// }
215 +// } catch ( Throwable $e ) {
216 +// $response['status'] = 'error';
217 +// $response['status_code'] = 400;
218 +// $response['message'] = $e->getMessage();
219 +// error_log( 'LP_Subscription_Manager: ' . $e->getMessage() );
220 +// }
221 +//
222 +// return $response;
223 +// }
64 224
65 - if ( empty( $event_id ) ) {
66 - $event_id = md5( wp_json_encode( $event ) );
67 - }
68 -
69 - $response = array(
70 - 'status' => 'ignored',
71 - 'event_id' => $event_id,
72 - 'event_type' => $event_type,
73 - 'status_code' => 200,
74 - );
75 -
76 - try {
77 - $order_subscription_id = $this->resolve_parent_order_id( $event );
78 - $order_subscription = $order_subscription_id ? learn_press_get_order( $order_subscription_id ) : false;
79 - $this->validate_parent_subscription_binding( $order_subscription, $event );
80 -
81 - if ( $this->is_event_already_handled( $event_type, $event_id, $order_subscription, $event ) ) {
82 - return array(
83 - 'status' => 'duplicate',
84 - 'event_id' => $event_id,
85 - 'event_type' => $event_type,
86 - 'status_code' => 200,
87 - );
88 - }
89 -
90 - if ( $order_subscription ) {
91 - $this->sync_subscription_meta( $order_subscription->get_id(), $event );
92 - }
93 -
94 - switch ( $event_type ) {
95 - case 'subscription_activated':
96 - if ( ! $order_subscription ) {
97 - throw new Exception( __( 'Order not found.', 'learnpress' ) );
98 - }
99 -
100 - $this->update_subscription_status( $order_subscription->get_id(), 'active' );
101 - // Team convention: activated means the subscription order becomes completed.
102 - $this->mark_parent_payment_completed( $order_subscription, $event );
103 - $order_subscription->add_note( __( 'Subscription activated.', 'learnpress' ) );
104 - do_action( 'learn-press/subscription/activated', $order_subscription->get_id(), $event, $gateway_id );
105 -
106 - $response['status'] = 'success';
107 - $response['order_id'] = $order_subscription->get_id();
108 - break;
109 - case 'initial_payment_succeeded':
110 - if ( ! $order_subscription ) {
111 - throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
112 - }
113 -
114 - $this->update_subscription_status( $order_subscription->get_id(), 'active' );
115 - $this->mark_parent_payment_completed( $order_subscription, $event );
116 - $order_subscription->add_note( __( 'Initial subscription payment succeeded.', 'learnpress' ) );
117 - do_action( 'learn-press/subscription/initial-payment-succeeded', $order_subscription->get_id(), $event, $gateway_id );
118 -
119 - $response['status'] = 'success';
120 - $response['order_id'] = $order_subscription->get_id();
121 - break;
122 - case 'renewal_payment_succeeded':
123 - if ( ! $order_subscription ) {
124 - throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
125 - }
126 -
127 - $this->update_subscription_status( $order_subscription->get_id(), 'active' );
128 - /*
129 - * PayPal may report the first successful charge as PAYMENT.SALE.COMPLETED.
130 - * If the parent subscription order is still not completed, treat this as
131 - * the initial payment instead of creating a renewal order.
132 - */
133 - if ( 'paypal' === $gateway_id && ! $order_subscription->is_completed() ) {
134 - $this->mark_parent_payment_completed( $order_subscription, $event );
135 - $order_subscription->add_note( __( 'Initial subscription payment succeeded.', 'learnpress' ) );
136 - do_action( 'learn-press/subscription/initial-payment-succeeded', $order_subscription->get_id(), $event, $gateway_id );
137 -
138 - $response['status'] = 'success';
139 - $response['order_id'] = $order_subscription->get_id();
140 - break;
141 - }
142 -
143 - $order_renew = $this->create_renewal_order( $order_subscription, $event, LP_ORDER_COMPLETED );
144 - $order_subscription->add_note( __( 'Subscription renewal payment succeeded.', 'learnpress' ) );
145 - do_action( 'learn-press/subscription/renewal-order-created', $order_renew->get_id(), $order_subscription->get_id(), $event, $gateway_id );
146 - do_action( 'learn-press/subscription/renewed', $order_subscription->get_id(), $order_renew->get_id(), $event, $gateway_id );
147 -
148 - $response['status'] = 'success';
149 - $response['order_id'] = $order_subscription->get_id();
150 - $response['renewal_order_id'] = $order_renew->get_id();
151 - break;
152 - case 'renewal_payment_failed':
153 - if ( ! $order_subscription ) {
154 - throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
155 - }
156 -
157 - $this->update_subscription_status( $order_subscription->get_id(), 'past_due' );
158 - $order_renew = $this->create_renewal_order( $order_subscription, $event, LP_ORDER_FAILED );
159 - $order_subscription->add_note( __( 'Subscription renewal payment failed.', 'learnpress' ) );
160 - do_action( 'learn-press/subscription/renewal-order-created', $order_renew->get_id(), $order_subscription->get_id(), $event, $gateway_id );
161 - do_action( 'learn-press/subscription/payment-failed', $order_subscription->get_id(), $order_renew->get_id(), $event, $gateway_id );
162 -
163 - $response['status'] = 'failed';
164 - $response['order_id'] = $order_subscription->get_id();
165 - $response['renewal_order_id'] = $order_renew->get_id();
166 - break;
167 - case 'subscription_cancelled':
168 - if ( ! $order_subscription ) {
169 - throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
170 - }
171 -
172 - $this->update_subscription_status( $order_subscription->get_id(), 'cancelled' );
173 - $order_subscription->add_note( __( 'Subscription cancelled.', 'learnpress' ) );
174 - do_action( 'learn-press/subscription/cancelled', $order_subscription->get_id(), $event, $gateway_id );
175 -
176 - $response['status'] = 'cancelled';
177 - $response['order_id'] = $order_subscription->get_id();
178 - break;
179 - case 'subscription_suspended':
180 - if ( ! $order_subscription ) {
181 - throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
182 - }
183 -
184 - $this->update_subscription_status( $order_subscription->get_id(), 'suspended' );
185 - $order_subscription->add_note( __( 'Subscription suspended.', 'learnpress' ) );
186 - do_action( 'learn-press/subscription/suspended', $order_subscription->get_id(), $event, $gateway_id );
187 -
188 - $response['status'] = 'suspended';
189 - $response['order_id'] = $order_subscription->get_id();
190 - break;
191 - case 'subscription_expired':
192 - if ( ! $order_subscription ) {
193 - throw new Exception( __( 'Parent subscription order not found.', 'learnpress' ) );
194 - }
195 -
196 - $this->update_subscription_status( $order_subscription->get_id(), 'expired' );
197 - $order_subscription->add_note( __( 'Subscription expired.', 'learnpress' ) );
198 - do_action( 'learn-press/subscription/expired', $order_subscription->get_id(), $event, $gateway_id );
199 -
200 - $response['status'] = 'expired';
201 - $response['order_id'] = $order_subscription->get_id();
202 - break;
203 - case 'subscription_updated':
204 - if ( $order_subscription ) {
205 - $order_subscription->add_note( __( 'Subscription updated.', 'learnpress' ) );
206 - $response['order_id'] = $order_subscription->get_id();
207 - }
208 - $response['status'] = 'updated';
209 - break;
210 - default:
211 - $response['status'] = 'ignored';
212 - break;
213 - }
214 - } catch ( Throwable $e ) {
215 - $response['status'] = 'error';
216 - $response['status_code'] = 400;
217 - $response['message'] = $e->getMessage();
218 - error_log( 'LP_Subscription_Manager: ' . $e->getMessage() );
219 - }
220 -
221 - return $response;
222 - }
223 -
224 225 /**
225 226 * Check whether the webhook event outcome is already reflected in order state.
226 227 *
227 228 * Replaces the old LP_Subscription_Event_Store transient-based approach with
@@ -234,10 +235,11 @@
234 235 * @param LP_Order|false $order_subscription Resolved subscription order (false when not found).
235 236 * @param array $event Full normalized event payload.
236 237 *
237 238 * @return bool True if the event outcome is already reflected in the database.
239 + * @deprecated 4.3.8
238 240 */
239 - private function is_event_already_handled( string $event_type, string $event_id, $order_subscription, array $event ): bool {
241 + /*private function is_event_already_handled( string $event_type, string $event_id, $order_subscription, array $event ): bool {
240 242
241 243 if ( ! $order_subscription instanceof LP_Order ) {
242 244 return false;
243 245 }
@@ -308,9 +310,9 @@
308 310 return ! empty( $event_id ) && $last_event === $event_id;
309 311 default:
310 312 return false;
311 313 }
312 - }
314 + }*/
313 315
314 316 /**
315 317 * Resolve parent order id for an incoming event.
316 318 *
@@ -321,10 +323,11 @@
321 323 *
322 324 * @param array $event Normalized event payload.
323 325 *
324 326 * @return int Parent order id or 0 when not found.
327 + * @deprecated 4.3.8
325 328 */
326 - public function resolve_parent_order_id( array $event ): int {
329 + /*public function resolve_parent_order_id( array $event ): int {
327 330
328 331 $order_subscription_id = absint( $event['parent_order_id'] ?? 0 );
329 332 if ( $order_subscription_id ) {
330 333 return $order_subscription_id;
@@ -358,9 +361,9 @@
358 361 return 0;
359 362 }
360 363
361 364 return absint( $order_ids[0] );
362 - }
365 + }*/
363 366
364 367 /**
365 368 * Persist shared subscription meta onto a parent order.
366 369 *
@@ -370,10 +373,11 @@
370 373 * @param int $order_id
371 374 * @param array $event Normalized event payload.
372 375 *
373 376 * @return void
377 + * @deprecated 4.3.8
374 378 */
375 - public function sync_subscription_meta( int $order_id, array $event ) {
379 + /*public function sync_subscription_meta( int $order_id, array $event ) {
376 380
377 381 if ( ! empty( $event['subscription_id'] ) ) {
378 382 update_post_meta( $order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_ID, sanitize_text_field( (string) $event['subscription_id'] ) );
379 383 }
@@ -389,9 +393,9 @@
389 393 }
390 394 if ( ! empty( $event['metadata'] ) && is_array( $event['metadata'] ) ) {
391 395 update_post_meta( $order_id, '_lp_subscription_metadata', $event['metadata'] );
392 396 }
393 - }
397 + }*/
394 398
395 399 /**
396 400 * Update current subscription status stored on parent order.
397 401 *
@@ -397,13 +401,14 @@
397 401 *
398 402 * @param int $order_id
399 403 * @param string $status Normalized status slug (active/past_due/cancelled/...).
400 404 * @return void
405 + * @deprecated 4.3.8
401 406 */
402 - public function update_subscription_status( int $order_id, string $status ) {
407 + /*public function update_subscription_status( int $order_id, string $status ) {
403 408
404 409 update_post_meta( $order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_STATUS, sanitize_key( $status ) );
405 - }
410 + }*/
406 411 /**
407 412 * Mark parent order paid when initial subscription activation succeeds.
408 413 *
409 414 * @param LP_Order $order_subscription
@@ -409,10 +414,11 @@
409 414 * @param LP_Order $order_subscription
410 415 * @param array $event Normalized event payload.
411 416 *
412 417 * @return void
418 + * @deprecated 4.3.8
413 419 */
414 - protected function mark_parent_payment_completed( LP_Order $order_subscription, array $event ) {
420 + /*protected function mark_parent_payment_completed( LP_Order $order_subscription, array $event ) {
415 421 $transaction_id = sanitize_text_field( (string) ( $event['transaction_id'] ?? '' ) );
416 422 if ( ! $order_subscription->is_completed() ) {
417 423 $order_subscription->payment_complete( $transaction_id );
418 424 return;
@@ -427,9 +433,9 @@
427 433 if ( '' === $saved_transaction_id ) {
428 434 update_post_meta( $order_subscription->get_id(), '_transaction_id', $transaction_id );
429 435 }
430 436 }
431 - }
437 + }*/
432 438 /**
433 439 * Create or reuse a renewal child order for a renewal event.
434 440 *
435 441 * Idempotency strategy:
@@ -441,80 +447,81 @@
441 447 * @param string $target_status Target order status for renewal result.
442 448 *
443 449 * @return LP_Order Existing or newly-created renewal order.
444 450 * @throws Exception
451 + * @deprecated 4.3.8
445 452 */
446 - public function create_renewal_order( LP_Order $order_subscription, array $event, string $target_status = LP_ORDER_PENDING ): LP_Order {
453 +// public function create_renewal_order( LP_Order $order_subscription, array $event, string $target_status = LP_ORDER_PENDING ): LP_Order {
454 +//
455 +// $renewal_key = $this->get_renewal_key( $event );
456 +// if ( ! empty( $renewal_key ) ) {
457 +// $existing = $this->find_renewal_order_by_key( $order_subscription->get_id(), $renewal_key );
458 +// if ( $existing ) {
459 +// return $existing;
460 +// }
461 +// }
462 +//
463 +// $event_id = sanitize_text_field( (string) ( $event['event_id'] ?? '' ) );
464 +// if ( ! empty( $event_id ) ) {
465 +// $existing = $this->find_renewal_order_by_event( $order_subscription->get_id(), $event_id );
466 +// if ( $existing ) {
467 +// return $existing;
468 +// }
469 +// }
470 +//
471 +// $renewal_total = isset( $event['amount'] ) && (float) $event['amount'] > 0 ? (float) $event['amount'] : (float) $order_subscription->get_total();
472 +// $renewal_subtotal = isset( $event['amount'] ) && (float) $event['amount'] > 0 ? (float) $event['amount'] : (float) $order_subscription->get_subtotal();
473 +// $renewal_currency = ! empty( $event['currency'] ) ? sanitize_text_field( (string) $event['currency'] ) : $order_subscription->get_currency();
474 +//
475 +// $order_renew = new LP_Order();
476 +// $order_renew->set_parent_id( $order_subscription->get_id() );
477 +// $order_renew->set_user_id( $order_subscription->get_user_id() );
478 +// $order_renew->set_checkout_email( $order_subscription->get_checkout_email() );
479 +// $order_renew->set_status( LP_ORDER_PENDING );
480 +// $order_renew->set_created_via( 'subscription' );
481 +// $order_renew->set_currency( $renewal_currency );
482 +// $order_renew->set_total( $renewal_total );
483 +// $order_renew->set_subtotal( $renewal_subtotal );
484 +// $order_renew->set_data( 'payment_method', $order_subscription->get_data( 'payment_method', '' ) );
485 +// $order_renew->set_data( 'payment_method_title', $order_subscription->get_payment_method_title() );
486 +//
487 +// $renewal_order_id = $order_renew->save();
488 +// if ( empty( $renewal_order_id ) ) {
489 +// throw new Exception( __( 'Cannot create renewal order.', 'learnpress' ) );
490 +// }
491 +//
492 +// $this->copy_parent_order_items_to_renewal( $order_subscription, $order_renew );
493 +// if ( ! empty( $event_id ) ) {
494 +// update_post_meta( $renewal_order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_EVENT_ID, $event_id );
495 +// }
496 +// if ( ! empty( $event['subscription_id'] ) ) {
497 +// update_post_meta( $renewal_order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_ID, sanitize_text_field( (string) $event['subscription_id'] ) );
498 +// }
499 +//
500 +// if ( LP_ORDER_COMPLETED !== $target_status && ! empty( $event['transaction_id'] ) ) {
501 +// update_post_meta( $renewal_order_id, '_transaction_id', sanitize_text_field( (string) $event['transaction_id'] ) );
502 +// }
503 +// if ( ! empty( $renewal_key ) ) {
504 +// update_post_meta( $renewal_order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_RENEWAL_KEY, $renewal_key );
505 +// }
506 +//
507 +// if ( LP_ORDER_COMPLETED === $target_status ) {
508 +// $order_renew->payment_complete( (string) ( $event['transaction_id'] ?? '' ) );
509 +// } else {
510 +// $order_renew->update_status( $target_status );
511 +// }
512 +//
513 +// $order_renew->add_note(
514 +// sprintf(
515 +// /* translators: %s: parent order number */
516 +// __( 'Subscription renewal generated from parent order %s.', 'learnpress' ),
517 +// $order_subscription->get_order_number()
518 +// )
519 +// );
520 +//
521 +// return $order_renew;
522 +// }
447 523
448 - $renewal_key = $this->get_renewal_key( $event );
449 - if ( ! empty( $renewal_key ) ) {
450 - $existing = $this->find_renewal_order_by_key( $order_subscription->get_id(), $renewal_key );
451 - if ( $existing ) {
452 - return $existing;
453 - }
454 - }
455 -
456 - $event_id = sanitize_text_field( (string) ( $event['event_id'] ?? '' ) );
457 - if ( ! empty( $event_id ) ) {
458 - $existing = $this->find_renewal_order_by_event( $order_subscription->get_id(), $event_id );
459 - if ( $existing ) {
460 - return $existing;
461 - }
462 - }
463 -
464 - $renewal_total = isset( $event['amount'] ) && (float) $event['amount'] > 0 ? (float) $event['amount'] : (float) $order_subscription->get_total();
465 - $renewal_subtotal = isset( $event['amount'] ) && (float) $event['amount'] > 0 ? (float) $event['amount'] : (float) $order_subscription->get_subtotal();
466 - $renewal_currency = ! empty( $event['currency'] ) ? sanitize_text_field( (string) $event['currency'] ) : $order_subscription->get_currency();
467 -
468 - $order_renew = new LP_Order();
469 - $order_renew->set_parent_id( $order_subscription->get_id() );
470 - $order_renew->set_user_id( $order_subscription->get_user_id() );
471 - $order_renew->set_checkout_email( $order_subscription->get_checkout_email() );
472 - $order_renew->set_status( LP_ORDER_PENDING );
473 - $order_renew->set_created_via( 'subscription' );
474 - $order_renew->set_currency( $renewal_currency );
475 - $order_renew->set_total( $renewal_total );
476 - $order_renew->set_subtotal( $renewal_subtotal );
477 - $order_renew->set_data( 'payment_method', $order_subscription->get_data( 'payment_method', '' ) );
478 - $order_renew->set_data( 'payment_method_title', $order_subscription->get_payment_method_title() );
479 -
480 - $renewal_order_id = $order_renew->save();
481 - if ( empty( $renewal_order_id ) ) {
482 - throw new Exception( __( 'Cannot create renewal order.', 'learnpress' ) );
483 - }
484 -
485 - $this->copy_parent_order_items_to_renewal( $order_subscription, $order_renew );
486 - if ( ! empty( $event_id ) ) {
487 - update_post_meta( $renewal_order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_EVENT_ID, $event_id );
488 - }
489 - if ( ! empty( $event['subscription_id'] ) ) {
490 - update_post_meta( $renewal_order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_ID, sanitize_text_field( (string) $event['subscription_id'] ) );
491 - }
492 -
493 - if ( LP_ORDER_COMPLETED !== $target_status && ! empty( $event['transaction_id'] ) ) {
494 - update_post_meta( $renewal_order_id, '_transaction_id', sanitize_text_field( (string) $event['transaction_id'] ) );
495 - }
496 - if ( ! empty( $renewal_key ) ) {
497 - update_post_meta( $renewal_order_id, LP_Gateway_Abstract::META_SUBSCRIPTION_RENEWAL_KEY, $renewal_key );
498 - }
499 -
500 - if ( LP_ORDER_COMPLETED === $target_status ) {
501 - $order_renew->payment_complete( (string) ( $event['transaction_id'] ?? '' ) );
502 - } else {
503 - $order_renew->update_status( $target_status );
504 - }
505 -
506 - $order_renew->add_note(
507 - sprintf(
508 - /* translators: %s: parent order number */
509 - __( 'Subscription renewal generated from parent order %s.', 'learnpress' ),
510 - $order_subscription->get_order_number()
511 - )
512 - );
513 -
514 - return $order_renew;
515 - }
516 -
517 524 /**
518 525 * Ensure webhook subscription id matches the resolved parent order binding.
519 526 *
520 527 * This prevents applying a callback payload to a parent order when provider
@@ -524,10 +531,11 @@
524 531 * @param array $event Normalized event payload.
525 532 *
526 533 * @return void
527 534 * @throws Exception
535 + * @deprecated 4.3.8
528 536 */
529 - protected function validate_parent_subscription_binding( $order_subscription, array $event ) {
537 + /*protected function validate_parent_subscription_binding( $order_subscription, array $event ) {
530 538
531 539 if ( ! $order_subscription instanceof LP_Order ) {
532 540 return;
533 541 }
@@ -542,9 +550,9 @@
542 550 );
543 551 if ( ! empty( $saved_subscription_id ) && $saved_subscription_id !== $event_subscription_id ) {
544 552 throw new Exception( __( 'Subscription id does not match parent order.', 'learnpress' ) );
545 553 }
546 - }
554 + }*/
547 555 /**
548 556 * Find renewal child order by parent id + provider event id.
549 557 *
550 558 * @param int $parent_order_id
@@ -550,10 +558,11 @@
550 558 * @param int $parent_order_id
551 559 * @param string $event_id
552 560 *
553 561 * @return LP_Order|false
562 + * @deprecated 4.3.8
554 563 */
555 - protected function find_renewal_order_by_event( int $parent_order_id, string $event_id ) {
564 + /*protected function find_renewal_order_by_event( int $parent_order_id, string $event_id ) {
556 565 $order_ids = get_posts(
557 566 array(
558 567 'post_type' => LP_ORDER_CPT,
559 568 'post_status' => 'any',
@@ -573,9 +582,9 @@
573 582 return false;
574 583 }
575 584
576 585 return learn_press_get_order( absint( $order_ids[0] ) );
577 - }
586 + }*/
578 587
579 588 /**
580 589 * Find renewal child order by parent id + renewal key.
581 590 *
@@ -582,10 +591,11 @@
582 591 * @param int $parent_order_id
583 592 * @param string $renewal_key
584 593 *
585 594 * @return LP_Order|false
595 + * @deprecated 4.3.8
586 596 */
587 - protected function find_renewal_order_by_key( int $parent_order_id, string $renewal_key ) {
597 + /*protected function find_renewal_order_by_key( int $parent_order_id, string $renewal_key ) {
588 598 $order_ids = get_posts(
589 599 array(
590 600 'post_type' => LP_ORDER_CPT,
591 601 'post_status' => 'any',
@@ -605,9 +615,9 @@
605 615 return false;
606 616 }
607 617
608 618 return learn_press_get_order( absint( $order_ids[0] ) );
609 - }
619 + }*/
610 620
611 621 /**
612 622 * Build stable renewal dedupe key from event payload.
613 623 *
@@ -617,10 +627,11 @@
617 627 *
618 628 * @param array $event Normalized event payload.
619 629 *
620 630 * @return string Non-empty dedupe key when enough data exists.
631 + * @deprecated 4.3.8
621 632 */
622 - protected function get_renewal_key( array $event ): string {
633 + /*protected function get_renewal_key( array $event ): string {
623 634 $renewal_key = sanitize_text_field( (string) ( $event['renewal_key'] ?? '' ) );
624 635 if ( ! empty( $renewal_key ) ) {
625 636 return $renewal_key;
626 637 }
@@ -631,9 +642,9 @@
631 642 return $subscription_id . '|' . $transaction_id;
632 643 }
633 644
634 645 return '';
635 - }
646 + }*/
636 647
637 648 /**
638 649 * Clone parent order items/meta into a renewal child order.
639 650 *
@@ -643,10 +654,11 @@
643 654 * @param LP_Order $order_subscription
644 655 * @param LP_Order $order_renew
645 656 *
646 657 * @return void
658 + * @deprecated 4.3.8
647 659 */
648 - protected function copy_parent_order_items_to_renewal( LP_Order $order_subscription, LP_Order $order_renew ) {
660 + /*protected function copy_parent_order_items_to_renewal( LP_Order $order_subscription, LP_Order $order_renew ) {
649 661 $parent_items = $order_subscription->get_items();
650 662 if ( empty( $parent_items ) || ! is_array( $parent_items ) ) {
651 663 return;
652 664 }
@@ -695,7 +707,7 @@
695 707 if ( ! $new_item_id ) {
696 708 continue;
697 709 }
698 710 }
699 - }
711 + }*/
700 712 }
701 713 }