Option to integrate Thrivecart and use an external cart and affiliate system

I was trying to set up affiliate (the plugin) to work with pro-sites, but it doesn’t have most of the capabilities I need.

I want to integrate Thrivecart and use an external cart and affiliate system, can this be done? Do you have integration with Zapier or…. How do I go about this?

Do you have docomtetion for integration?

  • Panos
    • SLS

    Hi there ido !

    I am not familiar with Thrivecart nor is any of my colleagues I asked. I am still waiting for some replies but I doubt that they are familiar.

    I did some research but it seems that it provides a link that you add in your website, then the purchase happens in their environment but there is no return back to your site. I might have been missing many things and could be completely wrong.

    In order to make this work in Pro Sites we need to be able to add some info (level, activation key ec) in the url that is linked to the Thrivecart product. Then, after a successful payment, Thrivecart would need to send some response back to a specified endpoint of the site. That response should confirm that payment was successful and the info that was sent to Thrivecart with the customized link (level, key etc). And this is the simplest form of communication which is not safe at all to use, as the endpoint can be easily compromised. For security, payment gateways use tokens or other payment notifications additionally.

    Could you update us with some technical info, if what mentioned above is possible?

    Kind regards!

    • ido
      • The Incredible Code Injector

      Hey Panos,

      Thanks for your reply,

      I’ve contacted Thrivecart support, thay have seen this ticket and sent this:

      … just as Pro-Sites, myself nor my team is familiar with their platform. However, I think this information will help as they mentioned ‘Hooks’ in their initial response.

      https://support.thrivecart.com/help/using-webhook-notifications/

      So if they support the use of Webhooks then you can use Webhooks to integrate Thrivecart with their platform.

      I hope they find that information helpful.

      So….

      I guss, if you can point me to the pro-sites webhooks that will be great

      Thanks in advance

      Ido

  • Panos
    • SLS

    Hi ido !

    I’m still not sure if it is possible to pass information from the product link on your site to Thrivecart. This is pretty important cause in the HTTP Request sent from Thrivecart to your site, eg for successful payment, the script on the site needs to know which blog it needs to update or what level to assign. If this is not possible then it won’t work for Pro Sites. Unless there is some option for that directly in Thrivecart’s checkout page, but in that case you won’t be needing the Pro Sites checkout page, and need a total custom development on that.

    In general, creating custom gateways is not considered as simple task so, it exceeds the scope of our support and you need to have a developer to work on it and keep in mind seriously about security holes.

    In order to provide some pointers and hooks to use, I have prepared a custom mu-plugin which you can download from here:

    https://gist.github.com/wpmudev-sls/0bb76413634ebb25f8e76e10dff51e56

    In case you need to use custom DB tables, you can use it as a normal plugin too, where you need to add an activation hook to create those tables.

    IMPORTANT NOTE:

    It uses a custom webhook, so in order to make the webhook work you need to flush/resave permalink settings. If you decide to use it as a normal plugin, you can do this too in your activation hook.

    I have added all comments required in the snippet so it should be pretty straightforward what to change there in order to fit your needs.

    I’ll explain here basic parts

    1. It needs to have an id for the gateway set in this line:

    private static $id = 'thrivecart';

    2. All Gateways in Pro Sites need some settings in order to function properly. Settings hooks used in the snippet are in these lines:

    // 1. Add gateway admin tab
    add_filter( 'prosites_gateways_tabs', array( $this, 'settings_tab' ) );
    // 2. Load the content for the Gateway Settings
    add_action( 'psts_settings_page', array( $this, 'settings' ) );

    In the settings page, you need to set your input fields. I have just added a text box field that contains a title for the button that would redirect to Thrivecart. You’ll probably need to add some public and secret key, depending on Thrivecart API. Make sure that all your input fields names are an array of psts[], eg: psts[thrivecart_public_key] and psts[thrivecart_private_key].

    3. In order to display a form/button on the checkout page of Pro Sites, Pro Sites requires a specific method for it’s gateways called render_gateway(). You can check it out in the snippet and modify accordingly.

    4. Another required method that Pro Sites requires for it’s gateways is this one

    public static function get_name()

    It simply returns the gateway’s name, but it is required in order to be able to select the gateway in admin and set it as a Primary or Secondary gateway in Gateway settings

    5. The hardest part and the part where the developer need to do all the handling, is to fetch and manage the HTTP Response(s) sent from Thrivecart. First we will need a custom webhook in the site, where Thrivecart will send it’s HTTP Requests. In the snippet there are 2 params that are combined to create that webhook:

    private static $webhook = 'ps-thrivecart-getway';
    private static $webhook_tag = 'thrive-cart-webhook';

    First time snippet is used, the permalinks need to be re-saved in WP network’s main site. You can change those of course depending on your preference. Whenever those are modified in code you will need to re-save main sites permalinks though.

    The above params give the following webhook url:

    site.com/ps-thrivecart-getway/thrive-cart-webhook

    You can use that in your Thrivecart account under Settings > API & Webhooks > Webhooks & notifications as I see in the docs. I don’t have an account so I can’t say for sure though

    Whenever Thrivecart sends an HTTP Request to your webhook (site.com/ps-thrivecart-getway/thrive-cart-webhook), this can be handled in the

    public function webhook_handler()

    method in the snippet.

    I don’t have a working example there but in comments I include how to parse the Request with php, some basic things that need to be checked and how to activate a signup (new sites are not created immediately. They get activated after first successful payment), how to cancel a Pro Site level and how to extend one.

    Hope this helps!

    Kind regards!

    • ido
      • The Incredible Code Injector

      Hey Panos

      The following is a question from my developer:

      Hi, just for clarification, i hope i’m passing the values properly to $psts->extends();

      The blog details extends successfully.

      please check the gist on github, i commented the code to try to understand what i was doing https://gist.github.com/Preciousomonze/65fdfdc2bb5a5546db035130da1ab893

      below is a screenshot of the details that were updated when thrivecart ran the webhook, is that the correct way it updates? please let me know so i’m sure i’m not missing anything.

      Note: i also noticed the blog level is 0 on the frontend, when you want to renew a payment of an existing blog, the details are empty, i can only get blog id from url and period(annually and monthly) from the drop down via jquery. notice the line from 119 to 129 , could it be something missing from you earlier code, like to get the blog details, im not sure . but here is the line of the code

      // If blog id is found in url.

      if ( ! empty( $bid ) ) {

      // Blog exists so probably might need to get info from Gateway’s API, eg for use info instead of :

      if ( ! empty( $blog_data ) ) {

      // Get the data.

      $username = empty( $blog_data ) ? ” : $blog_data;

      $user_email = empty( $blog_data ) ? ” : $blog_data;

      $blogname = empty( $blog_data ) ? ” : $blog_data;

      $blog_title = empty( $blog_data ) ? ” : $blog_data;

      }

      $url_params = $bid;

      }

      i hope these info could help

      Thanks in advance

      Ido

  • Panos
    • SLS

    Hi ido !

    i hope i’m passing the values properly to $psts->extends();

    In my comments in the gist snippet, I explained this part wrong I’m afraid:

    $result = $psts->extend($blog_id,$period_timestamp,self::$id,$level,$amount,$exp_timestamp,$recurring,false,'',$on_trial);

    The $period_timestamp should be the period, meaning it’s values should be 1 for 1 month period, 3 for 3 months period or 12 for annual period. It will be used to calculate the next expiration date, but only if the $exp_timestamp is not set. Sorry for confusion here. You can better check this in ProSites::extend().

    The extension seems correct though. The expiration date is important to be correct. Additionally you can provide some logs so you know each time what is going on. You can add a log upon payment/cancellation etc. For logs you can use:

    $psts->log_action( [Blog id], [The message] );

    Note: i also noticed the blog level is 0 on the frontend, when you want to renew a payment of an existing blog

    I am not sure about this. Renewals will be manual? I think you could try to check with some js to get the .choose-plan-button button and get the ul.chosen-plan and from that get the level id from it’s class eg psts-level-2.

    If you need the previous level of a blog, it is stored in the pro_sites DB table where you can select by blog_ID.

    I hope this is helpful :slight_smile:

    Kind regards!

    • ido
      • The Incredible Code Injector

      Hey Panos,

      Thanks for all your help here,

      I have another question…

      How we can get the token and PayerID values that shows up in the url parameter on final checkout?

      And is that all that is needed to generate the final confirmation page after payment?

      (The page that tells the new site owner how to login, his usernam, password and all that)

      Thanks in advance

      Ido

    • ido
      • The Incredible Code Injector

      Hey Panos,

      I’ve seen the troubling email from your CEO, and I see that this forum was integrated in to a general one.

      Hope you guys are not going to leave us hanging after all the work that was done here.

      The only problem I have now is after all is working well and payments are made… I need to send the new site owner to the page created by pro site… The last page that shows them the username, password, and signup link.

      And I don’t know how to find it.

      Hope you guys are still here.

      Ido

  • Panos
    • SLS

    Hi ido !

    Sorry for delay! Regarding that email it just means that we won’t be adding any new features. We’ll still be doing the best we can to support them :slight_smile:

    In regards to the PayerID and the token, it’s some check that Pro Sites does, but it doesn’t do any specific comparison, so those can be simply set in the query vars. The action var should be set to completed though.

    The only problem I have now is after all is working well and payments are made… I need to send the new site owner to the page created by pro site… The last page that shows them the username, password, and signup link.

    I’m not 100% sure, I believe some session var should be set. Allow me some time and will reply once I’m sure about it :slight_smile:

  • Panos
    • SLS

    The sessions way is a bit hackish, and needs to first create a custom session, as at some point Pro Sites sessions get deleted. Then in the prosites_before_checkout_page hook, use the custom session to fill the new_blog_details session var for new blogs or the upgraded_blog_details for existing ones.

    So I would suggest a simpler way. This would to be to redirect to the Pro Sites checkout page from your webhook handler and add the query args mentioned in previous post, plus the bid which will hold the blog_id. In the webhook_handler() method you should have all information for level, period, activation_key ( maybe blog id too if existing site) there.

    If it is a payment for new site, you can use the activation key to activate it. Here is an example using dummy data :

    $level = 2;
    $period = 3;
    $activation_key = 'b5c27738b3cf579d';
    $time = strtotime( date( 'Y-m-d' ) );
    $expire = strtotime("+{$period} month", $time);
    $is_trial = false;

    // Activate the blog now.
    $result = ProSites_Helper_Registration::activate_blog(
    $activation_key,
    $is_trial,
    $period,
    $level,
    $expire = date,
    false
    );

    if ( ! empty( $result['blog_id'] ) ) {
    $blog_id = $result['blog_id'];
    }

    Once all sorted you can redirect to the checkout page using this blog id in the url. We need to include the blog id in the bid query var, eg:

    $checkout_page = get_permalink( $psts->get_setting( 'checkout_page' ) );

    $checkout_page = add_query_arg( array(
    'action' => 'complete',
    'token' => 'couldbeblank',
    'PayerID' => 'couldbeblank',
    'bid' => $blog_id
    ), $checkout_page );

    wp_safe_redirect( $checkout_page );
    exit;

    I think you wont need to do anything form there on. The new user should be logged in during activation and should be able to see the info in the checkout page.

    Kind regards!

  • ido
    • The Incredible Code Injector

    Hi Panos,

    Thanks again for all your help with this issue.

    We used the bid to call up the new site variables and we got all new site details including password but the password is always wrong…

    Thanks in advance

    Ido

  • Panos
    • SLS

    Hi ido !

    There is a small error in my above example, sorry for that. The activate_blog() method’s first arg is an array which contains the activation key and the password. The password should already be generated and available in the session so you can pass it like this :

    $new_blog_details = ProSites_Helper_Session::session( 'new_blog_details' );

    $password = $new_blog_details['user_pass'];

    $data = array(
    'activation_key' => $activation_key,
    'new_blog_details' => array(
    'user_pass' => $password
    )
    );

    // Activate the blog now.
    $result = ProSites_Helper_Registration::activate_blog(
    $data,
    $is_trial,
    $period,
    $level,
    $expire,
    false
    );

    Kind regards!

    • ido
      • The Incredible Code Injector

      Hi guys,

      I’m sorry to keep bugging you with this one.

      But I’ve hade 4 freelancers work on this and no one managed to get this right, the password is still coming out incorrect.

      I’ve tried to add the WPMU-DEV plugin that lets people choose their own password when they signup and the password is still coming up incorrect.

      So, sorry again that I keep annoying you guys … but please help me out here this is killing me.

      Thanks in advance

      Ido.

  • Panos
    • SLS

    Hey Kasia Swiderska !

    I don’t have the response sent from Thrivecart, so I used static blog info from the signups db table :

    $blog_id = false;
    $payment_success = true;
    $blog_username = 'pstest2';

    $level = 2;
    $period = 3;
    $activation_key = '19a2e9d2a95db5b3';
    $time = strtotime( date( 'Y-m-d' ) );
    $expire = strtotime("+{$period} month", $time);
    $is_trial = false;

    $new_blog_details = ProSites_Helper_Session::session( 'new_blog_details' );
    $password = $new_blog_details['user_pass'];

    $data = array(
    'activation_key' => $activation_key,
    'new_blog_details' => array(
    'user_pass' => $password
    )
    );

    $result = ProSites_Helper_Registration::activate_blog(
    $data,
    $is_trial,
    $period,
    $level,
    $expire,
    false
    );

    if ( ! empty( $result['blog_id'] ) ) {
    $blog_id = $result['blog_id'];
    }

    $checkout_page = get_permalink( $psts->get_setting( 'checkout_page' ) );

    $checkout_page = add_query_arg( array(
    'action' => 'complete',
    'token' => 'the-token',
    'PayerID' => 'user-id',
    'bid' => $blog_id
    ), $checkout_page );

    wp_safe_redirect( $checkout_page );
    exit;

    and the password that is printed in the checkout page (and the one sent in the email) is correct in my side.

    I don’t see anything that would affect that in the file you attached. I don’t see the redirect to the checkout page though, so I’m not sure what you do see after the code in the webhook is done. You could try redirecting to the checkout page as in my example.

    • ido
      • The Incredible Code Injector

      Hi Panos,

      I’m sorry to keep coming with this one…

      But the freelancer that is working on this is saying it is not possible.

      Here is what he said,

      I just need you to tell me if it makes sans or not if you can:

      “What happens is this, as soon we get out from Prosites to Thrivecart, prosites doesn't see the new site as a new site any longer, it sees it as an existing site.

      so, on getting back to prosite after payment is completed and redirect is called it must show a wrong password because it is recognizing it as an existing site and not a new site.

      I guess Panos is not even aware of this but i can share you what you can show to Panos if you feel like but I am afraid there is nothing we or Panos can do about it due to the two-way process of moving from Prosite to Thrive then back”

      Please see the attached picture

      Thanks a lot

      Ido

  • Panos
    • SLS

    Hi ido ,

    There are two cases, one where guest is not registered to your site (so along with the new site it will create a new user), and one where he has registered already (so it will only create the new site). The part pointed above is for the case that the user already exists. I’ll try provide some detail about it so you get an idea how it’s processed so you can explain to your dev. It is a bit technical and I hope I don’t confuse you more.

    1st case: User is new

    In the first case, when the user goes to the checkout page, once he clicks the “Reserve your site” button, a new signup (meaning a new record in wp_signups table in db) is created with the site and user info collected from that page. At that point nor the site nor the user have been created. Their info is only in the signups table in the db. After successful payment (returning back from Thrivecart or any gateway) in the webhook we can now create the new site using the activation key (from the signups table) in ProSites_Helper_Registration::activate_blog() which uses the WP core function wpmu_activate_signup.

    That function will activate the blog (take info from signups table and create the actual site) and will create user if he doesn’t exist already (since it doesn’t it will):

    $user_id = username_exists( $signup->user_login );

    Something unusual that happens at this point is that the Session var :

    ProSites_Helper_Session::session( 'new_blog_details' )

    already contains a user password. So after the new user is created (by the WP core function), Pro Sites will assign the existing password (the one stored in the Session) to that user :

    wp_set_password( $user_pass, $result['user_id'] );

    So now the new user has the password that was stored in session.

    2nd case: Existing user creates a site

    Second case is when user already exists and wants to create a new site. This is the case that was pointed out in your reply. When an existing user is at the checkout page and clicks on the “Reserve your site” button, when receiving first payment from gateway, it will use once again the activation key and activate the blog. But since the user exists it doesn’t need to use the password again, even if we wanted to show it we can’t as it is already encrypted in db.

    The part pointed above is only when the user already exists where this condition is false:

    if ( ! empty( $userpass ) )

    as the $userpass variable is empty.

    Something else that you can try is get the user password from the $result variable:

    $result = ProSites_Helper_Registration::activate_blog( ....)

    The activate_blog() method should return the users password in an array, if that exists in the session. Here is how it sets it at the end of the method:

    if( ! empty( $user_pass ) ) {
    $result['password'] = $user_pass;
    }

    Hope this clarifies a bit.

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.