flp-callback.php
159 lines
| 1 | <?php |
| 2 | $flp_approve_status = get_setting( 'approve_status' ); |
| 3 | $flp_reject_status = get_setting( 'reject_status' ); |
| 4 | |
| 5 | /** |
| 6 | * Get plugin settings. |
| 7 | */ |
| 8 | function get_setting( $key ) { |
| 9 | return get_option( 'wc_settings_woocommerce-fraudlabs-pro_' . $key ); |
| 10 | } |
| 11 | |
| 12 | function verify_custom_nonce($nonce, $action, $id) { |
| 13 | if ($nonce == '') { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | if (strpos($nonce, '|') === false) { |
| 18 | return false; |
| 19 | } |
| 20 | |
| 21 | list($nonceValue, $expiryTimestamp) = explode('|', $nonce); |
| 22 | if (time() < $expiryTimestamp) { |
| 23 | if (!wp_verify_nonce($nonceValue, $action)) { |
| 24 | return false; |
| 25 | } |
| 26 | } else { |
| 27 | if ($id == '') { |
| 28 | return false; |
| 29 | } else { |
| 30 | $nonceChecks = get_post_meta( $id, '_fraudlabspro' ); |
| 31 | if ($nonceChecks) { |
| 32 | if (!is_array($nonceChecks[0]) && !is_object($nonceChecks[0])) { |
| 33 | $nonceCheck = json_decode($nonceChecks[0]); |
| 34 | } else { |
| 35 | $nonceCheck = $nonceChecks[0]; |
| 36 | } |
| 37 | |
| 38 | if ($nonceCheck) { |
| 39 | if (is_array($nonceChecks[0])) { |
| 40 | $callbackNonce = $nonceCheck['flp_callback_nonce'] ?? ''; |
| 41 | } else { |
| 42 | $callbackNonce = $nonceCheck->flp_callback_nonce ?? ''; |
| 43 | } |
| 44 | if ($callbackNonce != $nonce) { |
| 45 | return false; |
| 46 | } |
| 47 | } else { |
| 48 | return false; |
| 49 | } |
| 50 | } else { |
| 51 | return false; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | $id = (isset($_GET['orderid'])) ? sanitize_text_field($_GET['orderid']) : ''; |
| 60 | $action = (isset($_GET['action'])) ? sanitize_text_field($_GET['action']) : ''; |
| 61 | $nonce = (isset($_GET['nonce'])) ? sanitize_text_field($_GET['nonce']) : ''; |
| 62 | |
| 63 | if (!verify_custom_nonce($nonce, 'check-flp-callback', $id)) { |
| 64 | die; |
| 65 | } |
| 66 | |
| 67 | if ( $id != '' ) { |
| 68 | $order = wc_get_order( $id ); |
| 69 | |
| 70 | if (empty($order)) { |
| 71 | die; |
| 72 | } |
| 73 | |
| 74 | // Update for Approve case |
| 75 | if ( $action == 'APPROVE' ) { |
| 76 | if( $flp_approve_status ) { |
| 77 | // Add note and change status |
| 78 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Approved.', 'woocommerce-fraudlabs-pro' ) ); |
| 79 | $order->update_status( $flp_approve_status ); |
| 80 | }else{ |
| 81 | // Add the note only |
| 82 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Approved.', 'woocommerce-fraudlabs-pro' ) ); |
| 83 | } |
| 84 | |
| 85 | $result = get_post_meta( $id, '_fraudlabspro' ); |
| 86 | if ( !is_array( $result[0] ) && !is_object( $result[0] ) ) { |
| 87 | $row = json_decode( $result[0] ); |
| 88 | } else { |
| 89 | $row = $result[0]; |
| 90 | } |
| 91 | |
| 92 | if ( is_array( $result[0] ) ) { |
| 93 | $row['fraudlabspro_status'] = 'APPROVE'; |
| 94 | } else { |
| 95 | if (isset($row->fraudlabspro_status)) { |
| 96 | $row->fraudlabspro_status = 'APPROVE'; |
| 97 | } |
| 98 | } |
| 99 | update_post_meta( $id, '_fraudlabspro', $row ); |
| 100 | } |
| 101 | // Update for Reject case |
| 102 | elseif( $action == 'REJECT' ) { |
| 103 | if( $flp_reject_status ) { |
| 104 | // Add note and change status |
| 105 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Rejected.', 'woocommerce-fraudlabs-pro' ) ); |
| 106 | $order->update_status( $flp_reject_status ); |
| 107 | }else{ |
| 108 | // Add the note only |
| 109 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Rejected.', 'woocommerce-fraudlabs-pro' ) ); |
| 110 | } |
| 111 | |
| 112 | $result = get_post_meta( $id, '_fraudlabspro' ); |
| 113 | if ( !is_array( $result[0] ) && !is_object( $result[0] ) ) { |
| 114 | $row = json_decode( $result[0] ); |
| 115 | } else { |
| 116 | $row = $result[0]; |
| 117 | } |
| 118 | |
| 119 | if ( is_array( $result[0] ) ) { |
| 120 | $row['fraudlabspro_status'] = 'REJECT'; |
| 121 | } else { |
| 122 | if (isset($row->fraudlabspro_status)) { |
| 123 | $row->fraudlabspro_status = 'REJECT'; |
| 124 | } |
| 125 | } |
| 126 | update_post_meta( $id, '_fraudlabspro', $row ); |
| 127 | } |
| 128 | // Update for Blacklist case |
| 129 | elseif ( $action == 'REJECT_BLACKLIST' ) { |
| 130 | if( $flp_reject_status ) { |
| 131 | // Add note and change status |
| 132 | $order->add_order_note( __( 'Blacklisted order to FraudLabs Pro.', 'woocommerce-fraudlabs-pro' ) ); |
| 133 | $order->update_status( $flp_reject_status ); |
| 134 | }else{ |
| 135 | // Add the note only |
| 136 | $order->add_order_note( __( 'Blacklisted order to FraudLabs Pro.', 'woocommerce-fraudlabs-pro' ) ); |
| 137 | } |
| 138 | |
| 139 | $result = get_post_meta( $id, '_fraudlabspro' ); |
| 140 | if ( !is_array( $result[0] ) && !is_object( $result[0] ) ) { |
| 141 | $row = json_decode( $result[0] ); |
| 142 | } else { |
| 143 | $row = $result[0]; |
| 144 | } |
| 145 | |
| 146 | if ( is_array( $result[0] ) ) { |
| 147 | $row['fraudlabspro_status'] = 'REJECT'; |
| 148 | $row['is_blacklisted'] = '1'; |
| 149 | } else { |
| 150 | if (isset($row->fraudlabspro_status)) { |
| 151 | $row->fraudlabspro_status = 'REJECT'; |
| 152 | $row->is_blacklisted = '1'; |
| 153 | } |
| 154 | } |
| 155 | update_post_meta( $id, '_fraudlabspro', $row ); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | ?> |