Jun 05

Integrating Envato Market with Help Scout

Fri, 06/05/2015 - 00:15 — julie

With the new Envato API and Support announcements which have just been released in the last few weeks, I thought I ought to write a post about how I’ve updated my own support system to work with the new changes (previous support post here).

In this post, I’ll be offering two solutions for integrating Envato Market with Help Scout. The first solution is one which I have been using for many months, making use of the old Envato API (which still works, but will likely be retired in the future), and the second solution is one which I wrote only a couple of days ago, to make use of the new Envato API/Support requirements and integrate more heavily with Help Scout.

Both methods use WordPress and Gravity Forms – this tutorial will only work if you’re using WordPress (and the Gravity Forms parts will only work with that plugin, although they shouldn’t be too difficult to change over to Contact Form 7 integrations, for example).

I’d like to point out early on that using either of these methods (in parts or in their entirety) is at your own risk, and I cannot guarantee the security of these solutions or that they will work 100% correctly for you (every server setup is different). If you have any suggestions or improvements you’d like to contribute, please do leave a comment below.

Solution 1 (using the old Envato API)

For this version, I was using Gravity Forms, along with the following two files, available as a GitHub Gist here (feel free to Star it!), and this code works with any kind of email support system – it just uses Gravity Forms to verify an Envato purchase. Once that’s done, it’s up to you what you do with the data.

Step 1

Create two files – functions.php (or add to your existing functions.php file), and envato.api.class.php (this one should be in a subfolder called, ‘envato’).

Step 2

You’ll need to add your own username and API key, and update the functions.php file with your correct input IDs and form IDs from Gravity Forms. You’ll also need to update the API class with your own CURLOPT_USERAGENT.

Step 3

When using this method, I used an add-on which created a new user upon a successful form submission. The user is logged-in, and taken to a second form (same page, but using an if statement in the page template depending on if the user is logged in) where they submit their ticket to me.

So, in actual fact, the Envato API part only happens on creating a user, and if it’s successful, they can then submit a ticket.

Pros & Cons

This method worked well for me for many months, the main pro being that it was simple for users, they only ever had to enter their purchase code once, and they could submit future tickets with ease.

However, the limitations were that once the user had an account created, they could submit tickets for any product of mine, and as I offer support for more than just Envato Market items, they could create an account for a different product type, not have to enter a purchase code, and then submit Envato-type support tickets once logged in.

Thankfully, this was never an issue for me, as I’m a CodeCanyon author selling plugins, and don’t have enough users requiring support for it to be a problem, however it’s something to bare in mind.

Additionally, if someone has bought more than one product from you, only their first purchase code was ever verified, meaning that they could potentially then use their created account to gain support for more than one product, as mentioned earlier.

Solution 2 (using the new Envato API + Gravity Forms Web API + Help Scout API)

This method is much more complicated, will require SSL certificates for it to be done securely, and will require much more modification to make it work well for you. Here, the user doesn’t create an account on your site, but instead has to enter their purchase code for each new support ticket. Whilst this may be annoying for some, for me, it wasn’t an issue as the volume of customers I receive needing support is so small that it wasn’t worth a more complicated system.

Having said that, it wouldn’t be beyond the realms of possibility to rework some of my code and then create a better solution for your own Envato support systems.

Once they’ve successfully submitted their ticket (after the purchase code has been validated, or an error is returned), the purchase code is stored in the Gravity Forms backend, where it can be later called by our script. This means that if a buyer has bought more than one of your products, they can register each purchase code with you (unlike in the first solution).

After this is all done, the final product does the following: the current Help Scout customer’s email address is sent to the script, which checks against the Gravity Forms Web API for entries for a specific form (the Support form) where the email field contains the email from Help Scout. If there are any matches, the purchase code is taken from Gravity Forms, placed into an array and then sent to Envato where the purchase details can be returned, processed, and then displayed in the Help Scout sidebar, showing whether or not the purchase has been verified successfully.

Screen Shot 2015-05-27 at 20.02.35 An example of an Envato customer, with two, unique, verified purchase codes associated with their email address, both of which are valid and their data has been pulled in accordingly (though the buyer names have been obfuscated).

