Changeset 2788067
- Timestamp:
- 09/21/2022 09:07:29 AM (4 years ago)
- Location:
- app360/trunk
- Files:
-
- 3 edited
-
app360.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
transaction.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
app360/trunk/app360.php
r2783812 r2788067 11 11 * Plugin URI: https://www.app360.my/ 12 12 * Description: App360 CRM allows the integration between WooCommerce and App360 13 * Version: 1.3. 413 * Version: 1.3.5 14 14 * Author: App360 15 15 * License: GPLv2 or later … … 17 17 */ 18 18 19 /* 19 /* 20 20 license details here 21 21 */ … … 58 58 59 59 function 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 60 68 $app360_api_domain = get_option('app360_api_domain'); 61 69 $app360_api = get_option('app360_api'); -
app360/trunk/readme.txt
r2783812 r2788067 4 4 Requires at least: 5.6 5 5 Tested up to: 5.8 6 Stable tag: 1.3. 46 Stable tag: 1.3.5 7 7 License: GPLv2 or later 8 8 … … 38 38 39 39 == 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 40 46 41 47 = 1.3.4 = -
app360/trunk/transaction.php
r2783812 r2788067 661 661 } 662 662 } 663 664 665 //create redeem transaction in app360 666 add_filter('woocommerce_payment_successful_result', 'app360_redeem_voucher', 10, 2); 667 function 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.