Beispiel #1
0
 /**
  * Creates the pending referral during signup
  *
  * @access  public
  * @since   1.0
  */
 public function add_pending_referral($post_data, $user_id, $price)
 {
     $affiliate_discount = false;
     if (!empty($_POST['rcp_discount'])) {
         global $wpdb;
         $rcp_discounts = new RCP_Discounts();
         $discount_obj = $rcp_discounts->get_by('code', $_POST['rcp_discount']);
         $affiliate_id = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'affwp_discount_rcp_' . $discount_obj->id));
         $user_id = affwp_get_affiliate_user_id($affiliate_id);
         $discount_aff = get_user_meta($user_id, 'affwp_discount_rcp_' . $discount_obj->id, true);
         if ($discount_aff && affiliate_wp()->tracking->is_valid_affiliate($affiliate_id)) {
             $affiliate_discount = true;
             $amount = affwp_calc_referral_amount($price, $affiliate_id);
             if (0 == $amount && affiliate_wp()->settings->get('ignore_zero_referrals')) {
                 return false;
                 // Ignore a zero amount referral
             }
             $referral_id = affiliate_wp()->referrals->add(array('amount' => $amount, 'reference' => rcp_get_subscription_key($user_id), 'description' => rcp_get_subscription($user_id), 'affiliate_id' => $affiliate_id, 'context' => $this->context));
         }
     }
     if ($this->was_referred() && !$affiliate_discount) {
         $user = get_userdata($user_id);
         if ($this->is_affiliate_email($user->user_email)) {
             return;
             // Customers cannot refer themselves
         }
         $key = rcp_get_subscription_key($user_id);
         $total = $this->calculate_referral_amount($price, $key);
         $this->insert_pending_referral($total, $key, rcp_get_subscription($user_id));
     }
 }
 /**
  * Record referral conversion via ajax
  *
  * This is called anytime a referred visitor lands on a success page, defined by the [affiliate_conversion_script] shortcode
  *
  * @since 1.0
  */
 public function track_conversion()
 {
     $affiliate_id = absint($_POST['affiliate']);
     if ($this->is_valid_affiliate($affiliate_id)) {
         $md5 = md5($_POST['amount'] . $_POST['description'] . $_POST['reference'] . $_POST['context'] . $_POST['status']);
         if ($md5 !== $_POST['md5']) {
             die('-3');
             // The args were modified
         }
         if (affiliate_wp()->referrals->get_by('visit_id', $this->get_visit_id())) {
             die('-4');
             // This visit has already generated a referral
         }
         $status = !empty($_POST['status']) ? $_POST['status'] : 'unpaid';
         $amount = sanitize_text_field(urldecode($_POST['amount']));
         if (0 == $amount && affiliate_wp()->settings->get('ignore_zero_referrals')) {
             die('-5');
             // Ignore a zero amount referral
         }
         $amount = $amount > 0 ? affwp_calc_referral_amount($amount, $affiliate_id) : 0;
         // Store the visit in the DB
         $referral_id = affiliate_wp()->referrals->add(array('affiliate_id' => $affiliate_id, 'amount' => $amount, 'status' => 'pending', 'description' => sanitize_text_field($_POST['description']), 'context' => sanitize_text_field($_POST['context']), 'campaign' => sanitize_text_field($_POST['campaign']), 'reference' => sanitize_text_field($_POST['reference']), 'visit_id' => $this->get_visit_id()));
         affwp_set_referral_status($referral_id, $status);
         affiliate_wp()->visits->update($this->get_visit_id(), array('referral_id' => $referral_id), '', 'visit');
         echo $referral_id;
         exit;
     } else {
         die('-2');
     }
 }
Beispiel #3
0
 /**
  * Retrieves the rate and type for a specific product
  *
  * @access  public
  * @since   1.2
  * @return  array
  */
 public function calculate_referral_amount($base_amount = '', $reference = '', $product_id = 0)
 {
     $rate = '';
     $this->affiliate_id = $this->get_affiliate_id();
     if (!empty($product_id)) {
         $rate = $this->get_product_rate($product_id, $args = array('reference' => $reference));
     }
     $amount = affwp_calc_referral_amount($base_amount, $this->affiliate_id, $reference, $rate, $product_id);
     return $amount;
 }
Beispiel #4
0
 /**
  * Retrieves the rate and type for a specific product
  *
  * @access  public
  * @since   1.2
  * @return  array
  */
 public function calculate_referral_amount($base_amount = '', $reference = '', $product_id = 0, $affiliate_id = 0)
 {
     // the affiliate ID can be optionally passed in to override the referral amount
     $affiliate_id = !empty($affiliate_id) ? $affiliate_id : $this->get_affiliate_id($reference);
     $rate = '';
     if (!empty($product_id)) {
         $rate = $this->get_product_rate($product_id, $args = array('reference' => $reference, 'affiliate_id' => $affiliate_id));
     }
     $amount = affwp_calc_referral_amount($base_amount, $affiliate_id, $reference, $rate, $product_id);
     return $amount;
 }
Beispiel #5
0
 /**
  * Retrieves the rate and type for a specific product
  *
  * @access  public
  * @since   1.2
  * @return  array
  */
 public function calculate_referral_amount($base_amount = '', $reference = '', $product_id = 0)
 {
     $rate = '';
     $this->affiliate_id = $this->get_affiliate_id();
     if (!empty($product_id)) {
         $rate = $this->get_product_rate($product_id, $args = array('reference' => $reference));
         $type = affwp_get_affiliate_rate_type($this->affiliate_id);
         if ('percentage' == $type) {
             // Sanitize the rate and ensure it's in the proper format
             if ($rate > 1) {
                 $rate = $rate / 100;
             }
         }
     }
     $amount = affwp_calc_referral_amount($base_amount, $this->affiliate_id, $reference, $rate, $product_id);
     return $amount;
 }