flp-callback.php
97 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 | $id = (isset($_GET['orderid'])) ? sanitize_text_field($_GET['orderid']) : ''; |
| 13 | $action = (isset($_GET['action'])) ? sanitize_text_field($_GET['action']) : ''; |
| 14 | |
| 15 | if ( $id != '' ) { |
| 16 | $order = wc_get_order( $id ); |
| 17 | |
| 18 | // Update for Approve case |
| 19 | if ( $action == 'APPROVE' ) { |
| 20 | if( $flp_approve_status ) { |
| 21 | // Add note and change status |
| 22 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Approved.', 'woocommerce-fraudlabs-pro' ) ); |
| 23 | $order->update_status( $flp_approve_status ); |
| 24 | }else{ |
| 25 | // Add the note only |
| 26 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Approved.', 'woocommerce-fraudlabs-pro' ) ); |
| 27 | } |
| 28 | |
| 29 | $result = get_post_meta( $id, '_fraudlabspro' ); |
| 30 | if ( !is_array( $result[0] ) && !is_object( $result[0] ) ) { |
| 31 | $row = json_decode( $result[0] ); |
| 32 | } else { |
| 33 | $row = $result[0]; |
| 34 | } |
| 35 | |
| 36 | if ( is_array( $result[0] ) ) { |
| 37 | $row['fraudlabspro_status'] = 'APPROVE'; |
| 38 | } else { |
| 39 | $row->fraudlabspro_status = 'APPROVE'; |
| 40 | } |
| 41 | update_post_meta( $id, '_fraudlabspro', $row ); |
| 42 | } |
| 43 | // Update for Reject case |
| 44 | elseif( $action == 'REJECT' ) { |
| 45 | if( $flp_reject_status ) { |
| 46 | // Add note and change status |
| 47 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Rejected.', 'woocommerce-fraudlabs-pro' ) ); |
| 48 | $order->update_status( $flp_reject_status ); |
| 49 | }else{ |
| 50 | // Add the note only |
| 51 | $order->add_order_note( __( 'FraudLabs Pro status changed from Review to Rejected.', 'woocommerce-fraudlabs-pro' ) ); |
| 52 | } |
| 53 | |
| 54 | $result = get_post_meta( $id, '_fraudlabspro' ); |
| 55 | if ( !is_array( $result[0] ) && !is_object( $result[0] ) ) { |
| 56 | $row = json_decode( $result[0] ); |
| 57 | } else { |
| 58 | $row = $result[0]; |
| 59 | } |
| 60 | |
| 61 | if ( is_array( $result[0] ) ) { |
| 62 | $row['fraudlabspro_status'] = 'REJECT'; |
| 63 | } else { |
| 64 | $row->fraudlabspro_status = 'REJECT'; |
| 65 | } |
| 66 | update_post_meta( $id, '_fraudlabspro', $row ); |
| 67 | } |
| 68 | // Update for Blacklist case |
| 69 | elseif ( $action == 'REJECT_BLACKLIST' ) { |
| 70 | if( $flp_reject_status ) { |
| 71 | // Add note and change status |
| 72 | $order->add_order_note( __( 'Blacklisted order to FraudLabs Pro.', 'woocommerce-fraudlabs-pro' ) ); |
| 73 | $order->update_status( $flp_reject_status ); |
| 74 | }else{ |
| 75 | // Add the note only |
| 76 | $order->add_order_note( __( 'Blacklisted order to FraudLabs Pro.', 'woocommerce-fraudlabs-pro' ) ); |
| 77 | } |
| 78 | |
| 79 | $result = get_post_meta( $id, '_fraudlabspro' ); |
| 80 | if ( !is_array( $result[0] ) && !is_object( $result[0] ) ) { |
| 81 | $row = json_decode( $result[0] ); |
| 82 | } else { |
| 83 | $row = $result[0]; |
| 84 | } |
| 85 | |
| 86 | if ( is_array( $result[0] ) ) { |
| 87 | $row['fraudlabspro_status'] = 'REJECT'; |
| 88 | $row['is_blacklisted'] = '1'; |
| 89 | } else { |
| 90 | $row->fraudlabspro_status = 'REJECT'; |
| 91 | $row->is_blacklisted = '1'; |
| 92 | } |
| 93 | update_post_meta( $id, '_fraudlabspro', $row ); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | ?> |