Plugin Directory

Changeset 2788067


Ignore:
Timestamp:
09/21/2022 09:07:29 AM (4 years ago)
Author:
app360my
Message:

v1.3.5

  • feature | create redeem transaction on app360 after order payment complete
  • feature | prevent doing migration during plugin activation when capture processed migration before
Location:
app360/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app360/trunk/app360.php

    r2783812 r2788067  
    1111 * Plugin URI: https://www.app360.my/
    1212 * Description: App360 CRM allows the integration between WooCommerce and App360
    13  * Version: 1.3.4
     13 * Version: 1.3.5
    1414 * Author: App360
    1515 * License: GPLv2 or later
     
    1717 */
    1818
    19 /* 
     19/*
    2020license details here
    2121*/
     
    5858
    5959function app360_migrate(){
     60    global $wpdb;
     61
     62    $usermeta_app360 = $wpdb->get_results('SELECT `umeta_id` FROM '.$wpdb->usermeta.' WHERE `meta_key` LIKE "app360_%" LIMIT 1');
     63    if ($usermeta_app360) {
     64        //if found at least 1 usermeta for app360, then skip below migration
     65        return;
     66    }
     67
    6068    $app360_api_domain = get_option('app360_api_domain');
    6169    $app360_api = get_option('app360_api');
  • app360/trunk/readme.txt

    r2783812 r2788067  
    44Requires at least: 5.6
    55Tested up to: 5.8
    6 Stable tag: 1.3.4
     6Stable tag: 1.3.5
    77License: GPLv2 or later
    88
     
    3838
    3939== Changelog ==
     40
     41= 1.3.5 =
     42*Release Date - 21 September 2022*
     43
     44* feature  | create redeem transaction on app360 after order payment complete
     45* feature  | prevent doing migration during plugin activation when capture processed migration before
    4046
    4147= 1.3.4 =
  • app360/trunk/transaction.php

    r2783812 r2788067  
    661661    }
    662662}
     663
     664
     665//create redeem transaction in app360
     666add_filter('woocommerce_payment_successful_result', 'app360_redeem_voucher', 10, 2);
     667function app360_redeem_voucher($result, $order_id){
     668    $order = wc_get_order( $order_id );
     669    $order_data = $order->get_data();
     670
     671    if ($order_data['payment_method'] === 'app360') {
     672        //skip app360
     673        return $result;
     674    }
     675
     676    $user_id = $order->get_customer_id();
     677    $app360_user_id = get_user_meta( $user_id, 'app360_userid', true );
     678
     679    if($app360_user_id){
     680        $app360_api_domain = get_option('app360_api_domain');
     681        $app360_api = get_option('app360_api');
     682        if( $app360_api_domain && $app360_api ){
     683            foreach($order->get_coupon_codes() as $coupon_code){
     684                $args = array(
     685                    's'  => $coupon_code,
     686                    'post_type'   => 'shop_coupon'
     687                );
     688                $query = new WP_Query( $args );
     689                $coupon_posts = $query->posts;
     690                if($coupon_posts){
     691                    $reward_id = get_post_meta($coupon_posts[0]->ID, 'voucher_id', true) ? get_post_meta($coupon_posts[0]->ID, 'voucher_id', true) : 0;
     692                    if($reward_id && $reward_id != 0){
     693                        $url = $app360_api_domain.'/client/voucher/use?';
     694                        $url .= 'user_id='.$app360_user_id;
     695                        $url .= '&reward_id='.$reward_id;
     696                        $headers = array();
     697                        $headers['Content-type'] = 'application/json';
     698                        $headers['apikey'] = $app360_api;
     699                        $response = wp_remote_get($url, ['headers'=> $headers]);
     700
     701                        //$result = is_array($response) && isset($response['body']) ? json_decode($response['body']) : null;
     702                    }
     703                }
     704            }
     705        } else{
     706            wp_delete_post($order_id,true);
     707            throw new Exception( __( 'API not working.', 'woocommerce' ), 110 );
     708        }
     709    } elseif(!is_user_logged_in()){ // if user is not logged in
     710        // do nothing
     711    } else{
     712        wp_delete_post($order_id, true);
     713        throw new Exception( __( 'User ID not found.', 'woocommerce' ), 110 );
     714    }
     715
     716    return $result;
     717}
Note: See TracChangeset for help on using the changeset viewer.