← All changes
|
square/controllers/FrmSquareLiteEventsController.php
+15
-18
6.27
→
6.22.1
View file →
| @@ -9,11 +9,8 @@ | ||
| 9 | 9 | * @var string |
| 10 | 10 | */ |
| 11 | 11 | public static $events_to_skip_option_name = 'frm_square_events_to_skip'; |
| 12 | 12 | |
| 13 | - /** | |
| 14 | - * @var object|null | |
| 15 | - */ | |
| 16 | 13 | private $event; |
| 17 | 14 | |
| 18 | 15 | /** |
| 19 | 16 | * Tell Square Connect API that the request came through by flushing early before processing. |
| @@ -54,9 +51,8 @@ | ||
| 54 | 51 | |
| 55 | 52 | if ( $unprocessed_event_ids ) { |
| 56 | 53 | $this->process_event_ids( $unprocessed_event_ids ); |
| 57 | 54 | } |
| 58 | - | |
| 59 | 55 | wp_send_json_success(); |
| 60 | 56 | } |
| 61 | 57 | |
| 62 | 58 | /** |
| @@ -62,9 +58,8 @@ | ||
| 62 | 58 | /** |
| 63 | 59 | * @since 6.22 |
| 64 | 60 | * |
| 65 | 61 | * @param array<string> $event_ids |
| 66 | - * | |
| 67 | 62 | * @return void |
| 68 | 63 | */ |
| 69 | 64 | private function process_event_ids( $event_ids ) { |
| 70 | 65 | foreach ( $event_ids as $event_id ) { |
| @@ -89,9 +84,8 @@ | ||
| 89 | 84 | /** |
| 90 | 85 | * @since 6.22 |
| 91 | 86 | * |
| 92 | 87 | * @param string $event_id |
| 93 | - * | |
| 94 | 88 | * @return bool True if the event should be skipped. |
| 95 | 89 | */ |
| 96 | 90 | private function should_skip_event( $event_id ) { |
| 97 | 91 | if ( $this->last_attempt_to_process_event_is_too_recent( $event_id ) ) { |
| @@ -98,15 +92,17 @@ | ||
| 98 | 92 | return true; |
| 99 | 93 | } |
| 100 | 94 | |
| 101 | 95 | $option = get_option( self::$events_to_skip_option_name ); |
| 96 | + if ( ! is_array( $option ) ) { | |
| 97 | + return false; | |
| 98 | + } | |
| 102 | 99 | |
| 103 | - return is_array( $option ) && in_array( $event_id, $option, true ); | |
| 100 | + return in_array( $event_id, $option, true ); | |
| 104 | 101 | } |
| 105 | 102 | |
| 106 | 103 | /** |
| 107 | 104 | * @param string $event_id |
| 108 | - * | |
| 109 | 105 | * @return bool |
| 110 | 106 | */ |
| 111 | 107 | private function last_attempt_to_process_event_is_too_recent( $event_id ) { |
| 112 | 108 | $last_process_attempt = get_transient( 'frm_square_last_process_' . $event_id ); |
| @@ -116,17 +112,20 @@ | ||
| 116 | 112 | /** |
| 117 | 113 | * @since 6.22 |
| 118 | 114 | * |
| 119 | 115 | * @param string $event_id |
| 120 | - * | |
| 121 | 116 | * @return void |
| 122 | 117 | */ |
| 123 | 118 | private function count_failed_event( $event_id ) { |
| 124 | - $transient_name = 'frm_square_failed_event_' . $event_id; | |
| 125 | - $transient = get_transient( $transient_name ); | |
| 126 | - $failed_count = is_int( $transient ) ? $transient + 1 : 1; | |
| 119 | + $transient_name = 'frm_square_failed_event_' . $event_id; | |
| 120 | + $transient = get_transient( $transient_name ); | |
| 121 | + if ( is_int( $transient ) ) { | |
| 122 | + $failed_count = $transient + 1; | |
| 123 | + } else { | |
| 124 | + $failed_count = 1; | |
| 125 | + } | |
| 126 | + | |
| 127 | 127 | $maximum_retries = 3; |
| 128 | - | |
| 129 | 128 | if ( $failed_count >= $maximum_retries ) { |
| 130 | 129 | $this->track_handled_event( $event_id ); |
| 131 | 130 | } else { |
| 132 | 131 | set_transient( $transient_name, $failed_count, 4 * DAY_IN_SECONDS ); |
| @@ -139,9 +138,8 @@ | ||
| 139 | 138 | * |
| 140 | 139 | * @since 6.22 |
| 141 | 140 | * |
| 142 | 141 | * @param string $event_id |
| 143 | - * | |
| 144 | 142 | * @return void |
| 145 | 143 | */ |
| 146 | 144 | private function track_handled_event( $event_id ) { |
| 147 | 145 | $option = get_option( self::$events_to_skip_option_name ); |
| @@ -193,9 +191,8 @@ | ||
| 193 | 191 | 'payment' => $payment, |
| 194 | 192 | ) |
| 195 | 193 | ); |
| 196 | 194 | } |
| 197 | - | |
| 198 | 195 | return; |
| 199 | 196 | } |
| 200 | 197 | break; |
| 201 | 198 | case 'subscription.updated': |
| @@ -223,13 +220,13 @@ | ||
| 223 | 220 | /** |
| 224 | 221 | * Add a payment row for the payments table. |
| 225 | 222 | * |
| 226 | 223 | * @param string $subscription_id The Square ID for the current subscription. |
| 227 | - * | |
| 228 | 224 | * @return void |
| 229 | 225 | */ |
| 230 | 226 | private function add_subscription_payment( $subscription_id ) { |
| 231 | - $payment_id = $this->event->data->id; | |
| 227 | + $payment_id = $this->event->data->id; | |
| 228 | + | |
| 232 | 229 | $frm_payment = new FrmTransLitePayment(); |
| 233 | 230 | $payment = $frm_payment->get_one_by( $payment_id, 'receipt_id' ); |
| 234 | 231 | |
| 235 | 232 | if ( $payment ) { |
| @@ -238,9 +235,8 @@ | ||
| 238 | 235 | } |
| 239 | 236 | |
| 240 | 237 | $frm_sub = new FrmTransLiteSubscription(); |
| 241 | 238 | $sub = $frm_sub->get_one_by( $subscription_id, 'sub_id' ); |
| 242 | - | |
| 243 | 239 | if ( ! $sub ) { |
| 244 | 240 | return; |
| 245 | 241 | } |
| 246 | 242 | |
| @@ -270,8 +266,9 @@ | ||
| 270 | 266 | array( 'next_bill_date' => gmdate( 'Y-m-d', strtotime( $expire_date ) ) ) |
| 271 | 267 | ); |
| 272 | 268 | } |
| 273 | 269 | } |
| 270 | + | |
| 274 | 271 | |
| 275 | 272 | $frm_payment = new FrmTransLitePayment(); |
| 276 | 273 | $frm_payment->create( |
| 277 | 274 | array( |