class-zcrm-contact.php
1 year ago
class-zcrm-modules.php
1 year ago
class-zcrm-product.php
11 months ago
class-zcrm-salesorder.php
1 year ago
index.php
1 year ago
class-zcrm-contact.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | use CMBIRD_API_Handler_Zoho; |
| 8 | |
| 9 | class CMBIRD_ZCRM_Contact { |
| 10 | |
| 11 | /** |
| 12 | * create API Get call to Zoho CRM to get all contacts |
| 13 | * |
| 14 | * @return array | \WP_Error |
| 15 | */ |
| 16 | public function cmbird_get_contacts() { |
| 17 | $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' ); |
| 18 | $url = $zoho_crm_url . 'crm/v2/Contacts'; |
| 19 | $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho(); |
| 20 | $json = $execute_curl_call_handle->execute_curl_call_get( $url ); |
| 21 | if ( is_wp_error( $json ) ) { |
| 22 | return $json; |
| 23 | } else { |
| 24 | // Parse the response |
| 25 | $parsed_contacts = array(); |
| 26 | |
| 27 | foreach ( $json->data as $contact ) { |
| 28 | $parsed_contacts[] = array( |
| 29 | 'id' => $contact->id, |
| 30 | 'contact_name' => $contact->contact_name, |
| 31 | 'account_name' => $contact->account_name, |
| 32 | 'contact_type' => $contact->contact_type, |
| 33 | 'phone' => $contact->phone, |
| 34 | 'email' => $contact->email, |
| 35 | 'website' => $contact->website, |
| 36 | 'created_time' => $contact->created_time, |
| 37 | 'modified_time' => $contact->modified_time, |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | return $parsed_contacts; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * create API Get call to Zoho CRM to get a contact |
| 47 | * |
| 48 | * @param contact_id $contact_id - contact id |
| 49 | * @return array | \WP_Error |
| 50 | */ |
| 51 | public function cmbird_get_contact( $contact_id ) { |
| 52 | $zoho_crm_url = get_option( 'cmbird_zoho_crm_url' ); |
| 53 | $url = $zoho_crm_url . 'crm/v2/Contacts/' . $contact_id; |
| 54 | $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho(); |
| 55 | $json = $execute_curl_call_handle->execute_curl_call_get( $url ); |
| 56 | if ( is_wp_error( $json ) ) { |
| 57 | return $json; |
| 58 | } else { |
| 59 | // Parse the response |
| 60 | $parsed_contact = array(); |
| 61 | |
| 62 | $parsed_contact = array( |
| 63 | 'id' => $json->data->id, |
| 64 | 'contact_name' => $json->data->contact_name, |
| 65 | 'account_name' => $json->data->account_name, |
| 66 | 'contact_type' => $json->data->contact_type, |
| 67 | 'phone' => $json->data->phone, |
| 68 | 'email' => $json->data->email, |
| 69 | 'website' => $json->data->website, |
| 70 | 'created_time' => $json->data->created_time, |
| 71 | 'modified_time' => $json->data->modified_time, |
| 72 | ); |
| 73 | |
| 74 | return $parsed_contact; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 |