Version Description
28/12/2021 =
In this release, we have optimization code.
Download this release
Release Info
Developer | Tatvic |
Plugin | Enhanced Ecommerce Google Analytics Plugin for WooCommerce |
Version | 4.5.6 |
Comparing to | |
See all releases |
Code changes from version 4.5.5 to 4.5.6
- admin/class-tvc-admin-auto-product-sync-helper.php +37 -40
- admin/helper/class-onboarding-helper.php +197 -182
- enhanced-ecommerce-google-analytics.php +2 -2
- includes/data/class-tvc-ajax-file.php +15 -59
- includes/setup/CustomApi.php +386 -375
- includes/setup/ShoppingApi.php +73 -51
- includes/setup/help-html.php +12 -10
- readme.txt +6 -2
admin/class-tvc-admin-auto-product-sync-helper.php
CHANGED
@@ -399,7 +399,7 @@ if ( ! class_exists( 'TVC_Admin_Auto_Product_sync_Helper' ) ) {
|
|
399 |
),
|
400 |
'body' => wp_json_encode($data)
|
401 |
);
|
402 |
-
$request = wp_remote_post($url, $args);
|
403 |
|
404 |
// Retrieve information
|
405 |
$response_code = wp_remote_retrieve_response_code($request);
|
@@ -472,47 +472,44 @@ if ( ! class_exists( 'TVC_Admin_Auto_Product_sync_Helper' ) ) {
|
|
472 |
}*/
|
473 |
|
474 |
public function generateAccessToken($access_token, $refresh_token) {
|
475 |
-
$
|
476 |
-
|
477 |
-
|
478 |
-
$ch = curl_init();
|
479 |
-
curl_setopt($ch, CURLOPT_URL, $request);
|
480 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
481 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
482 |
-
$response = curl_exec($ch);
|
483 |
-
$result = json_decode($response);
|
484 |
|
|
|
|
|
|
|
485 |
if (isset($result->error) && $result->error) {
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
}
|
517 |
public function get_tvc_access_token(){
|
518 |
if(!empty($this->access_token)){
|
399 |
),
|
400 |
'body' => wp_json_encode($data)
|
401 |
);
|
402 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
403 |
|
404 |
// Retrieve information
|
405 |
$response_code = wp_remote_retrieve_response_code($request);
|
472 |
}*/
|
473 |
|
474 |
public function generateAccessToken($access_token, $refresh_token) {
|
475 |
+
$url = "https://www.googleapis.com/oauth2/v1/tokeninfo?=" . $access_token;
|
476 |
+
$request = wp_remote_get(esc_url_raw($url), array("access_token"=>$access_token));
|
477 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
|
|
|
|
|
|
|
|
|
|
|
|
478 |
|
479 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
480 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
481 |
+
|
482 |
if (isset($result->error) && $result->error) {
|
483 |
+
$credentials = json_decode(file_get_contents(ENHANCAD_PLUGIN_DIR . 'includes/setup/json/client-secrets.json'), true);
|
484 |
+
$url = 'https://www.googleapis.com/oauth2/v4/token';
|
485 |
+
$header = array("content-type: application/json");
|
486 |
+
$clientId = $credentials['web']['client_id'];
|
487 |
+
$clientSecret = $credentials['web']['client_secret'];
|
488 |
+
|
489 |
+
$data = [
|
490 |
+
"grant_type" => 'refresh_token',
|
491 |
+
"client_id" => esc_attr($clientId),
|
492 |
+
'client_secret' => esc_attr($clientSecret),
|
493 |
+
'refresh_token' => esc_attr($refresh_token),
|
494 |
+
];
|
495 |
+
$args = array(
|
496 |
+
'headers' =>$header,
|
497 |
+
'method' => 'POST',
|
498 |
+
'body' => $data
|
499 |
+
);
|
500 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
501 |
+
// Retrieve information
|
502 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
503 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
504 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
505 |
+
if(isset($response->access_token)){
|
506 |
+
return $response->access_token;
|
507 |
+
}else{
|
508 |
+
//return $access_token;
|
509 |
+
}
|
510 |
+
} else {
|
511 |
+
return $access_token;
|
512 |
+
}
|
513 |
}
|
514 |
public function get_tvc_access_token(){
|
515 |
if(!empty($this->access_token)){
|
admin/helper/class-onboarding-helper.php
CHANGED
@@ -475,6 +475,7 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
475 |
// Send remote request
|
476 |
$args['timeout']= esc_attr("1000");
|
477 |
$request = wp_remote_post($url, $args);
|
|
|
478 |
// Retrieve information
|
479 |
$response_code = wp_remote_retrieve_response_code($request);
|
480 |
|
@@ -521,36 +522,6 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
521 |
|
522 |
}
|
523 |
|
524 |
-
public function updateTokenToSubscription($tvc_data) {
|
525 |
-
try {
|
526 |
-
$tvc_data = json_decode(base64_decode($tvc_data));
|
527 |
-
$url = $this->apiDomain . '/customer-subscriptions/update-token';
|
528 |
-
$header = array("Authorization: Bearer $this->token", "content-type: application/json");
|
529 |
-
$data = [
|
530 |
-
'subscription_id' => "",//$this->subscription_id,
|
531 |
-
'gmail' => sanitize_email($tvc_data->g_mail),
|
532 |
-
'access_token' => base64_decode(sanitize_text_field($this->access_token)),
|
533 |
-
'refresh_token' => base64_decode(sanitize_text_field($this->refresh_token)),
|
534 |
-
'domain' => sanitize_text_field($tvc_data->user_domain)
|
535 |
-
];
|
536 |
-
$curl_url = $url;
|
537 |
-
$data = json_encode($data);
|
538 |
-
$ch = curl_init();
|
539 |
-
curl_setopt_array($ch, array(
|
540 |
-
CURLOPT_URL => $curl_url, //esc_url($curl_url),
|
541 |
-
CURLOPT_RETURNTRANSFER => true,
|
542 |
-
CURLOPT_TIMEOUT => 0,
|
543 |
-
CURLOPT_HTTPHEADER => $header,
|
544 |
-
CURLOPT_POSTFIELDS => $data
|
545 |
-
));
|
546 |
-
$response = curl_exec($ch);
|
547 |
-
$response = json_decode($response);
|
548 |
-
return $response;
|
549 |
-
} catch (Exception $e) {
|
550 |
-
return $e->getMessage();
|
551 |
-
}
|
552 |
-
}
|
553 |
-
|
554 |
public function getSubscriptionDetails($tvc_data, $subscription_id){
|
555 |
try{
|
556 |
$tvc_data = (object)$tvc_data;
|
@@ -561,19 +532,25 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
561 |
'subscription_id' => sanitize_text_field($subscription_id),//$this->subscription_id,
|
562 |
'domain' => sanitize_text_field($tvc_data->user_domain)
|
563 |
];
|
564 |
-
$
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
577 |
}catch(Exception $e){
|
578 |
return $e->getMessage();
|
579 |
}
|
@@ -582,8 +559,8 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
582 |
public function getAnalyticsWebProperties($postData) {
|
583 |
try {
|
584 |
$url = $this->apiDomain . '/google-analytics/account-list';
|
|
|
585 |
$access_token = base64_decode(sanitize_text_field($this->access_token));
|
586 |
-
$header = array("Authorization: Bearer MTIzNA==", "content-type: application/json", "AccessToken: $access_token");
|
587 |
$max_results = 10;
|
588 |
$page = (isset($postData['page']) && sanitize_text_field($postData['page']) >1)?sanitize_text_field($postData['page']):"1";
|
589 |
if($page > 1){
|
@@ -595,20 +572,33 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
595 |
'page'=>sanitize_text_field($page),
|
596 |
'max_results'=>sanitize_text_field($max_results)
|
597 |
];
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
$
|
611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
612 |
} catch (Exception $e) {
|
613 |
return $e->getMessage();
|
614 |
}
|
@@ -620,18 +610,34 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
620 |
//$tvc_data = json_decode(base64_decode($postData['tvc_data']));
|
621 |
$url = $this->apiDomain . '/adwords/list';
|
622 |
$refresh_token = base64_decode(sanitize_text_field($this->refresh_token));
|
623 |
-
$
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
));
|
633 |
-
|
634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
635 |
}else{
|
636 |
return json_decode(array("error"=>true));
|
637 |
}
|
@@ -647,19 +653,24 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
647 |
$data = [
|
648 |
'access_token' => base64_decode(sanitize_text_field($this->access_token)),
|
649 |
];
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
|
|
|
|
|
|
|
|
|
|
663 |
} catch (Exception $e) {
|
664 |
return $e->getMessage();
|
665 |
}
|
@@ -721,52 +732,38 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
721 |
]
|
722 |
]
|
723 |
];
|
724 |
-
$
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
)
|
734 |
-
$
|
735 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
736 |
} catch (Exception $e) {
|
737 |
return $e->getMessage();
|
738 |
}
|
739 |
}
|
740 |
-
public function doCustomerLogin($tvc_data) {
|
741 |
-
try {
|
742 |
-
$tvc_data = json_decode(base64_decode($tvc_data));
|
743 |
-
$url = $this->apiDomain . '/customers/login';
|
744 |
-
$header = array("Authorization: Bearer MTIzNA==", "content-type: application/json");
|
745 |
-
$data = [
|
746 |
-
'email' => sanitize_email($tvc_data->g_mail),
|
747 |
-
'access_token' => base64_decode(sanitize_text_field($this->access_token)),
|
748 |
-
'refresh_token' => base64_decode(sanitize_text_field($this->refresh_token)),
|
749 |
-
'sign_in_type' => sanitize_text_field($tvc_data->sign_in_type)
|
750 |
-
];
|
751 |
-
$curl_url = $url;
|
752 |
-
$data = json_encode($data);
|
753 |
-
$ch = curl_init();
|
754 |
-
curl_setopt_array($ch, array(
|
755 |
-
CURLOPT_URL => esc_url_raw($curl_url), //esc_url($curl_url),
|
756 |
-
CURLOPT_RETURNTRANSFER => true,
|
757 |
-
CURLOPT_TIMEOUT => 0,
|
758 |
-
CURLOPT_HTTPHEADER => $header,
|
759 |
-
CURLOPT_POSTFIELDS => $data
|
760 |
-
));
|
761 |
-
$response = curl_exec($ch);
|
762 |
-
return json_decode($response);
|
763 |
-
} catch (Exception $e) {
|
764 |
-
return $e->getMessage();
|
765 |
-
}
|
766 |
-
}//doCustomerLogin
|
767 |
-
|
768 |
|
769 |
-
|
770 |
public function saveAnalyticsData($postData = array()) {
|
771 |
try {
|
772 |
$url = $this->apiDomain . '/customer-subscriptions/update-detail';
|
@@ -901,18 +898,24 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
901 |
'web_property' => sanitize_text_field($postData['web_property']),
|
902 |
];
|
903 |
}
|
904 |
-
$
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
916 |
} catch (Exception $e) {
|
917 |
return $e->getMessage();
|
918 |
}
|
@@ -927,18 +930,25 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
927 |
'account_id' => sanitize_text_field($postData['account_id']),
|
928 |
'adwords_id' => sanitize_text_field($postData['adwords_id'])
|
929 |
];
|
930 |
-
$
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
942 |
} catch (Exception $e) {
|
943 |
return $e->getMessage();
|
944 |
}
|
@@ -951,19 +961,25 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
951 |
'subscription_id' => sanitize_text_field((isset($postData['subscription_id']))?$postData['subscription_id'] : ''),
|
952 |
'setup_end_time' => date('Y-m-d H:i:s')
|
953 |
];
|
954 |
-
$
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
967 |
} catch (Exception $e) {
|
968 |
return $e->getMessage();
|
969 |
}
|
@@ -1040,15 +1056,12 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
1040 |
}
|
1041 |
}
|
1042 |
public function generateAccessToken($access_token, $refresh_token) {
|
1043 |
-
$
|
1044 |
-
|
|
|
1045 |
|
1046 |
-
$
|
1047 |
-
|
1048 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
1049 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
1050 |
-
$response = curl_exec($ch);
|
1051 |
-
$result = json_decode($response);
|
1052 |
|
1053 |
if (isset($result->error) && $result->error) {
|
1054 |
$credentials = json_decode(file_get_contents(ENHANCAD_PLUGIN_DIR . 'includes/setup/json/client-secrets.json'), true);
|
@@ -1063,19 +1076,21 @@ if(!class_exists('Conversios_Onboarding_ApiCall') ){
|
|
1063 |
'client_secret' => esc_attr($clientSecret),
|
1064 |
'refresh_token' => esc_attr($refresh_token),
|
1065 |
];
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
));
|
1076 |
-
$response
|
1077 |
-
|
1078 |
-
|
|
|
|
|
1079 |
} else {
|
1080 |
return $access_token;
|
1081 |
}
|
475 |
// Send remote request
|
476 |
$args['timeout']= esc_attr("1000");
|
477 |
$request = wp_remote_post($url, $args);
|
478 |
+
|
479 |
// Retrieve information
|
480 |
$response_code = wp_remote_retrieve_response_code($request);
|
481 |
|
522 |
|
523 |
}
|
524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
public function getSubscriptionDetails($tvc_data, $subscription_id){
|
526 |
try{
|
527 |
$tvc_data = (object)$tvc_data;
|
532 |
'subscription_id' => sanitize_text_field($subscription_id),//$this->subscription_id,
|
533 |
'domain' => sanitize_text_field($tvc_data->user_domain)
|
534 |
];
|
535 |
+
$args = array(
|
536 |
+
'headers' =>$header,
|
537 |
+
'method' => 'POST',
|
538 |
+
'body' => $data
|
539 |
+
);
|
540 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
541 |
+
|
542 |
+
$return = new \stdClass();
|
543 |
+
if($result->status == 200){
|
544 |
+
$return->status = $result->status;
|
545 |
+
$return->data = $result->data;
|
546 |
+
$return->error = false;
|
547 |
+
return $return;
|
548 |
+
}else{
|
549 |
+
$return->error = true;
|
550 |
+
$return->data = $result->data;
|
551 |
+
$return->status = $result->status;
|
552 |
+
return $return;
|
553 |
+
}
|
554 |
}catch(Exception $e){
|
555 |
return $e->getMessage();
|
556 |
}
|
559 |
public function getAnalyticsWebProperties($postData) {
|
560 |
try {
|
561 |
$url = $this->apiDomain . '/google-analytics/account-list';
|
562 |
+
|
563 |
$access_token = base64_decode(sanitize_text_field($this->access_token));
|
|
|
564 |
$max_results = 10;
|
565 |
$page = (isset($postData['page']) && sanitize_text_field($postData['page']) >1)?sanitize_text_field($postData['page']):"1";
|
566 |
if($page > 1){
|
572 |
'page'=>sanitize_text_field($page),
|
573 |
'max_results'=>sanitize_text_field($max_results)
|
574 |
];
|
575 |
+
$args = array(
|
576 |
+
'timeout' => 10000,
|
577 |
+
'headers' => array(
|
578 |
+
'Authorization' => "Bearer MTIzNA==",
|
579 |
+
'Content-Type' => 'application/json',
|
580 |
+
'AccessToken' => $access_token
|
581 |
+
),
|
582 |
+
'body' => wp_json_encode($data)
|
583 |
+
);
|
584 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
585 |
+
|
586 |
+
// Retrieve information
|
587 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
588 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
589 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
590 |
+
$return = new \stdClass();
|
591 |
+
if (isset($response->error) && $response->error == '') {
|
592 |
+
$return->status = $response_code;
|
593 |
+
$return->data = $response->data;
|
594 |
+
$return->error = false;
|
595 |
+
return $return;
|
596 |
+
}else{
|
597 |
+
$return->error = true;
|
598 |
+
$return->data = $response->data;
|
599 |
+
$return->status = $response_code;
|
600 |
+
return $return;
|
601 |
+
}
|
602 |
} catch (Exception $e) {
|
603 |
return $e->getMessage();
|
604 |
}
|
610 |
//$tvc_data = json_decode(base64_decode($postData['tvc_data']));
|
611 |
$url = $this->apiDomain . '/adwords/list';
|
612 |
$refresh_token = base64_decode(sanitize_text_field($this->refresh_token));
|
613 |
+
$args = array(
|
614 |
+
'timeout' => 10000,
|
615 |
+
'headers' => array(
|
616 |
+
'Authorization' => "Bearer MTIzNA==",
|
617 |
+
'Content-Type' => 'application/json',
|
618 |
+
'RefreshToken' => $refresh_token
|
619 |
+
),
|
620 |
+
'body' => wp_json_encode($data)
|
621 |
+
);
|
622 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
623 |
+
|
624 |
+
// Retrieve information
|
625 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
626 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
627 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
628 |
+
//print_r($response);
|
629 |
+
$return = new \stdClass();
|
630 |
+
if (isset($response->error) && $response->error == '') {
|
631 |
+
$return->status = $response_code;
|
632 |
+
$return->data = $response->data;
|
633 |
+
$return->error = false;
|
634 |
+
return $return;
|
635 |
+
}else{
|
636 |
+
$return->error = true;
|
637 |
+
$return->data = $response->data;
|
638 |
+
$return->status = $response_code;
|
639 |
+
return $return;
|
640 |
+
}
|
641 |
}else{
|
642 |
return json_decode(array("error"=>true));
|
643 |
}
|
653 |
$data = [
|
654 |
'access_token' => base64_decode(sanitize_text_field($this->access_token)),
|
655 |
];
|
656 |
+
$args = array(
|
657 |
+
'headers' =>$header,
|
658 |
+
'method' => 'POST',
|
659 |
+
'body' => $data
|
660 |
+
);
|
661 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
662 |
+
$return = new \stdClass();
|
663 |
+
if($result->status == 200){
|
664 |
+
$return->status = $result->status;
|
665 |
+
$return->data = $result->data;
|
666 |
+
$return->error = false;
|
667 |
+
return $return;
|
668 |
+
}else{
|
669 |
+
$return->error = true;
|
670 |
+
$return->data = $result->data;
|
671 |
+
$return->status = $result->status;
|
672 |
+
return $return;
|
673 |
+
}
|
674 |
} catch (Exception $e) {
|
675 |
return $e->getMessage();
|
676 |
}
|
732 |
]
|
733 |
]
|
734 |
];
|
735 |
+
$args = array(
|
736 |
+
'headers' =>$header,
|
737 |
+
'method' => 'POST',
|
738 |
+
'body' => $data
|
739 |
+
);
|
740 |
+
$args = array(
|
741 |
+
'headers' =>$header,
|
742 |
+
'method' => 'POST',
|
743 |
+
'body' => $data
|
744 |
+
);
|
745 |
+
$args['timeout']= esc_attr("1000");
|
746 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
747 |
+
|
748 |
+
// Retrieve information
|
749 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
750 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
751 |
+
$response_body = json_decode(wp_remote_retrieve_body($request));
|
752 |
+
if ((isset($response_body->error) && $response_body->error == '') || (!isset($response_body->error)) ) {
|
753 |
+
return $response_body;
|
754 |
+
} else {
|
755 |
+
$return = new \stdClass();
|
756 |
+
$return->error = true;
|
757 |
+
//$return->data = $result->data;
|
758 |
+
$return->status = $response_code;
|
759 |
+
return $return;
|
760 |
+
//return new WP_Error($response_code, $response_message, $response_body);
|
761 |
+
}
|
762 |
} catch (Exception $e) {
|
763 |
return $e->getMessage();
|
764 |
}
|
765 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
766 |
|
|
|
767 |
public function saveAnalyticsData($postData = array()) {
|
768 |
try {
|
769 |
$url = $this->apiDomain . '/customer-subscriptions/update-detail';
|
898 |
'web_property' => sanitize_text_field($postData['web_property']),
|
899 |
];
|
900 |
}
|
901 |
+
$args = array(
|
902 |
+
'headers' =>$header,
|
903 |
+
'method' => 'POST',
|
904 |
+
'body' => $data
|
905 |
+
);
|
906 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
907 |
+
$return = new \stdClass();
|
908 |
+
if($result->status == 200){
|
909 |
+
$return->status = $result->status;
|
910 |
+
$return->data = $result->data;
|
911 |
+
$return->error = false;
|
912 |
+
return $return;
|
913 |
+
}else{
|
914 |
+
$return->error = true;
|
915 |
+
$return->data = $result->data;
|
916 |
+
$return->status = $result->status;
|
917 |
+
return $return;
|
918 |
+
}
|
919 |
} catch (Exception $e) {
|
920 |
return $e->getMessage();
|
921 |
}
|
930 |
'account_id' => sanitize_text_field($postData['account_id']),
|
931 |
'adwords_id' => sanitize_text_field($postData['adwords_id'])
|
932 |
];
|
933 |
+
$args = array(
|
934 |
+
'headers' =>$header,
|
935 |
+
'method' => 'POST',
|
936 |
+
'body' => $data
|
937 |
+
);
|
938 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
939 |
+
$return = new \stdClass();
|
940 |
+
if($result->status == 200){
|
941 |
+
$return->status = $result->status;
|
942 |
+
$return->data = $result->data;
|
943 |
+
$return->error = false;
|
944 |
+
return $return;
|
945 |
+
}else{
|
946 |
+
$return->error = true;
|
947 |
+
$return->data = $result->data;
|
948 |
+
$return->status = $result->status;
|
949 |
+
return $return;
|
950 |
+
}
|
951 |
+
|
952 |
} catch (Exception $e) {
|
953 |
return $e->getMessage();
|
954 |
}
|
961 |
'subscription_id' => sanitize_text_field((isset($postData['subscription_id']))?$postData['subscription_id'] : ''),
|
962 |
'setup_end_time' => date('Y-m-d H:i:s')
|
963 |
];
|
964 |
+
$args = array(
|
965 |
+
'headers' =>$header,
|
966 |
+
'method' => 'POST',
|
967 |
+
'body' => $data
|
968 |
+
);
|
969 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
970 |
+
$return = new \stdClass();
|
971 |
+
if($result->status == 200){
|
972 |
+
$return->status = $result->status;
|
973 |
+
$return->data = $result->data;
|
974 |
+
$return->error = false;
|
975 |
+
return $return;
|
976 |
+
}else{
|
977 |
+
$return->error = true;
|
978 |
+
$return->data = $result->data;
|
979 |
+
$return->status = $result->status;
|
980 |
+
return $return;
|
981 |
+
}
|
982 |
+
|
983 |
} catch (Exception $e) {
|
984 |
return $e->getMessage();
|
985 |
}
|
1056 |
}
|
1057 |
}
|
1058 |
public function generateAccessToken($access_token, $refresh_token) {
|
1059 |
+
$url = "https://www.googleapis.com/oauth2/v1/tokeninfo?=" . $access_token;
|
1060 |
+
$request = wp_remote_get(esc_url_raw($url), array("access_token"=>$access_token));
|
1061 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
1062 |
|
1063 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
1064 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
|
|
|
|
|
|
|
|
1065 |
|
1066 |
if (isset($result->error) && $result->error) {
|
1067 |
$credentials = json_decode(file_get_contents(ENHANCAD_PLUGIN_DIR . 'includes/setup/json/client-secrets.json'), true);
|
1076 |
'client_secret' => esc_attr($clientSecret),
|
1077 |
'refresh_token' => esc_attr($refresh_token),
|
1078 |
];
|
1079 |
+
$args = array(
|
1080 |
+
'headers' =>$header,
|
1081 |
+
'method' => 'POST',
|
1082 |
+
'body' => $data
|
1083 |
+
);
|
1084 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
1085 |
+
// Retrieve information
|
1086 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
1087 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
1088 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
1089 |
+
if(isset($response->access_token)){
|
1090 |
+
return $response->access_token;
|
1091 |
+
}else{
|
1092 |
+
//return $access_token;
|
1093 |
+
}
|
1094 |
} else {
|
1095 |
return $access_token;
|
1096 |
}
|
enhanced-ecommerce-google-analytics.php
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
* Plugin Name: Conversios.io - Google Analytics and Google Shopping plugin for WooCommerce
|
16 |
* Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
|
17 |
* Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
|
18 |
-
* Version: 4.5.
|
19 |
* Author: Tatvic
|
20 |
* Author URI: www.tatvic.com
|
21 |
* License: GPL-2.0+
|
@@ -37,7 +37,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
37 |
* Start at version 1.0.0 and use SemVer - https://semver.org
|
38 |
* Rename this for your plugin and update it as you release new versions.
|
39 |
*/
|
40 |
-
define( 'PLUGIN_TVC_VERSION', '4.5.
|
41 |
$fullName = plugin_basename( __FILE__ );
|
42 |
$dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
|
43 |
if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
|
15 |
* Plugin Name: Conversios.io - Google Analytics and Google Shopping plugin for WooCommerce
|
16 |
* Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
|
17 |
* Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
|
18 |
+
* Version: 4.5.6
|
19 |
* Author: Tatvic
|
20 |
* Author URI: www.tatvic.com
|
21 |
* License: GPL-2.0+
|
37 |
* Start at version 1.0.0 and use SemVer - https://semver.org
|
38 |
* Rename this for your plugin and update it as you release new versions.
|
39 |
*/
|
40 |
+
define( 'PLUGIN_TVC_VERSION', '4.5.6' );
|
41 |
$fullName = plugin_basename( __FILE__ );
|
42 |
$dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
|
43 |
if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
|
includes/data/class-tvc-ajax-file.php
CHANGED
@@ -385,7 +385,7 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
385 |
'body' => wp_json_encode($data)
|
386 |
);
|
387 |
// Send remote request
|
388 |
-
$request = wp_remote_request($url, $args);
|
389 |
|
390 |
// Retrieve information
|
391 |
$response_code = wp_remote_retrieve_response_code($request);
|
@@ -442,18 +442,18 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
442 |
'ad_group_id' => $campaignData->data['data']->adGroupId,
|
443 |
'ad_group_resource_name' => $campaignData->data['data']->adGroupResourceName
|
444 |
];
|
445 |
-
|
446 |
-
$
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
if (isset($response->error) && $response->error == false) {
|
458 |
$message = $response->message;
|
459 |
echo json_encode(['status' => 'success', 'message' => $message]);
|
@@ -490,7 +490,7 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
490 |
);
|
491 |
|
492 |
// Send remote request
|
493 |
-
$request = wp_remote_post($url, $args);
|
494 |
|
495 |
// Retrieve information
|
496 |
$response_code = wp_remote_retrieve_response_code($request);
|
@@ -545,7 +545,7 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
545 |
);
|
546 |
|
547 |
// Send remote request
|
548 |
-
$request = wp_remote_post($url, $args);
|
549 |
|
550 |
// Retrieve information
|
551 |
$response_code = wp_remote_retrieve_response_code($request);
|
@@ -573,50 +573,6 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
573 |
exit;
|
574 |
}
|
575 |
|
576 |
-
public function generateAccessToken($access_token, $refresh_token) {
|
577 |
-
$request = "https://www.googleapis.com/oauth2/v1/tokeninfo?"
|
578 |
-
. "access_token=" . $access_token;
|
579 |
-
|
580 |
-
$ch = curl_init();
|
581 |
-
curl_setopt($ch, CURLOPT_URL, $request);
|
582 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
583 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
584 |
-
$response = curl_exec($ch);
|
585 |
-
$result = json_decode($response);
|
586 |
-
|
587 |
-
if (isset($result->error) && $result->error) {
|
588 |
-
$credentials_file = ENHANCAD_PLUGIN_DIR . 'includes/setup/json/client-secrets.json';
|
589 |
-
$str = file_get_contents($credentials_file);
|
590 |
-
$credentials = $str ? json_decode($str, true) : [];
|
591 |
-
$url = 'https://www.googleapis.com/oauth2/v4/token';
|
592 |
-
$header = array("content-type: application/json");
|
593 |
-
$clientId = sanitize_text_field($credentials['web']['client_id']);
|
594 |
-
$clientSecret = sanitize_text_field($credentials['web']['client_secret']);
|
595 |
-
$refreshToken = $refresh_token;
|
596 |
-
$data = [
|
597 |
-
"grant_type" => 'refresh_token',
|
598 |
-
"client_id" => $clientId,
|
599 |
-
'client_secret' => $clientSecret,
|
600 |
-
'refresh_token' => $refreshToken,
|
601 |
-
];
|
602 |
-
|
603 |
-
$postData = json_encode($data);
|
604 |
-
$ch = curl_init();
|
605 |
-
curl_setopt_array($ch, array(
|
606 |
-
CURLOPT_URL => $url, //esc_url($this->curl_url),
|
607 |
-
CURLOPT_RETURNTRANSFER => true,
|
608 |
-
CURLOPT_TIMEOUT => 0,
|
609 |
-
CURLOPT_HTTPHEADER => $header,
|
610 |
-
CURLOPT_POSTFIELDS => $postData
|
611 |
-
));
|
612 |
-
$response = curl_exec($ch);
|
613 |
-
$response = json_decode($response);
|
614 |
-
return $response->access_token;
|
615 |
-
} else {
|
616 |
-
return $access_token;
|
617 |
-
}
|
618 |
-
}
|
619 |
-
|
620 |
}
|
621 |
// End of TVC_Ajax_File_Class
|
622 |
endif;
|
385 |
'body' => wp_json_encode($data)
|
386 |
);
|
387 |
// Send remote request
|
388 |
+
$request = wp_remote_request(esc_url_raw($url), $args);
|
389 |
|
390 |
// Retrieve information
|
391 |
$response_code = wp_remote_retrieve_response_code($request);
|
442 |
'ad_group_id' => $campaignData->data['data']->adGroupId,
|
443 |
'ad_group_resource_name' => $campaignData->data['data']->adGroupResourceName
|
444 |
];
|
445 |
+
|
446 |
+
$args = array(
|
447 |
+
'headers' =>$header,
|
448 |
+
'method' => 'PATCH',
|
449 |
+
'body' => $data
|
450 |
+
);
|
451 |
+
$request = wp_remote_request(esc_url_raw($curl_url), $args);
|
452 |
+
//print_r($request);
|
453 |
+
// Retrieve information
|
454 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
455 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
456 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
457 |
if (isset($response->error) && $response->error == false) {
|
458 |
$message = $response->message;
|
459 |
echo json_encode(['status' => 'success', 'message' => $message]);
|
490 |
);
|
491 |
|
492 |
// Send remote request
|
493 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
494 |
|
495 |
// Retrieve information
|
496 |
$response_code = wp_remote_retrieve_response_code($request);
|
545 |
);
|
546 |
|
547 |
// Send remote request
|
548 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
549 |
|
550 |
// Retrieve information
|
551 |
$response_code = wp_remote_retrieve_response_code($request);
|
573 |
exit;
|
574 |
}
|
575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
}
|
577 |
// End of TVC_Ajax_File_Class
|
578 |
endif;
|
includes/setup/CustomApi.php
CHANGED
@@ -33,6 +33,31 @@ class CustomApi{
|
|
33 |
return $this->refresh_token;
|
34 |
}
|
35 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
public function is_allow_call_api(){
|
37 |
$ee_options_data = unserialize(get_option('ee_options'));
|
38 |
if(isset($ee_options_data['subscription_id'])) {
|
@@ -44,6 +69,7 @@ class CustomApi{
|
|
44 |
|
45 |
public function getGoogleAnalyticDetail($subscription_id = null) {
|
46 |
try {
|
|
|
47 |
$url = $this->apiDomain . '/customer-subscriptions/subscription-detail';
|
48 |
$header = array(
|
49 |
"Authorization: Bearer ".$this->token,
|
@@ -57,38 +83,29 @@ class CustomApi{
|
|
57 |
'subscription_id' => sanitize_text_field($subscription_id),
|
58 |
'domain' => get_site_url()
|
59 |
];
|
60 |
-
$
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
$
|
|
|
71 |
$return = new \stdClass();
|
72 |
-
if
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
}
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
} else {
|
83 |
-
$return->error = true;
|
84 |
-
$return->data = [];
|
85 |
-
if(isset($response_body->errors->key[0])){
|
86 |
-
$return->message = $response_body->errors->key[0];
|
87 |
-
}else{
|
88 |
-
$return->message = esc_html__("Please try after some time.","conversios");
|
89 |
-
}
|
90 |
-
}
|
91 |
-
return $return;
|
92 |
}
|
93 |
|
94 |
} catch (Exception $e) {
|
@@ -139,27 +156,24 @@ class CustomApi{
|
|
139 |
"Authorization: Bearer MTIzNA==",
|
140 |
"content-type: application/json"
|
141 |
);
|
142 |
-
$
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
CURLOPT_HTTPHEADER => $header,
|
150 |
-
CURLOPT_POSTFIELDS => $postData
|
151 |
-
));
|
152 |
-
$response = curl_exec($ch);
|
153 |
-
$response = json_decode($response);
|
154 |
$return = new \stdClass();
|
155 |
-
if
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
163 |
}
|
164 |
} catch (Exception $e) {
|
165 |
return $e->getMessage();
|
@@ -171,31 +185,30 @@ class CustomApi{
|
|
171 |
"Authorization: Bearer MTIzNA==",
|
172 |
"content-type: application/json"
|
173 |
);
|
174 |
-
$
|
175 |
-
$
|
176 |
'key' => esc_attr($licence_key),
|
177 |
'domain' => get_site_url(),
|
178 |
'subscription_id'=>esc_attr($subscription_id)
|
179 |
];
|
180 |
-
$
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
)
|
189 |
-
$response =
|
190 |
-
$response = json_decode($response);
|
191 |
$return = new \stdClass();
|
192 |
-
if (isset($response->error) && $response->error == '') {
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
}
|
198 |
-
|
199 |
$return->error = false;
|
200 |
$return->data = $response->data;
|
201 |
$return->message = $response->message;
|
@@ -210,6 +223,7 @@ class CustomApi{
|
|
210 |
|
211 |
}
|
212 |
return $return;
|
|
|
213 |
}
|
214 |
} catch (Exception $e) {
|
215 |
return $e->getMessage();
|
@@ -221,42 +235,28 @@ class CustomApi{
|
|
221 |
"Authorization: Bearer MTIzNA==",
|
222 |
"content-type: application/json"
|
223 |
);
|
224 |
-
$
|
225 |
-
$
|
226 |
'customer_id' => esc_attr($customer_id)
|
227 |
];
|
228 |
-
$
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
CURLOPT_POSTFIELDS => $postData
|
236 |
-
));
|
237 |
-
$response = curl_exec($ch);
|
238 |
-
$response = json_decode($response);
|
239 |
$return = new \stdClass();
|
240 |
-
if
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
}
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
} else {
|
251 |
-
$return->error = true;
|
252 |
-
$return->data = [];
|
253 |
-
if(isset($response->errors->key[0])){
|
254 |
-
$return->message = $response->errors->key[0];
|
255 |
-
}else{
|
256 |
-
$return->message = "";
|
257 |
-
}
|
258 |
-
}
|
259 |
-
return $return;
|
260 |
}
|
261 |
} catch (Exception $e) {
|
262 |
return $e->getMessage();
|
@@ -268,23 +268,30 @@ class CustomApi{
|
|
268 |
"Authorization: Bearer MTIzNA==",
|
269 |
"content-type: application/json"
|
270 |
);
|
271 |
-
$
|
272 |
-
$
|
273 |
'merchant_id' => esc_attr($merchant_id),
|
274 |
'customer_id' => esc_attr($customer_id)
|
275 |
];
|
276 |
-
$
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
)
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
} catch (Exception $e) {
|
289 |
return $e->getMessage();
|
290 |
}
|
@@ -293,26 +300,33 @@ class CustomApi{
|
|
293 |
* @since 4.1.4
|
294 |
* Get view ID for GA3 reporting API
|
295 |
*/
|
296 |
-
public function get_analytics_viewid_currency($
|
297 |
try {
|
298 |
$header = array(
|
299 |
"Authorization: Bearer MTIzNA==",
|
300 |
"content-type: application/json"
|
301 |
);
|
302 |
-
$
|
303 |
-
$
|
304 |
-
$
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
)
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
} catch (Exception $e) {
|
317 |
return $e->getMessage();
|
318 |
}
|
@@ -321,9 +335,9 @@ class CustomApi{
|
|
321 |
* @since 4.1.4
|
322 |
* Get google analytics reports call using reporting API
|
323 |
*/
|
324 |
-
public function get_google_analytics_reports($
|
325 |
try {
|
326 |
-
$
|
327 |
$header = array(
|
328 |
"Authorization: Bearer MTIzNA==",
|
329 |
"content-type: application/json"
|
@@ -331,19 +345,26 @@ class CustomApi{
|
|
331 |
|
332 |
$access_token = $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token());
|
333 |
if($access_token != ""){
|
334 |
-
$
|
335 |
-
$
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
)
|
344 |
-
|
345 |
-
|
346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
}else{
|
348 |
$return = new \stdClass();
|
349 |
$return->error = true;
|
@@ -354,36 +375,6 @@ class CustomApi{
|
|
354 |
return $e->getMessage();
|
355 |
}
|
356 |
}
|
357 |
-
public function verifyLicenceKey($licence_key, $subscription_id) {
|
358 |
-
try {
|
359 |
-
$url = $this->apiDomain . '/licence/verify-key';
|
360 |
-
$data = [
|
361 |
-
'key' => $licence_key,
|
362 |
-
'domain' => get_site_url()
|
363 |
-
];
|
364 |
-
$args = array(
|
365 |
-
'headers' => array(
|
366 |
-
'Authorization' => "Bearer $this->token",
|
367 |
-
'Content-Type' => 'application/json'
|
368 |
-
),
|
369 |
-
'method' => 'POST',
|
370 |
-
'body' => wp_json_encode($data)
|
371 |
-
);
|
372 |
-
// Send remote request
|
373 |
-
$request = wp_remote_post(esc_url_raw($url), $args);
|
374 |
-
// Retrieve information
|
375 |
-
$response_code = wp_remote_retrieve_response_code($request);
|
376 |
-
$response_message = wp_remote_retrieve_response_message($request);
|
377 |
-
$response_body = json_decode(wp_remote_retrieve_body($request));
|
378 |
-
if ((isset($response_body->error) && $response_body->error == '')) {
|
379 |
-
return new WP_REST_Response(array('status' => $response_code, 'message' => $response_message,'data' => $response_body->data ));
|
380 |
-
} else {
|
381 |
-
return new WP_Error($response_code, $response_message, $response_body);
|
382 |
-
}
|
383 |
-
} catch (Exception $e) {
|
384 |
-
return $e->getMessage();
|
385 |
-
}
|
386 |
-
}
|
387 |
|
388 |
public function setGmcCategoryMapping($postData) {
|
389 |
try {
|
@@ -461,201 +452,202 @@ class CustomApi{
|
|
461 |
}
|
462 |
public function products_sync($data) {
|
463 |
try {
|
464 |
-
$
|
465 |
-
|
466 |
-
|
467 |
-
|
|
|
|
|
|
|
|
|
|
|
468 |
);
|
469 |
-
$
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
CURLOPT_TIMEOUT => 10000,
|
476 |
-
CURLOPT_HTTPHEADER => $header,
|
477 |
-
CURLOPT_POSTFIELDS => $postData
|
478 |
-
));
|
479 |
-
$response = curl_exec($ch);
|
480 |
-
$response = json_decode($response);
|
481 |
$return = new \stdClass();
|
482 |
if (isset($response->error) && $response->error == '') {
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
}else{
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
}
|
494 |
} catch (Exception $e) {
|
495 |
return $e->getMessage();
|
496 |
}
|
497 |
}
|
498 |
public function getSyncProductList($postData) {
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
}
|
534 |
-
} catch (Exception $e) {
|
535 |
-
return $e->getMessage();
|
536 |
}
|
|
|
|
|
|
|
|
|
537 |
}
|
538 |
|
539 |
|
540 |
public function getCampaignCurrencySymbol($postData) {
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
}
|
575 |
|
576 |
-
public function generateAccessToken($access_token, $refresh_token) {
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
return $response->access_token;
|
613 |
-
}else{
|
614 |
-
//return $access_token;
|
615 |
-
}
|
616 |
} else {
|
617 |
return $access_token;
|
618 |
}
|
619 |
-
}
|
620 |
|
621 |
public function siteVerificationToken($postData) {
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
$
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
return $
|
652 |
-
|
|
|
|
|
|
|
|
|
|
|
653 |
}
|
654 |
|
655 |
public function siteVerification($postData) {
|
656 |
try {
|
657 |
$url = $this->apiDomain . '/gmc/site-verification';
|
658 |
-
$
|
659 |
"content-type: application/json",
|
660 |
"AccessToken:" . $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
661 |
);
|
@@ -668,20 +660,30 @@ class CustomApi{
|
|
668 |
'method' => esc_attr($postData['method'])
|
669 |
];
|
670 |
|
671 |
-
$
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
$
|
684 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
685 |
} catch (Exception $e) {
|
686 |
return $e->getMessage();
|
687 |
}
|
@@ -690,7 +692,7 @@ class CustomApi{
|
|
690 |
public function claimWebsite($postData) {
|
691 |
try {
|
692 |
$url = $this->apiDomain . '/gmc/claim-website';
|
693 |
-
$
|
694 |
"content-type: application/json",
|
695 |
"AccessToken:" . $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
696 |
);
|
@@ -701,21 +703,30 @@ class CustomApi{
|
|
701 |
'access_token' => $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token()),
|
702 |
'subscription_id' => esc_attr($postData['subscription_id']),
|
703 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
704 |
|
705 |
-
$
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
$this->response = json_decode($this->response);
|
718 |
-
return $this->response;
|
719 |
} catch (Exception $e) {
|
720 |
return $e->getMessage();
|
721 |
}
|
33 |
return $this->refresh_token;
|
34 |
}
|
35 |
}
|
36 |
+
|
37 |
+
public function tc_wp_remot_call_post($url, $args){
|
38 |
+
try {
|
39 |
+
if(!empty($args)){
|
40 |
+
// Send remote request
|
41 |
+
$args['timeout']= esc_attr("1000");
|
42 |
+
$request = wp_remote_post($url, $args);
|
43 |
+
|
44 |
+
// Retrieve information
|
45 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
46 |
+
|
47 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
48 |
+
$response_body = json_decode(wp_remote_retrieve_body($request));
|
49 |
+
|
50 |
+
if ((isset($response_body->error) && $response_body->error == '')) {
|
51 |
+
return new WP_REST_Response($response_body->data);
|
52 |
+
} else {
|
53 |
+
return new WP_Error($response_code, $response_message, $response_body);
|
54 |
+
}
|
55 |
+
}
|
56 |
+
} catch (Exception $e) {
|
57 |
+
return $e->getMessage();
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
public function is_allow_call_api(){
|
62 |
$ee_options_data = unserialize(get_option('ee_options'));
|
63 |
if(isset($ee_options_data['subscription_id'])) {
|
69 |
|
70 |
public function getGoogleAnalyticDetail($subscription_id = null) {
|
71 |
try {
|
72 |
+
|
73 |
$url = $this->apiDomain . '/customer-subscriptions/subscription-detail';
|
74 |
$header = array(
|
75 |
"Authorization: Bearer ".$this->token,
|
83 |
'subscription_id' => sanitize_text_field($subscription_id),
|
84 |
'domain' => get_site_url()
|
85 |
];
|
86 |
+
if($subscription_id == ""){
|
87 |
+
$return = new \stdClass();
|
88 |
+
$return->error = true;
|
89 |
+
return $return;
|
90 |
+
}
|
91 |
+
$args = array(
|
92 |
+
'headers' =>$header,
|
93 |
+
'method' => 'POST',
|
94 |
+
'body' => $data
|
95 |
+
);
|
96 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
97 |
+
|
98 |
$return = new \stdClass();
|
99 |
+
if($result->status == 200){
|
100 |
+
$return->status = $result->status;
|
101 |
+
$return->data = $result->data;
|
102 |
+
$return->error = false;
|
103 |
+
return $return;
|
104 |
+
}else{
|
105 |
+
$return->error = true;
|
106 |
+
$return->data = $result->data;
|
107 |
+
$return->status = $result->status;
|
108 |
+
return $return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
|
111 |
} catch (Exception $e) {
|
156 |
"Authorization: Bearer MTIzNA==",
|
157 |
"content-type: application/json"
|
158 |
);
|
159 |
+
$args = array(
|
160 |
+
'headers' =>$header,
|
161 |
+
'method' => 'POST',
|
162 |
+
'body' => $data
|
163 |
+
);
|
164 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
165 |
+
|
|
|
|
|
|
|
|
|
|
|
166 |
$return = new \stdClass();
|
167 |
+
if($result->status == 200){
|
168 |
+
$return->status = $result->status;
|
169 |
+
$return->data = $result->data;
|
170 |
+
$return->error = false;
|
171 |
+
return $return;
|
172 |
+
}else{
|
173 |
+
$return->error = true;
|
174 |
+
$return->data = $result->data;
|
175 |
+
$return->status = $result->status;
|
176 |
+
return $return;
|
177 |
}
|
178 |
} catch (Exception $e) {
|
179 |
return $e->getMessage();
|
185 |
"Authorization: Bearer MTIzNA==",
|
186 |
"content-type: application/json"
|
187 |
);
|
188 |
+
$url = $this->apiDomain . "/licence/activation";
|
189 |
+
$data = [
|
190 |
'key' => esc_attr($licence_key),
|
191 |
'domain' => get_site_url(),
|
192 |
'subscription_id'=>esc_attr($subscription_id)
|
193 |
];
|
194 |
+
$args = array(
|
195 |
+
'headers' =>$header,
|
196 |
+
'method' => 'POST',
|
197 |
+
'body' => $data
|
198 |
+
);
|
199 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
200 |
+
// Retrieve information
|
201 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
202 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
203 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
|
|
204 |
$return = new \stdClass();
|
205 |
+
if ((isset($response->error) && $response->error == '')) {
|
206 |
+
//$return->status = $result->status;
|
207 |
+
$return->data = $response->data;
|
208 |
+
$return->error = false;
|
209 |
+
return $return;
|
210 |
+
}else{
|
211 |
+
if (isset($response->data)) {
|
212 |
$return->error = false;
|
213 |
$return->data = $response->data;
|
214 |
$return->message = $response->message;
|
223 |
|
224 |
}
|
225 |
return $return;
|
226 |
+
return $return;
|
227 |
}
|
228 |
} catch (Exception $e) {
|
229 |
return $e->getMessage();
|
235 |
"Authorization: Bearer MTIzNA==",
|
236 |
"content-type: application/json"
|
237 |
);
|
238 |
+
$url = $this->apiDomain . "/google-ads/remarketing-snippets";
|
239 |
+
$data = [
|
240 |
'customer_id' => esc_attr($customer_id)
|
241 |
];
|
242 |
+
$args = array(
|
243 |
+
'headers' =>$header,
|
244 |
+
'method' => 'POST',
|
245 |
+
'body' => $data
|
246 |
+
);
|
247 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
248 |
+
|
|
|
|
|
|
|
|
|
249 |
$return = new \stdClass();
|
250 |
+
if($result->status == 200){
|
251 |
+
$return->status = $result->status;
|
252 |
+
$return->data = $result->data;
|
253 |
+
$return->error = false;
|
254 |
+
return $return;
|
255 |
+
}else{
|
256 |
+
$return->error = true;
|
257 |
+
$return->data = $result->data;
|
258 |
+
$return->status = $result->status;
|
259 |
+
return $return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
}
|
261 |
} catch (Exception $e) {
|
262 |
return $e->getMessage();
|
268 |
"Authorization: Bearer MTIzNA==",
|
269 |
"content-type: application/json"
|
270 |
);
|
271 |
+
$url = $this->apiDomain . "/google-ads/conversion-list";
|
272 |
+
$data = [
|
273 |
'merchant_id' => esc_attr($merchant_id),
|
274 |
'customer_id' => esc_attr($customer_id)
|
275 |
];
|
276 |
+
$args = array(
|
277 |
+
'headers' =>$header,
|
278 |
+
'method' => 'POST',
|
279 |
+
'body' => $data
|
280 |
+
);
|
281 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
282 |
+
|
283 |
+
$return = new \stdClass();
|
284 |
+
if($result->status == 200){
|
285 |
+
$return->status = $result->status;
|
286 |
+
$return->data = $result->data;
|
287 |
+
$return->error = false;
|
288 |
+
return $return;
|
289 |
+
}else{
|
290 |
+
$return->error = true;
|
291 |
+
$return->data = $result->data;
|
292 |
+
$return->status = $result->status;
|
293 |
+
return $return;
|
294 |
+
}
|
295 |
} catch (Exception $e) {
|
296 |
return $e->getMessage();
|
297 |
}
|
300 |
* @since 4.1.4
|
301 |
* Get view ID for GA3 reporting API
|
302 |
*/
|
303 |
+
public function get_analytics_viewid_currency($data) {
|
304 |
try {
|
305 |
$header = array(
|
306 |
"Authorization: Bearer MTIzNA==",
|
307 |
"content-type: application/json"
|
308 |
);
|
309 |
+
$url = $this->apiDomain . "/actionable-dashboard/analytics-viewid-currency";
|
310 |
+
$data['access_token']= $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token());
|
311 |
+
$args = array(
|
312 |
+
'headers' =>$header,
|
313 |
+
'method' => 'POST',
|
314 |
+
'body' => $data
|
315 |
+
);
|
316 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
317 |
+
|
318 |
+
$return = new \stdClass();
|
319 |
+
if($result->status == 200){
|
320 |
+
$return->status = $result->status;
|
321 |
+
$return->data = $result->data;
|
322 |
+
$return->error = false;
|
323 |
+
return $return;
|
324 |
+
}else{
|
325 |
+
$return->error = true;
|
326 |
+
$return->data = $result->data;
|
327 |
+
$return->status = $result->status;
|
328 |
+
return $return;
|
329 |
+
}
|
330 |
} catch (Exception $e) {
|
331 |
return $e->getMessage();
|
332 |
}
|
335 |
* @since 4.1.4
|
336 |
* Get google analytics reports call using reporting API
|
337 |
*/
|
338 |
+
public function get_google_analytics_reports($data) {
|
339 |
try {
|
340 |
+
$url = $this->apiDomain . "/actionable-dashboard/google-analytics-reports";
|
341 |
$header = array(
|
342 |
"Authorization: Bearer MTIzNA==",
|
343 |
"content-type: application/json"
|
345 |
|
346 |
$access_token = $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token());
|
347 |
if($access_token != ""){
|
348 |
+
$data['access_token']= $access_token;
|
349 |
+
$args = array(
|
350 |
+
'headers' =>$header,
|
351 |
+
'method' => 'POST',
|
352 |
+
'body' => $data
|
353 |
+
);
|
354 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
355 |
+
//print_r($result);
|
356 |
+
$return = new \stdClass();
|
357 |
+
if($result->status == 200){
|
358 |
+
$return->status = $result->status;
|
359 |
+
$return->data = $result->data;
|
360 |
+
$return->error = false;
|
361 |
+
return $return;
|
362 |
+
}else{
|
363 |
+
$return->error = true;
|
364 |
+
$return->data = $result->data;
|
365 |
+
$return->status = $result->status;
|
366 |
+
return $return;
|
367 |
+
}
|
368 |
}else{
|
369 |
$return = new \stdClass();
|
370 |
$return->error = true;
|
375 |
return $e->getMessage();
|
376 |
}
|
377 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
|
379 |
public function setGmcCategoryMapping($postData) {
|
380 |
try {
|
452 |
}
|
453 |
public function products_sync($data) {
|
454 |
try {
|
455 |
+
$url = $this->apiDomain . "/products/batch";
|
456 |
+
$args = array(
|
457 |
+
'timeout' => 10000,
|
458 |
+
'headers' => array(
|
459 |
+
'Authorization' => "Bearer MTIzNA==",
|
460 |
+
'Content-Type' => 'application/json',
|
461 |
+
'AccessToken' => $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
462 |
+
),
|
463 |
+
'body' => wp_json_encode($data)
|
464 |
);
|
465 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
466 |
+
|
467 |
+
// Retrieve information
|
468 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
469 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
470 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
$return = new \stdClass();
|
472 |
if (isset($response->error) && $response->error == '') {
|
473 |
+
$return->error = false;
|
474 |
+
$return->products_sync = count($response->data->entries);
|
475 |
+
return $return;
|
476 |
}else{
|
477 |
+
$return->error = true;
|
478 |
+
foreach($response->errors as $err){
|
479 |
+
$return->message = $err;
|
480 |
+
break;
|
481 |
+
}
|
482 |
+
return $return;
|
483 |
}
|
484 |
} catch (Exception $e) {
|
485 |
return $e->getMessage();
|
486 |
}
|
487 |
}
|
488 |
public function getSyncProductList($postData) {
|
489 |
+
try {
|
490 |
+
$url = $this->apiDomain . "/products/list";
|
491 |
+
$postData["maxResults"] = 25;
|
492 |
+
$args = array(
|
493 |
+
'timeout' => 10000,
|
494 |
+
'headers' => array(
|
495 |
+
'Authorization' => "Bearer MTIzNA==",
|
496 |
+
'Content-Type' => 'application/json',
|
497 |
+
'AccessToken' => $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
498 |
+
),
|
499 |
+
'body' => wp_json_encode($postData)
|
500 |
+
);
|
501 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
502 |
+
|
503 |
+
// Retrieve information
|
504 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
505 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
506 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
507 |
+
|
508 |
+
$return = new \stdClass();
|
509 |
+
if (isset($response->error) && $response->error == '') {
|
510 |
+
$return->status = $response_code;
|
511 |
+
$return->error = false;
|
512 |
+
$return->data = $response->data;
|
513 |
+
$return->message = $response->message;
|
514 |
+
return $return;
|
515 |
+
}else{
|
516 |
+
$return->status = $response_code;
|
517 |
+
$return->error = true;
|
518 |
+
foreach($response->errors as $err){
|
519 |
+
$return->message = $err;
|
520 |
+
break;
|
521 |
+
}
|
522 |
+
return $return;
|
|
|
|
|
|
|
523 |
}
|
524 |
+
|
525 |
+
} catch (Exception $e) {
|
526 |
+
return $e->getMessage();
|
527 |
+
}
|
528 |
}
|
529 |
|
530 |
|
531 |
public function getCampaignCurrencySymbol($postData) {
|
532 |
+
try {
|
533 |
+
$url = $this->apiDomain . '/campaigns/currency-symbol';
|
534 |
+
|
535 |
+
$args = array(
|
536 |
+
'headers' => array(
|
537 |
+
'Authorization' => "Bearer $this->token",
|
538 |
+
'Content-Type' => 'application/json'
|
539 |
+
),
|
540 |
+
'body' => wp_json_encode($postData)
|
541 |
+
);
|
542 |
+
|
543 |
+
// Send remote request
|
544 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
545 |
+
|
546 |
+
// Retrieve information
|
547 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
548 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
549 |
+
$response_body = json_decode(wp_remote_retrieve_body($request));
|
550 |
+
if ((isset($response_body->error) && $response_body->error == '')) {
|
551 |
+
|
552 |
+
return new WP_REST_Response(
|
553 |
+
array(
|
554 |
+
'status' => $response_code,
|
555 |
+
'message' => $response_message,
|
556 |
+
'data' => $response_body->data
|
557 |
+
)
|
558 |
+
);
|
559 |
+
} else {
|
560 |
+
return new WP_Error($response_code, $response_message, $response_body);
|
561 |
+
}
|
562 |
+
} catch (Exception $e) {
|
563 |
+
return $e->getMessage();
|
564 |
+
}
|
565 |
}
|
566 |
|
567 |
+
public function generateAccessToken($access_token, $refresh_token) {
|
568 |
+
$url = "https://www.googleapis.com/oauth2/v1/tokeninfo?=" . $access_token;
|
569 |
+
$request = wp_remote_get(esc_url_raw($url), array("access_token"=>$access_token));
|
570 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
571 |
+
|
572 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
573 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
574 |
+
|
575 |
+
if (isset($result->error) && $result->error) {
|
576 |
+
$credentials = json_decode(file_get_contents(ENHANCAD_PLUGIN_DIR . 'includes/setup/json/client-secrets.json'), true);
|
577 |
+
$url = 'https://www.googleapis.com/oauth2/v4/token';
|
578 |
+
$header = array("content-type: application/json");
|
579 |
+
$clientId = $credentials['web']['client_id'];
|
580 |
+
$clientSecret = $credentials['web']['client_secret'];
|
581 |
+
|
582 |
+
$data = [
|
583 |
+
"grant_type" => 'refresh_token',
|
584 |
+
"client_id" => esc_attr($clientId),
|
585 |
+
'client_secret' => esc_attr($clientSecret),
|
586 |
+
'refresh_token' => esc_attr($refresh_token),
|
587 |
+
];
|
588 |
+
$args = array(
|
589 |
+
'headers' =>$header,
|
590 |
+
'method' => 'POST',
|
591 |
+
'body' => $data
|
592 |
+
);
|
593 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
594 |
+
// Retrieve information
|
595 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
596 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
597 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
598 |
+
if(isset($response->access_token)){
|
599 |
+
return $response->access_token;
|
600 |
+
}else{
|
601 |
+
//return $access_token;
|
602 |
+
}
|
|
|
|
|
|
|
|
|
603 |
} else {
|
604 |
return $access_token;
|
605 |
}
|
606 |
+
}//generateAccessToken
|
607 |
|
608 |
public function siteVerificationToken($postData) {
|
609 |
+
try {
|
610 |
+
$url = $this->apiDomain . '/gmc/site-verification-token';
|
611 |
+
$header = array("Authorization: Bearer MTIzNA==",
|
612 |
+
"content-type: application/json",
|
613 |
+
"AccessToken:" . $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
614 |
+
);
|
615 |
+
|
616 |
+
$data = [
|
617 |
+
'merchant_id' => esc_attr($postData['merchant_id']),
|
618 |
+
'website' => esc_url_raw($postData['website_url']),
|
619 |
+
'account_id' => esc_attr($postData['account_id']),
|
620 |
+
'method' => esc_attr($postData['method'])
|
621 |
+
];
|
622 |
+
|
623 |
+
$args = array(
|
624 |
+
'headers' =>$header,
|
625 |
+
'method' => 'POST',
|
626 |
+
'body' => $data
|
627 |
+
);
|
628 |
+
$result = $this->tc_wp_remot_call_post(esc_url_raw($url), $args);
|
629 |
+
|
630 |
+
$return = new \stdClass();
|
631 |
+
if($result->status == 200){
|
632 |
+
$return->status = $result->status;
|
633 |
+
$return->data = $result->data;
|
634 |
+
$return->error = false;
|
635 |
+
return $return;
|
636 |
+
}else{
|
637 |
+
$return->error = true;
|
638 |
+
$return->data = $result->data;
|
639 |
+
$return->status = $result->status;
|
640 |
+
return $return;
|
641 |
+
}
|
642 |
+
} catch (Exception $e) {
|
643 |
+
return $e->getMessage();
|
644 |
+
}
|
645 |
}
|
646 |
|
647 |
public function siteVerification($postData) {
|
648 |
try {
|
649 |
$url = $this->apiDomain . '/gmc/site-verification';
|
650 |
+
$header = array("Authorization: Bearer MTIzNA==",
|
651 |
"content-type: application/json",
|
652 |
"AccessToken:" . $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
653 |
);
|
660 |
'method' => esc_attr($postData['method'])
|
661 |
];
|
662 |
|
663 |
+
$args = array(
|
664 |
+
'headers' =>$header,
|
665 |
+
'method' => 'POST',
|
666 |
+
'body' => $data
|
667 |
+
);
|
668 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
669 |
+
// Retrieve information
|
670 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
671 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
672 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
673 |
+
|
674 |
+
|
675 |
+
$return = new \stdClass();
|
676 |
+
if ((isset($result->error) && $result->error == '')) {
|
677 |
+
|
678 |
+
$return->data = $result->data;
|
679 |
+
$return->error = false;
|
680 |
+
return $return;
|
681 |
+
}else{
|
682 |
+
$return->error = true;
|
683 |
+
$return->errors = $result->errors;
|
684 |
+
|
685 |
+
return $return;
|
686 |
+
}
|
687 |
} catch (Exception $e) {
|
688 |
return $e->getMessage();
|
689 |
}
|
692 |
public function claimWebsite($postData) {
|
693 |
try {
|
694 |
$url = $this->apiDomain . '/gmc/claim-website';
|
695 |
+
$header = array("Authorization: Bearer MTIzNA==",
|
696 |
"content-type: application/json",
|
697 |
"AccessToken:" . $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
|
698 |
);
|
703 |
'access_token' => $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token()),
|
704 |
'subscription_id' => esc_attr($postData['subscription_id']),
|
705 |
];
|
706 |
+
$args = array(
|
707 |
+
'headers' =>$header,
|
708 |
+
'method' => 'POST',
|
709 |
+
'body' => $data
|
710 |
+
);
|
711 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
712 |
+
// Retrieve information
|
713 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
714 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
715 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
716 |
+
|
717 |
|
718 |
+
$return = new \stdClass();
|
719 |
+
if ((isset($result->error) && $result->error == '')) {
|
720 |
+
|
721 |
+
$return->data = $result->data;
|
722 |
+
$return->error = false;
|
723 |
+
return $return;
|
724 |
+
}else{
|
725 |
+
$return->error = true;
|
726 |
+
$return->errors = $result->errors;
|
727 |
+
|
728 |
+
return $return;
|
729 |
+
}
|
|
|
|
|
730 |
} catch (Exception $e) {
|
731 |
return $e->getMessage();
|
732 |
}
|
includes/setup/ShoppingApi.php
CHANGED
@@ -157,7 +157,7 @@ class ShoppingApi {
|
|
157 |
$days_diff = strtotime($to_date) - strtotime($from_date);
|
158 |
$days_diff = abs(round($days_diff / 86400));
|
159 |
}
|
160 |
-
$
|
161 |
$data = [
|
162 |
'customer_id' => sanitize_text_field($this->customerId),
|
163 |
'graph_type' => sanitize_text_field(($date_range_type == 2 && $days_diff > 61) ? 'month' : 'day'),
|
@@ -171,26 +171,38 @@ class ShoppingApi {
|
|
171 |
"Authorization: Bearer $this->token",
|
172 |
"content-type: application/json"
|
173 |
);
|
174 |
-
$
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
$
|
184 |
-
$
|
185 |
-
$
|
186 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
} catch (Exception $e) {
|
188 |
return $e->getMessage();
|
189 |
}
|
190 |
}
|
191 |
public function campaign_performance($date_range_type, $days = 0, $from_date = '', $to_date = '') {
|
192 |
try {
|
193 |
-
$
|
194 |
$days_diff = 0;
|
195 |
if ($date_range_type == 2) {
|
196 |
$days_diff = strtotime($to_date) - strtotime($from_date);
|
@@ -208,19 +220,31 @@ class ShoppingApi {
|
|
208 |
"Authorization: Bearer $this->token",
|
209 |
"content-type: application/json"
|
210 |
);
|
211 |
-
$
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
$
|
221 |
-
$
|
222 |
-
|
223 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
} catch (Exception $e) {
|
225 |
return $e->getMessage();
|
226 |
}
|
@@ -428,17 +452,18 @@ class ShoppingApi {
|
|
428 |
'filter_by' => 'category',
|
429 |
'filter_data' => ["id" => sanitize_text_field($category_id), "level" => sanitize_text_field($category_level)]
|
430 |
];
|
431 |
-
|
432 |
-
$
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
)
|
440 |
-
$
|
441 |
-
$response = json_decode($
|
|
|
442 |
$return = new \stdClass();
|
443 |
if (isset($response->error) && $response->error == false) {
|
444 |
$return->error = false;
|
@@ -477,19 +502,16 @@ class ShoppingApi {
|
|
477 |
'filter_by' => 'category',
|
478 |
'filter_data' => ["id" => sanitize_text_field($category_id), "level" => sanitize_text_field($category_level)]
|
479 |
];
|
480 |
-
$postData = json_encode($data);
|
481 |
-
$ch = curl_init();
|
482 |
-
curl_setopt_array($ch, array(
|
483 |
-
CURLOPT_URL => esc_url_raw($curl_url),
|
484 |
-
CURLOPT_CUSTOMREQUEST => 'PATCH',
|
485 |
-
CURLOPT_RETURNTRANSFER => true,
|
486 |
-
CURLOPT_TIMEOUT => 1000,
|
487 |
-
CURLOPT_HTTPHEADER => $header,
|
488 |
-
CURLOPT_POSTFIELDS => $postData
|
489 |
-
));
|
490 |
-
$response = curl_exec($ch);
|
491 |
-
$response = json_decode($response);
|
492 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
$return = new \stdClass();
|
494 |
if (isset($response->error) && $response->error == false) {
|
495 |
$return->error = false;
|
157 |
$days_diff = strtotime($to_date) - strtotime($from_date);
|
158 |
$days_diff = abs(round($days_diff / 86400));
|
159 |
}
|
160 |
+
$url = $this->apiDomain . '/reports/account-performance';
|
161 |
$data = [
|
162 |
'customer_id' => sanitize_text_field($this->customerId),
|
163 |
'graph_type' => sanitize_text_field(($date_range_type == 2 && $days_diff > 61) ? 'month' : 'day'),
|
171 |
"Authorization: Bearer $this->token",
|
172 |
"content-type: application/json"
|
173 |
);
|
174 |
+
$args = array(
|
175 |
+
'headers' =>$header,
|
176 |
+
'method' => 'POST',
|
177 |
+
'body' => $data
|
178 |
+
);
|
179 |
+
// Send remote request
|
180 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
181 |
+
|
182 |
+
// Retrieve information
|
183 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
184 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
185 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
186 |
+
$return = new \stdClass();
|
187 |
+
if ((isset($result->error) && $result->error == '')) {
|
188 |
+
$return->data = $result->data;
|
189 |
+
$return->data->graph_type = $data['graph_type'];
|
190 |
+
$return->error = false;
|
191 |
+
return $return;
|
192 |
+
}else{
|
193 |
+
$return->error = true;
|
194 |
+
$return->data = $result->data;
|
195 |
+
$return->status = $result->status;
|
196 |
+
return $return;
|
197 |
+
}
|
198 |
+
|
199 |
} catch (Exception $e) {
|
200 |
return $e->getMessage();
|
201 |
}
|
202 |
}
|
203 |
public function campaign_performance($date_range_type, $days = 0, $from_date = '', $to_date = '') {
|
204 |
try {
|
205 |
+
$url = $this->apiDomain . '/reports/campaign-performance';
|
206 |
$days_diff = 0;
|
207 |
if ($date_range_type == 2) {
|
208 |
$days_diff = strtotime($to_date) - strtotime($from_date);
|
220 |
"Authorization: Bearer $this->token",
|
221 |
"content-type: application/json"
|
222 |
);
|
223 |
+
$args = array(
|
224 |
+
'headers' =>$header,
|
225 |
+
'method' => 'POST',
|
226 |
+
'body' => $data
|
227 |
+
);
|
228 |
+
// Send remote request
|
229 |
+
$request = wp_remote_post(esc_url_raw($url), $args);
|
230 |
+
|
231 |
+
// Retrieve information
|
232 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
233 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
234 |
+
$result = json_decode(wp_remote_retrieve_body($request));
|
235 |
+
$return = new \stdClass();
|
236 |
+
if ((isset($result->error) && $result->error == '')) {
|
237 |
+
$return->data = $result->data;
|
238 |
+
//$return->data->graph_type = isset($data['graph_type'])?$data['graph_type']:"";
|
239 |
+
$return->error = false;
|
240 |
+
return $return;
|
241 |
+
}else{
|
242 |
+
$return->error = true;
|
243 |
+
$return->data = $result->data;
|
244 |
+
$return->status = $result->status;
|
245 |
+
return $return;
|
246 |
+
}
|
247 |
+
|
248 |
} catch (Exception $e) {
|
249 |
return $e->getMessage();
|
250 |
}
|
452 |
'filter_by' => 'category',
|
453 |
'filter_data' => ["id" => sanitize_text_field($category_id), "level" => sanitize_text_field($category_level)]
|
454 |
];
|
455 |
+
|
456 |
+
$args = array(
|
457 |
+
'headers' =>$header,
|
458 |
+
'method' => 'POST',
|
459 |
+
'body' => $data
|
460 |
+
);
|
461 |
+
$request = wp_remote_post(esc_url_raw($curl_url), $args);
|
462 |
+
|
463 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
464 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
465 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
466 |
+
|
467 |
$return = new \stdClass();
|
468 |
if (isset($response->error) && $response->error == false) {
|
469 |
$return->error = false;
|
502 |
'filter_by' => 'category',
|
503 |
'filter_data' => ["id" => sanitize_text_field($category_id), "level" => sanitize_text_field($category_level)]
|
504 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
505 |
|
506 |
+
$args = array(
|
507 |
+
'headers' =>$header,
|
508 |
+
'method' => 'PATCH',
|
509 |
+
'body' => $data
|
510 |
+
);
|
511 |
+
$request = wp_remote_post(esc_url_raw($curl_url), $args);
|
512 |
+
$response_code = wp_remote_retrieve_response_code($request);
|
513 |
+
$response_message = wp_remote_retrieve_response_message($request);
|
514 |
+
$response = json_decode(wp_remote_retrieve_body($request));
|
515 |
$return = new \stdClass();
|
516 |
if (isset($response->error) && $response->error == false) {
|
517 |
$return->error = false;
|
includes/setup/help-html.php
CHANGED
@@ -28,31 +28,33 @@ function info_htnml($validation){
|
|
28 |
}
|
29 |
}
|
30 |
function get_google_shopping_tabs_html($site_url, $google_merchant_center_id){
|
31 |
-
$site_url_p = (isset($google_merchant_center_id) && $google_merchant_center_id != '')?$site_url:"
|
32 |
$site_url_p_target ="";
|
33 |
if(isset($google_merchant_center_id) && esc_attr($google_merchant_center_id) == ''){
|
34 |
$site_url_p_target = 'data-toggle="modal" data-target="#tvc_google_connect"';
|
35 |
}
|
36 |
$tab = (isset($_GET['tab']) && sanitize_text_field($_GET['tab']))?sanitize_text_field($_GET['tab']):"";
|
37 |
$TVC_Admin_Helper = new TVC_Admin_Helper();
|
38 |
-
|
39 |
-
|
40 |
<li class="nav-item" role="presentation">
|
41 |
-
<div class="tvc-tooltip nav-link
|
42 |
-
<a href="
|
43 |
</div>
|
44 |
</li>
|
45 |
<li class="nav-item" role="presentation">
|
46 |
-
<div class="tvc-tooltip nav-link
|
47 |
-
<a href="
|
48 |
</div>
|
49 |
</li>
|
50 |
<li class="nav-item" role="presentation">
|
51 |
-
<div class="tvc-tooltip nav-link
|
52 |
-
<a href="
|
53 |
</div>
|
54 |
</li>
|
55 |
-
</ul>
|
|
|
|
|
56 |
}
|
57 |
function get_tvc_google_ads_help_html(){
|
58 |
$TVC_Admin_Helper = new TVC_Admin_Helper();
|
28 |
}
|
29 |
}
|
30 |
function get_google_shopping_tabs_html($site_url, $google_merchant_center_id){
|
31 |
+
$site_url_p = (isset($google_merchant_center_id) && $google_merchant_center_id != '')?$site_url:"";
|
32 |
$site_url_p_target ="";
|
33 |
if(isset($google_merchant_center_id) && esc_attr($google_merchant_center_id) == ''){
|
34 |
$site_url_p_target = 'data-toggle="modal" data-target="#tvc_google_connect"';
|
35 |
}
|
36 |
$tab = (isset($_GET['tab']) && sanitize_text_field($_GET['tab']))?sanitize_text_field($_GET['tab']):"";
|
37 |
$TVC_Admin_Helper = new TVC_Admin_Helper();
|
38 |
+
ob_start();
|
39 |
+
?><ul class="nav nav-tabs nav-justified edit-tabs" id="myTab" role="tablist">
|
40 |
<li class="nav-item" role="presentation">
|
41 |
+
<div class="tvc-tooltip nav-link <?php echo esc_attr(($tab=="gaa_config_page")?"active":""); ?>">
|
42 |
+
<a href="<?php echo esc_url_raw($site_url.'gaa_config_page'); ?>" id="smart-shopping-campaigns"><?php echo esc_html__("Configuration", "conversios" ); ?></a>
|
43 |
</div>
|
44 |
</li>
|
45 |
<li class="nav-item" role="presentation">
|
46 |
+
<div class="tvc-tooltip nav-link <?php echo esc_attr(($tab=="sync_product_page")?"active":""); ?>" <?php echo esc_attr($site_url_p_target); ?>>
|
47 |
+
<a href="<?php echo ($site_url_p)?esc_url_raw($site_url_p.'sync_product_page'):"#"; ?>" id="smart-shopping-campaigns"><?php echo esc_html__("Product Sync", "conversios" ); ?></a>
|
48 |
</div>
|
49 |
</li>
|
50 |
<li class="nav-item" role="presentation">
|
51 |
+
<div class="tvc-tooltip nav-link <?php echo esc_attr(($tab=="shopping_campaigns_page")?"active":""); ?>" <?php echo esc_attr($site_url_p_target); ?>>
|
52 |
+
<a href="<?php echo ($site_url_p)?esc_url_raw($site_url_p . 'shopping_campaigns_page'):"#"; ?>" id="smart-shopping-campaigns"><?php echo esc_html__("Smart Shopping Campaigns", "conversios" ); ?></a>
|
53 |
</div>
|
54 |
</li>
|
55 |
+
</ul>
|
56 |
+
<?php
|
57 |
+
return ob_get_clean();
|
58 |
}
|
59 |
function get_tvc_google_ads_help_html(){
|
60 |
$TVC_Admin_Helper = new TVC_Admin_Helper();
|
readme.txt
CHANGED
@@ -8,8 +8,8 @@ Author: Tatvic
|
|
8 |
Requires at least: 3.0.0
|
9 |
Tested up to: 5.8.2
|
10 |
Requires PHP: 5.6 or Higher
|
11 |
-
Stable tag: 4.5.
|
12 |
-
Version: 4.5.
|
13 |
License: GPLv3
|
14 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
15 |
|
@@ -380,6 +380,10 @@ You can resolve the duplication of data by removing the manually implemented GA
|
|
380 |
|
381 |
== Changelog ==
|
382 |
|
|
|
|
|
|
|
|
|
383 |
= 4.5.5 - 27/12/2021 =
|
384 |
|
385 |
* Some users were facing PHP warning issue. The issue is now fixed.
|
8 |
Requires at least: 3.0.0
|
9 |
Tested up to: 5.8.2
|
10 |
Requires PHP: 5.6 or Higher
|
11 |
+
Stable tag: 4.5.6
|
12 |
+
Version: 4.5.6
|
13 |
License: GPLv3
|
14 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
15 |
|
380 |
|
381 |
== Changelog ==
|
382 |
|
383 |
+
= 4.5.6 - 28/12/2021 =
|
384 |
+
|
385 |
+
* In this release, we have optimization code.
|
386 |
+
|
387 |
= 4.5.5 - 27/12/2021 =
|
388 |
|
389 |
* Some users were facing PHP warning issue. The issue is now fixed.
|