Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kerkness committed Sep 22, 2022
1 parent aedc5ca commit b3a8f51
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/WCHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ public static function createOrUpdateHubspot(WP_User $user)
// Call the HubSpot API
$response = $contacts->createOrUpdate($properties, 'email');

moi_debug("Create or Update response");
moi_debug($response);

// If Successful call action with HubSpot ID and WP_User object
if ($response->data && $response->data->vid) {
do_action('wc_hub_hubspot_contact_updated', $response->data->vid, $user);
Expand Down Expand Up @@ -146,9 +143,6 @@ public static function getHubSpotContact(WP_User $user)

$parameters = apply_filters( 'wc_hub_hubspot_get_contact_parameters', $default_params );

moi_debug("We want to get these parameters");
moi_debug($parameters);

//
$contact = $contacts->where('email', 'EQ', $user->user_email)->first();
$properties = $contact ? $contact->getProperties() : [];
Expand All @@ -158,9 +152,6 @@ public static function getHubSpotContact(WP_User $user)

// Now fetch list memberships...

moi_debug("Loaded user .. did we");
moi_debug($user);

return [
'user' => $user,
];
Expand All @@ -170,14 +161,20 @@ public static function getHubSpotContact(WP_User $user)
* Update HubSpot contact with specific properties
* @see https://legacydocs.hubspot.com/docs/methods/contacts/update_contact-by-email
*/
public static function updateHubSpotContact($email, $properties)
public static function updateHubSpotContact($email, $params)
{
// Create HubSpot Client
$hub = Hub::create(get_option('wc_hub_hubspot_access_token'));
$hub = HubSpotClientHelper::createFactory(get_option('wc_hub_hubspot_access_token'));
$contacts = HubContacts::factory($hub);

$contact = $contacts->where('email', 'EQ', $email)->first();
$properties = $contact ? $contact->getProperties() : [];

// return $properties;
if(!$properties['hs_object_id']) {
return false;
}

$response = $hub->contacts()->updateByEmail($email, $properties);
$response = $contacts->update($properties['hs_object_id'], $params);

$user = get_user_by( 'email', $email );
do_action('wc_hub_hubspot_contact_updated', '', $user);
Expand Down

0 comments on commit b3a8f51

Please sign in to comment.