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

    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!

  • Panos

    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:

    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.
    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:
    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

      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['username'] ) ? '' : $blog_data['username'];
      $user_email = empty( $blog_data['email'] ) ? '' : $blog_data['email'];
      $blogname = empty( $blog_data['blogname'] ) ? '' : $blog_data['blogname'];
      $blog_title = empty( $blog_data['title'] ) ? '' : $blog_data['title'];
      $url_params['blog_id_username'] = $bid;

      i hope these info could help

      Thanks in advance

  • Panos

    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!

  • Panos

    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

    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(
                    $expire = date,
                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 );

    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!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.