PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.3.14
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.3.14
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / admin / includes / Actions / Sync / ZohoCRMSync.php
commercebird / admin / includes / Actions / Sync Last commit date
ExactOnlineSync.php 11 months ago ZohoCRMSync.php 1 year ago index.php 1 year ago
ZohoCRMSync.php
77 lines
1 <?php
2
3 namespace CommerceBird\Admin\Actions\Sync;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use CMBIRD_API_Handler_Zoho;
10 use CMBIRD_Auth_Zoho;
11 use WP_Error;
12
13 class ZohoCRMSync {
14
15 /* create API Get call to Zoho CRM to get all custom fields
16 *
17 * @param module $module - module name
18 * @return array | \WP_Error
19 */
20 public static function get_custom_fields( $module ) {
21 $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' );
22 $url = $zoho_crm_url . 'crm/v7/settings/fields?module=' . $module;
23 $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho();
24 $json = $execute_curl_call_handle->execute_curl_call_get( $url );
25 if ( is_wp_error( $json ) ) {
26 return $json;
27 } else {
28 // Parse the response
29 $parsed_fields = array();
30
31 foreach ( $json->fields as $field ) {
32 if (
33 ! empty( $field->custom_field ) &&
34 ( empty( $field->read_only ) || $field->read_only === false )
35 ) {
36 $parsed_fields[] = [
37 'id' => $field->id,
38 'apiName' => $field->api_name,
39 'visible' => (bool) $field->visible,
40 'fieldLabel' => $field->field_label,
41 'displayLabel' => $field->display_label,
42 'customField' => true,
43 'dataType' => $field->data_type,
44 ];
45 }
46 }
47
48 return $parsed_fields;
49 }
50 }
51
52 /**
53 * Refresh the access token of Zoho CRM.
54 * @since 1.0.0
55 * @return void | \WP_Error
56 */
57 public static function refresh_token() {
58 // return if there is no access token
59 if ( empty( get_option( 'cmbird_zoho_crm_access_token' ) ) ) {
60 return;
61 }
62 $zoho_refresh_token = get_option( 'cmbird_zoho_crm_refresh_token' );
63 $zoho_timestamp = get_option( 'cmbird_zoho_crm_timestamp' );
64 $current_time = strtotime( gmdate( 'Y-m-d H:i:s' ) );
65 if ( $zoho_timestamp < $current_time ) {
66 $handlefunction = new CMBIRD_Auth_Zoho();
67 $respo_at_js = $handlefunction->get_zoho_refresh_token( $zoho_refresh_token, 'zoho_crm' );
68 if ( empty( $respo_at_js ) || ! array_key_exists( 'access_token', $respo_at_js ) ) {
69 return new WP_Error( 403, 'Access denied!' );
70 } else {
71 update_option( 'cmbird_zoho_crm_access_token', $respo_at_js['access_token'] );
72 update_option( 'cmbird_zoho_crm_timestamp', strtotime( gmdate( 'Y-m-d H:i:s' ) ) + $respo_at_js['expires_in'] );
73 }
74 }
75 }
76 }
77