Skip to content

Commit

Permalink
Merge pull request #7 from kerkness/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
kerkness authored Sep 22, 2022
2 parents 9144be8 + efc4990 commit fc96761
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 103 deletions.
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If installing from git or composer run `composer install` before activating.

### Setup

Add your HubSpot API Key in `Settings > WCHub`
Add your HubSpot Private App Access Token in `Settings > WCHub`

### Usage

Expand All @@ -24,19 +24,16 @@ To manually update a Hubspot Contact use the function `wc_hub_update_hubspot_con
$wc_hub_contact_id = wc_hub_create_or_update_hubspot_contact( $user );
// Get an existing WCHub Contact record for current user
// @see https://developers.hubspot.com/docs/methods/contacts/get_contact_by_email
$contact = wc_hub_get_current_contact();
// Get an existing WCHub Contact from a WP_User object
// @see https://developers.hubspot.com/docs/methods/contacts/get_contact_by_email
$contact = wc_hub_get_hubspot_contact( $user );
// Update an existing wc-hub contact
// @see https://legacydocs.hubspot.com/docs/methods/contacts/update_contact-by-email
$properties = [
['property' => 'firstname', 'value' => 'Sam'],
['property' => 'lastname', 'value' => 'Iam'],
['property' => 'custom_property', 'value' => 'custom value']
['firstname' => 'Sam'],
['lastname' => 'Iam'],
['custom_property' => 'custom value']
]
wc_hub_update_hubspot_contact( $current_user->user_email, $properties);
```
Expand All @@ -60,9 +57,8 @@ add_filter( 'wc_hub_hubspot_contact_properties', 'handle_hubspot_contact_props_f
function handle_hubspot_contact_props_filter( $properties, $user ) {
$properties[] = [
'property' => 'wordpress_username',
'value' => $user->user_login
$properties = [
'property_name' => 'property_value',
];
return $properties;
Expand All @@ -72,13 +68,12 @@ function handle_hubspot_contact_props_filter( $properties, $user ) {

```
// Modify what HubSpot Contact Properties are returned use the `wc_hub_hubspot_get_contact_parameters` filter.
// See https://developers.hubspot.com/docs/methods/contacts/get_contact_by_email for more details.
add_filter( 'wc_hub_hubspot_get_contact_parameters', 'handle_wc_hub_hubspot_get_contact_parameters', 10, 1 );
function handle_wc_hub_hubspot_get_contact_parameters( $parameters ) {
$parameters = ['showListMemberships' => 1, 'property' => 'lastname'];
return $parameters;
return array_merge($parameters, [
'custom_property_key1',
'custom_property_key2',
]);
}
```
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
"require": {
"php": ">=7.1.0",
"composer/installers": "v1.0.6",
"hubspot/hubspot-php": "^3.1"
"hubspot/api-client": "^8.3"
},
"autoload" : {
"psr-4" : {
"WCHub\\" : "src"
}
},
"config": {
"vendor-dir": "lib"
"vendor-dir": "lib",
"allow-plugins": {
"composer/installers": true
}
}
}

57 changes: 31 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: Kerkness
Tags: hubspot, crm, woocommerce, customers
Requires at least: 5.4
Tested up to: 5.8
Stable tag: 1.0.4
Tested up to: 6.0.2
Stable tag: 1.1.0
Requires PHP: 7.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -38,6 +38,9 @@ Yes. The plugin loads your complete HubSpot contact record and makes all propert

== Changelog ==

= 1.1.0 =
* upgraded to use HubSpot V3 SDK and Private APP Token authentication. Requires the creation of a HubSpot private app.

= 1.0.4 =
* updating stable tag

Expand Down
12 changes: 6 additions & 6 deletions src/Admin/WCHubOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function wc_hub_activation_hook()
*/
public function wc_hub_deactivation_hook()
{
delete_option( 'wc_hub_hubspot_api_key' );
delete_site_option('wc_hub_hubspot_api_key');
delete_option( 'wc_hub_hubspot_access_token' );
delete_site_option('wc_hub_hubspot_access_token');
}

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ public function wc_hub_register_settings()
{
register_setting(
'wc_hub_settings',
'wc_hub_hubspot_api_key',
'wc_hub_hubspot_access_token',
array(
'type' => 'string',
'show_in_rest' => false,
Expand All @@ -112,15 +112,15 @@ public function wc_hub_options_page()
<div class="wrap">
<h1><?php echo __('WCHub Settings', 'wc-hub') ?></h1>

<p><?php echo sprintf(__('To use this plugin you need to <a target="_blank" href="%s">create an HubSpot API key</a> and then enter the key below.', 'wc-hub'), 'https://knowledge.hubspot.com/integrations/how-do-i-get-my-hubspot-api-key') ?></p>
<p><?php echo sprintf(__('To use this plugin you need to create a private app with permissions to read/write contacts and <a target="_blank" href="%s">copy your private app acccess-token</a> and then enter the token below.', 'wc-hub'), 'https://developers.hubspot.com/docs/api/migrate-an-api-key-integration-to-a-private-app') ?></p>

<form method="post" action="options.php">
<?php settings_fields('wc_hub_settings'); ?>
<?php do_settings_sections('wc_hub_settings'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php echo __('HubSpot API Key', 'wc-hub') ?></th>
<td><input type="text" name="wc_hub_hubspot_api_key" value="<?php echo esc_attr(get_option('wc_hub_hubspot_api_key')); ?>" /></td>
<th scope="row"><?php echo __('HubSpot App Access Token', 'wc-hub') ?></th>
<td><input type="text" name="wc_hub_hubspot_access_token" value="<?php echo esc_attr(get_option('wc_hub_hubspot_access_token')); ?>" /></td>
</tr>

</table>
Expand Down
21 changes: 21 additions & 0 deletions src/HubContacts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace WCHub;


class HubContacts
{
use HubObject;

public function basicApi()
{
return $this->client->crm()->contacts()->basicApi();
}

public function searchApi()
{
return $this->client->crm()->contacts()->searchApi();
}


}
Loading

0 comments on commit fc96761

Please sign in to comment.