← All changes
|
square/controllers/FrmSquareLiteEventsController.php
+13
-21
6.26
→
trunk
View file →
| @@ -54,8 +54,9 @@ | ||
| 54 | 54 | |
| 55 | 55 | if ( $unprocessed_event_ids ) { |
| 56 | 56 | $this->process_event_ids( $unprocessed_event_ids ); |
| 57 | 57 | } |
| 58 | + | |
| 58 | 59 | wp_send_json_success(); |
| 59 | 60 | } |
| 60 | 61 | |
| 61 | 62 | /** |
| @@ -74,15 +75,16 @@ | ||
| 74 | 75 | set_transient( 'frm_square_last_process_' . $event_id, time(), 60 ); |
| 75 | 76 | |
| 76 | 77 | $this->event = FrmSquareLiteConnectHelper::get_event( $event_id ); |
| 77 | 78 | |
| 78 | - if ( is_object( $this->event ) ) { | |
| 79 | - $this->handle_event(); | |
| 80 | - $this->track_handled_event( $event_id ); | |
| 81 | - FrmSquareLiteConnectHelper::process_event( $event_id ); | |
| 82 | - } else { | |
| 79 | + if ( ! is_object( $this->event ) ) { | |
| 83 | 80 | $this->count_failed_event( $event_id ); |
| 81 | + continue; | |
| 84 | 82 | } |
| 83 | + | |
| 84 | + $this->handle_event(); | |
| 85 | + $this->track_handled_event( $event_id ); | |
| 86 | + FrmSquareLiteConnectHelper::process_event( $event_id ); | |
| 85 | 87 | } |
| 86 | 88 | } |
| 87 | 89 | |
| 88 | 90 | /** |
| @@ -98,13 +100,9 @@ | ||
| 98 | 100 | } |
| 99 | 101 | |
| 100 | 102 | $option = get_option( self::$events_to_skip_option_name ); |
| 101 | 103 | |
| 102 | - if ( ! is_array( $option ) ) { | |
| 103 | - return false; | |
| 104 | - } | |
| 105 | - | |
| 106 | - return in_array( $event_id, $option, true ); | |
| 104 | + return is_array( $option ) && in_array( $event_id, $option, true ); | |
| 107 | 105 | } |
| 108 | 106 | |
| 109 | 107 | /** |
| 110 | 108 | * @param string $event_id |
| @@ -123,17 +121,11 @@ | ||
| 123 | 121 | * |
| 124 | 122 | * @return void |
| 125 | 123 | */ |
| 126 | 124 | private function count_failed_event( $event_id ) { |
| 127 | - $transient_name = 'frm_square_failed_event_' . $event_id; | |
| 128 | - $transient = get_transient( $transient_name ); | |
| 129 | - | |
| 130 | - if ( is_int( $transient ) ) { | |
| 131 | - $failed_count = $transient + 1; | |
| 132 | - } else { | |
| 133 | - $failed_count = 1; | |
| 134 | - } | |
| 135 | - | |
| 125 | + $transient_name = 'frm_square_failed_event_' . $event_id; | |
| 126 | + $transient = get_transient( $transient_name ); | |
| 127 | + $failed_count = is_int( $transient ) ? $transient + 1 : 1; | |
| 136 | 128 | $maximum_retries = 3; |
| 137 | 129 | |
| 138 | 130 | if ( $failed_count >= $maximum_retries ) { |
| 139 | 131 | $this->track_handled_event( $event_id ); |
| @@ -202,8 +194,9 @@ | ||
| 202 | 194 | 'payment' => $payment, |
| 203 | 195 | ) |
| 204 | 196 | ); |
| 205 | 197 | } |
| 198 | + | |
| 206 | 199 | return; |
| 207 | 200 | } |
| 208 | 201 | break; |
| 209 | 202 | case 'subscription.updated': |
| @@ -235,10 +228,9 @@ | ||
| 235 | 228 | * |
| 236 | 229 | * @return void |
| 237 | 230 | */ |
| 238 | 231 | private function add_subscription_payment( $subscription_id ) { |
| 239 | - $payment_id = $this->event->data->id; | |
| 240 | - | |
| 232 | + $payment_id = $this->event->data->id; | |
| 241 | 233 | $frm_payment = new FrmTransLitePayment(); |
| 242 | 234 | $payment = $frm_payment->get_one_by( $payment_id, 'receipt_id' ); |
| 243 | 235 | |
| 244 | 236 | if ( $payment ) { |