Tips and Tricks HQ Support

Support site for Tips and Tricks HQ premium products

  • Home
  • Contact Us
  • Documentation
  • Forum Home
    • Forum
    • Forum Search
    • Forum Login
    • Forum Registration

Affiliate recurring billing with 3rd party cart

by

Tips and Tricks HQ Support Portal › Forums › WP Affiliate Platform › Affiliate recurring billing with 3rd party cart

  • This topic has 13 replies, 3 voices, and was last updated 12 years ago by admin.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • September 30, 2012 at 5:53 am #7519
    oniiru
    Member

    Howdy,

    I use Paid Memberships Pro to handle payment on my site. I have managed to set up WP affiliate Platform to work with the initial payment, using the supplied code:

    $sale_amt = $pmpro_level->initial_payment; //TODO – The commission will be calculated based on this amount

    $unique_transaction_id = $order_id; //TODO – The unique transaction ID for reference

    $email = $bemail; //TODO – Customer email for record

    $referrer = $_COOKIE;

    do_action(‘wp_affiliate_process_cart_commission’, array(“referrer” => $referrer, “sale_amt” =>$sale_amt, “txn_id”=>$unique_transaction_id, “buyer_email”=>$email));

    Seems to work perfectly. It’s just that I’m not sure what code I should use for the recurring payments. I realize that without diving into the Paid Memberships Pro plugin, you can’t give me an exact answer. But generally speaking what code would you use to attribute a recurring payment to a specific affiliate? I was looking for a support doc like http://www.tipsandtricks-hq.com/wordpress-affiliate/api-awarding-commission-via-wordpress-hook-501, but referring to recurring payments, but couldn’t find it.

    Any help would be hugely appreciated.

    Thanks!

    Andrew

    October 1, 2012 at 3:34 am #49884
    admin
    Keymaster

    When the recurring payment is processed by that plugin, you simply execute the same code that you have prepared for the initial payment. The only thing you will need to change is the “sale_amt” value to reflect the recurring amount. The affiliate plugin doesn’t care if it is an initial payment or recurring payment. You simply make an API call and pass the info then the affiliate plugin will track the commission accordingly.

    October 1, 2012 at 9:56 pm #49885
    oniiru
    Member

    cool. Does it treat it as a new sale or link it to the original purchase? The reason I ask is that if it is a new sale, once the cookie expires, wouldn’t the affiliate no longer receive credit?

    Or does it apply any payment with the same email address to the affiliate going forward, or something like that?

    All the best,

    Andrew

    October 2, 2012 at 12:28 am #49886
    admin
    Keymaster

    It will treat is as a new commission. After the first sale, you would save the cookie value (the referrer ID) with other sale related details in the eCommerce plugin’s order database table. This way, when it is time to award a recurring commission, you can retrieve all the required data from the order database table (or something similar) and notify the affiliate plugin accordingly.

    June 26, 2013 at 2:57 am #49887
    Aff
    Member

    Hi oniiru,

    I’m curious if you were able to resolve this because I’m in the same position now. I would really appreciate any direction or advice on how to track the recurring payments.

    June 27, 2013 at 12:48 am #49888
    admin
    Keymaster

    @Aff, What 3rd party cart solution are you using? And how are you integrating it?

    June 27, 2013 at 7:30 am #49889
    Aff
    Member

    Hi admin,

    I’m using paid memberships pro (stripe gateway) and i’m currently using their addon plugin hosted here: https://gist.github.com/strangerstudios/3137539

    However, I’m not sure how exactly I can a) accomplish tracking and notifying WP affiliate platform of recurring payments and b) how to tie this to the affiliate from the initial purchase.

    June 27, 2013 at 10:03 pm #49890
    Aff
    Member

    Also, just to confirm, the initial payments are being tracked and attributed to the corresponding affiliate, the problem is with recurring payments. By looking at that addon above, are you seeing any reason why recurring payments aren’t being tracked and attributed to the original affiliate?

    June 28, 2013 at 5:44 pm #49891
    Aff
    Member

    Can someone please provide feedback – I’m urgently trying to resolve this issue but I need help from the support team here.

    June 29, 2013 at 12:16 am #49892
    admin
    Keymaster

    Hi, I just had a look at the code/addon the other developer created. It looks like the following action hook should be fired for every time a recurring payment is charged:

    pmpro_add_order

    Is your stripe addon doing that? Please ask the stripe addon developer to confirm that they are doing it.

    We didn’t develop the above mentioned addon so I am just suggesting by looking at the code.

    June 29, 2013 at 3:03 am #49893
    Aff
    Member

    Hi,

    I’ve tried reaching the developer but they won’t respond. Below you can see the code for the saveOrder() method that runs each time a stripe order comes through (via webhook). The bottom shows where the pmpro_add_order gets fired. Any other clues as to what may be going wrong?

    I appreciate the help.

    function saveOrder()

    {

    global $current_user, $wpdb;

    //get a random code to use for the public ID

    if(empty($this->code))

    $this->code = $this->getRandomCode();

    //figure out how much we charged

    if(!empty($this->InitialPayment))

    $amount = $this->InitialPayment;

    elseif(!empty($this->subtotal))

    $amount = $this->subtotal;

    else

    $amount = 0;

    //Todo: Tax?!, Coupons, Certificates, affiliates

    if(empty($this->subtotal))

    $this->subtotal = $amount;

    if(isset($this->tax))

    $tax = $this->tax;

    else

    $tax = $this->getTax(true);

    $this->certificate_id = “”;

    $this->certificateamount = “”;

    //calculate total

    if(!empty($this->total))

    $total = $this->total;

    else

    $total = (float)$amount + (float)$tax;

    //these fix some warnings/notices

    if(empty($this->billing))

    {

    $this->billing->name = $this->billing->street = $this->billing->city = $this->billing->state = $this->billing->zip = $this->billing->country = $this->billing->phone = “”;

    }

    if(empty($this->user_id))

    $this->user_id = “”;

    if(empty($this->paypal_token))

    $this->paypal_token = “”;

    if(empty($this->couponamount))

    $this->couponamount = “”;

    if(empty($this->payment_type))

    $this->payment_type = “”;

    if(empty($this->payment_transaction_id))

    $this->payment_transaction_id = “”;

    if(empty($this->subscription_transaction_id))

    $this->subscription_transaction_id = “”;

    if(empty($this->affiliate_id))

    $this->affiliate_id = “”;

    if(empty($this->affiliate_subid))

    $this->affiliate_subid = “”;

    if(empty($this->session_id))

    $this->session_id = “”;

    if(empty($this->gateway))

    $this->gateway = pmpro_getOption(“gateway”);

    if(empty($this->gateway_environment))

    $this->gateway_environment = pmpro_getOption(“gateway_environment”);

    if(empty($this->notes))

    $this->notes = “”;

    //build query

    if(!empty($this->id))

    {

    //set up actions

    $before_action = “pmpro_update_order”;

    $after_action = “pmpro_updated_order”;

    //update

    $this->sqlQuery = “UPDATE $wpdb->pmpro_membership_orders

    SET code = ‘” . $this->code . “‘,

    session_id = ‘” . $this->session_id . “‘,

    user_id = ‘” . $this->user_id . “‘,

    membership_id = ‘” . $this->membership_id . “‘,

    paypal_token = ‘” . $this->paypal_token . “‘,

    billing_name = ‘” . $wpdb->escape($this->billing->name) . “‘,

    billing_street = ‘” . $wpdb->escape($this->billing->street) . “‘,

    billing_city = ‘” . $wpdb->escape($this->billing->city) . “‘,

    billing_state = ‘” . $wpdb->escape($this->billing->state) . “‘,

    billing_zip = ‘” . $wpdb->escape($this->billing->zip) . “‘,

    billing_country = ‘” . $wpdb->escape($this->billing->country) . “‘,

    billing_phone = ‘” . $wpdb->escape($this->billing->phone) . “‘,

    subtotal = ‘” . $this->subtotal . “‘,

    tax = ‘” . $this->tax . “‘,

    couponamount = ‘” . $this->couponamount . “‘,

    certificate_id = ‘” . $this->certificate_id . “‘,

    certificateamount = ‘” . $this->certificateamount . “‘,

    total = ‘” . $this->total . “‘,

    payment_type = ‘” . $this->payment_type . “‘,

    cardtype = ‘” . $this->cardtype . “‘,

    accountnumber = ‘” . $this->accountnumber . “‘,

    expirationmonth = ‘” . $this->expirationmonth . “‘,

    expirationyear = ‘” . $this->expirationyear . “‘,

    status = ‘” . $wpdb->escape($this->status) . “‘,

    gateway = ‘” . $this->gateway . “‘,

    gateway_environment = ‘” . $this->gateway_environment . “‘,

    payment_transaction_id = ‘” . $wpdb->escape($this->payment_transaction_id) . “‘,

    subscription_transaction_id = ‘” . $wpdb->escape($this->subscription_transaction_id) . “‘,

    affiliate_id = ‘” . $wpdb->escape($this->affiliate_id) . “‘,

    affiliate_subid = ‘” . $wpdb->escape($this->affiliate_subid) . “‘,

    notes = ‘” . $wpdb->escape($this->notes) . “‘

    WHERE id = ‘” . $this->id . “‘

    LIMIT 1″;

    }

    else

    {

    //set up actions

    $before_action = “pmpro_add_order”;

    $after_action = “pmpro_added_order”;

    //insert

    $this->sqlQuery = “INSERT INTO $wpdb->pmpro_membership_orders

    (code, session_id, user_id, membership_id, paypal_token, billing_name, billing_street, billing_city, billing_state, billing_zip, billing_country, billing_phone, subtotal, tax, couponamount, certificate_id, certificateamount, total, payment_type, cardtype, accountnumber, expirationmonth, expirationyear, status, gateway, gateway_environment, payment_transaction_id, subscription_transaction_id, timestamp, affiliate_id, affiliate_subid, notes)

    VALUES(‘” . $this->code . “‘,

    ‘” . session_id() . “‘,

    ‘” . $this->user_id . “‘,

    ‘” . $this->membership_id . “‘,

    ‘” . $this->paypal_token . “‘,

    ‘” . $wpdb->escape(trim($this->billing->name)) . “‘,

    ‘” . $wpdb->escape(trim($this->billing->street)) . “‘,

    ‘” . $wpdb->escape($this->billing->city) . “‘,

    ‘” . $wpdb->escape($this->billing->state) . “‘,

    ‘” . $wpdb->escape($this->billing->zip) . “‘,

    ‘” . $wpdb->escape($this->billing->country) . “‘,

    ‘” . cleanPhone($this->billing->phone) . “‘,

    ‘” . $amount . “‘,

    ‘” . $tax . “‘,

    ‘” . $this->couponamount. “‘,

    ‘” . intval($this->certificate_id) . “‘,

    ‘” . $this->certificateamount . “‘,

    ‘” . $total . “‘,

    ‘” . $this->payment_type . “‘,

    ‘” . $this->cardtype . “‘,

    ‘” . hideCardNumber($this->accountnumber, false) . “‘,

    ‘” . substr($this->ExpirationDate, 0, 2) . “‘,

    ‘” . substr($this->ExpirationDate, 2, 4) . “‘,

    ‘” . $wpdb->escape($this->status) . “‘,

    ‘” . $this->gateway . “‘,

    ‘” . $this->gateway_environment . “‘,

    ‘” . $wpdb->escape($this->payment_transaction_id) . “‘,

    ‘” . $wpdb->escape($this->subscription_transaction_id) . “‘,

    now(),

    ‘” . $wpdb->escape($this->affiliate_id) . “‘,

    ‘” . $wpdb->escape($this->affiliate_subid) . “‘,

    ‘” . $wpdb->escape($this->notes) . “‘

    )”;

    }

    do_action($before_action, $this);

    if($wpdb->query($this->sqlQuery) !== false)

    {

    if(empty($this->id))

    $this->id = $wpdb->insert_id;

    do_action($after_action, $this);

    return $this->getMemberOrderByID($this->id);

    }

    else

    {

    return false;

    }

    }

    June 30, 2013 at 2:43 am #49894
    admin
    Keymaster

    Lets try to establish if this addon is actually *notifying* the affiliate plugin when a recurring payment is charged.

    Please go to the settings menu of the affiliate plugin and enable the debug option. Then wait for a recurring payment to get charged then we will check the debug and see if any notification call was made to the affiliate plugin (the debug will tell us anyone sent any notification).

    July 2, 2013 at 9:18 pm #49895
    Aff
    Member

    Hi,

    Yes the log is working, but is there an alternative to waiting a month for another recurring payment to come through from a user who was driven to the site from an affiliate, just to test this integration?

    As you can see in the integration code and the saveOrder function I posted previously, the wpa_pmpro_add_order should be running whenever recurring payments come through.

    July 3, 2013 at 2:37 am #49896
    admin
    Keymaster

    Yeah it should but remember that we didn’t develop that addon so we really have no way to know for sure unless it gets tested and we can check debug to make sure that addon did do the notification.

  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Log In

Forum Related

  • Forum Home
  • Forum Search
  • Forum Registration
  • Forum Login

Support Related Forms

  • Contact Us
  • Customer Support
  • Request a Plugin Update
  • Request Fresh Download Links

Useful Links

  • Plugin Upgrade Instructions
  • WP eStore Documentation
  • WP eMember Documentation
  • WP Affiliate Platform Documentation
  • Tips and Tricks HQ Home Page
  • Our Projects

Quick Setup Video Tutorials

  • WP eStore Video Tutorial
  • WP eMember Video Tutorial
  • WP Affiliate Platform Video Tutorial
  • Lightbox Ultimate Video Tutorial

Our Other Plugins

  • WP Express Checkout
  • Stripe Payments Plugin
  • Simple Shopping Cart Plugin
  • Simple Download Monitor

Copyright © 2025 | Tips and Tricks HQ