PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.3.10
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.3.10
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 / includes / classes / zoho-crm / class-zcrm-modules.php
commercebird / includes / classes / zoho-crm Last commit date
class-zcrm-contact.php 1 year ago class-zcrm-modules.php 1 year ago class-zcrm-salesorder.php 1 year ago index.php 1 year ago
class-zcrm-modules.php
111 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class CMBIRD_ZCRM_Modules {
8
9 /**
10 * create API Get call to Zoho CRM to get all custom fields
11 *
12 * @param module $module - module name
13 * @return array | \WP_Error
14 */
15 public function cmbird_get_module( $module ) {
16 $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' );
17 $url = $zoho_crm_url . 'crm/v7/settings/fields?module=' . $module;
18 $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho();
19 $json = $execute_curl_call_handle->execute_curl_call_get( $url );
20 if ( is_wp_error( $json ) ) {
21 return $json;
22 } else {
23 // Parse the response
24 $parsed_fields = array();
25
26 foreach ( $json->fields as $field ) {
27 $parsed_fields[] = array(
28 'id' => $field->id,
29 'apiName' => $field->api_name,
30 'visible' => (bool) $field->visible,
31 'fieldLabel' => $field->field_label,
32 'displayLabel' => $field->display_label,
33 'customField' => (bool) $field->custom_field,
34 'dataType' => $field->data_type,
35 );
36 }
37
38 return $parsed_fields;
39 }
40 }
41
42 /**
43 * create API Get call to Zoho CRM to get a record of a module
44 *
45 * @param module $module - module name
46 * @param record_id $record_id - record id
47 * @return array | \WP_Error
48 */
49 public function cmbird_get_record( $module, $record_id ) {
50 $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' );
51 $url = $zoho_crm_url . 'crm/v7/' . $module . '/' . $record_id;
52 $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho();
53 $json = $execute_curl_call_handle->execute_curl_call_get( $url );
54 if ( is_wp_error( $json ) ) {
55 return $json;
56 } else {
57 return $json;
58 }
59 }
60
61 /**
62 * create API Get call to Zoho CRM to create a record of a module
63 *
64 * @param string $module - module name
65 * @param array $data - data to be created
66 * @return array | \WP_Error
67 */
68 public function cmbird_create_record( $module, $data ) {
69 $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' );
70 $url = $zoho_crm_url . 'crm/v7/' . $module;
71 $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho();
72 // convert the data to JSON format
73 if ( is_array( $data ) ) {
74 $data = json_encode( $data );
75 }
76 if ( ! $data ) {
77 return new \WP_Error( 'cmbird_no_data', __( 'No data provided for creating record.', 'cmbird' ) );
78 }
79 $json = $execute_curl_call_handle->execute_curl_call_post( $url, $data );
80 if (! isset( $json->data[0]->code ) || 'SUCCESS' !== $json->data[0]->code ) {
81 return new \WP_Error( '500', __( $json->data[0]->message, 'cmbird' ), array( 'status' => 500 ) );
82 }
83 return $json;
84 }
85
86 /**
87 * create API Get call to Zoho CRM to update a record of a module
88 *
89 * @param string $module - module name
90 * @param string $record_id - record id
91 * @param array $data - data to be updated
92 * @return array | \WP_Error
93 */
94 public function cmbird_update_record( $module, $record_id, $data ) {
95 $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' );
96 $url = $zoho_crm_url . 'crm/v7/' . $module . '/' . $record_id;
97 $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho();
98 // convert the data to JSON format
99 if ( is_array( $data ) ) {
100 $data = json_encode( $data );
101 }
102 $json = $execute_curl_call_handle->execute_curl_call_put( $url, $data );
103 // response has data in the format of {"data":[{"code":"SUCCESS","details":{}}],"info":{"per_page":200,"count":1,"page":1}}
104 // if code is not SUCCESS, return error
105 if ( ! isset( $json->data[0]->code ) || 'SUCCESS' !== $json->data[0]->code ) {
106 return new \WP_Error( '500', __( $json->data[0]->message, 'cmbird' ), array( 'status' => 500 ) );
107 }
108 return $json;
109 }
110 }
111