If for some reason the current Help Scout customer has not been through your official support form and has instead emailed the support address directly, they won’t necessarily have any verified purchases on record, so an error is displayed accordingly.

Screen Shot 2015-05-27 at 20.02.53 An example of a user who has no Envato purchase codes associated with their account (as they’re supposedly a non-Envato support customer).

In the future when the new Envato support plans come into place, I’ll update this solution so you’ll be able to easily see (using the different coloured headings and more provided in the Help Scout Style Guide) whether or not a user is entitled to/has purchased support for your item or not, or if their support package has expired, or if they’re a legacy buyer.

Before we begin, you’ll need to have enabled the Gravity Forms API in the backend of your WordPress site. Choose your public and private API keys, making sure they’re nice and secure. I’ll also assume that you have uploaded the Help Scout PHP client library into an src directory on your server in an obscure place (even though the requests to it will need to be authorised) and that you are using the paid version of Help Scout with a new Dynamic App type created (with the URL set to the location of the client library, not the src one, the level above that) and another randomly generated, secret key.

Step 1

With this solution, we just have one form – the Support form. Here, we need to collect the support type (if there’s more than just Envato item support going through this, which in my case, there is), the user’s email address (as Envato doesn’t provide this to us using the standard purchase verification API call), the user’s purchase code, a subject (not necessary, but nice to have), a related URL (again, not always needed, but helpful), and then the main ticket message.

The Support Form - Gravity Forms, Envato and Help Scout API integrations.

Step 2

Using the function created for solution 1, set the form field values etc. as necessary, add your Envato username and API key and also update the user agent (as explained earlier on).

Step 3

Using the code embedded below, replace these values with your own:

  • $envato_user – your Envato username.
  • $envato_token – your Envato token, generated here.
  • $gf_api_key – your Gravity Forms public key.
  • $gf_private_key – your Gravity Forms private key.
  • $gf_route – remove {FORM_ID}, replacing it with your form’s ID.
  • $gf_letsgo – change this to your domain name (and add your WordPress directory, if necessary), and also replace {FORM_ID} as above.
  • if (($entry[8]=="Envato Item Support") && (strtolower($entry[6])==$hs_email)) – change the first entry to your support type’s field ID (or remove if not in use) and make sure the email entry field ID is changed to your own value (note, we must convert email addresses to lower case in our script as Help Scout does this too).
  • $purchase_code = $entry[7] – change this entry value to the field ID of your customer purchase codes.
  • curl_setopt($envato_ch, CURLOPT_USERAGENT, 'YOUR NAME - Help Scout verify') – enter your name or something else here to create your own user agent.
  • $old->setTimezone(new DateTimeZone('Europe/London')) – change this timezone as necessary to convert the Australian date/time values into your own country’s timezone.

The Source Code

Here is the GitHub Gist I’ve created containing the full source code for the script – if you can’t see the embedded code, you can access it here. Please feel free to star the Gist if you’ve found it useful!

Pros & Cons

The advantages to this system will really come when the new support plans are in place, but for now, it’s definitely a nice visual indicator as to whether or not your customers have verified their purchase codes with you. The only downside I would say is that the user must enter their purchase code each time (unless you try using the new OAuth stuff which may work) which could be a pain, but shouldn’t be too much of a big deal, especially if your customers don’t tend to need to open more than one support ticket.

Final Words

So, that’s it! Two working solutions for how you can integrate either Gravity Forms and Envato Market (and then any other support solution offering email ticket creation), or Gravity Forms, Envato Market and Help Scout to display customer purchase verification details in the sidebar of your Help Scout tickets.

By providing this tutorial to the community, I really hope that many people will find the information useful. If you have any questions, please either feel free to leave a comment below or contact me individually. Finally, a big thanks to Justin Scheetz (BoxyStudio) for helping me out with the first solution some months back!

This tutorial was originally published on Sam’s blog here.

The post Integrating Envato Market with Help Scout appeared first on Market Blog.

Copyright 2009. E-mail Me
Auto Spare Parts