Index: readme.txt
===================================================================
--- readme.txt	(revision 882853)
+++ readme.txt	(working copy)
@@ -1,14 +1,14 @@
 === Restrict Content Pro - Affiliates Pro Add On ===
 Author URI: http://pippinsplugins.com
 Plugin URI: http://pippinsplugins.com/restrict-content-pro-affiliates
-Contributors: mordauk
+Contributors: mordauk, itthinx
 Donate link: http://pippinsplugins.com/support-the-site
 Tags: Affiliates, Affiliates Pro, restrict content, memberships, premium content, Restrict Content Pro, mordauk, Pippin Williamson, pippinsplugins
 Requires at least: 3.2
 Tested up to: 3.4.1
 Stable Tag: 1.0
+License: GPLv3
 
-
 Provides an integration between Restrict Content Pro and Affiliates (Light or Pro).
 
 == Description ==
@@ -22,8 +22,9 @@
 == Installation ==
 
 1. Activate the plugin
-2. Ensure you have the Affiliates (pro or light) configured correctly. Consult the documentation for those plugins if you are unsure about setup
-3. There is no setup for this add-on, just activate and use
+2. Ensure you have the Affiliates, Affiliates Pro or Affiliates Enterprise plugin installed and configured correctly. Consult the documentation for those plugins if you are unsure about setup.
+3. There is no setup for this add-on if you are using Affiliates Pro or Affiliates Enterprise. If you are using the Affiliates plugin, change the value of the RCP_REFERRAL_RATE from 0.1 to your desired commission rate.
+   Look for the line `define( 'RCP_REFERRAL_RATE', 0.1 );` in the plugin's main file `rcp-affiliates-pro.php`.
 
 When Affiliates is configured, you will see referrals in the plugin's dashboard anytime a member is referred and signs up for a paid membership.
 
@@ -33,19 +34,26 @@
 
 No, referral earnings are tracked on the first payment only.
 
-2. Who do I talk you about configuring Affiliates (Pro or Light)?
+2. Who do I talk you about configuring Affiliates, Affiliates Pro or Affiliates Enterprise?
 
-[itthinx](http://profiles.wordpress.org/itthinx/) is the developer that wrote both versions of the Affiliates plugin, so please talk to him about problems or questions with either plugin.
+Plugin support page : [Affiliates](http://www.itthinx.com/plugins/affiliates/).
 
 
 == Changelog ==
 
+= 1.1 =
+* corrected wrong referral petition point
+* added referral status update handling
+
 = Version 1.0 =
 
 First release.
 
 == Upgrade Notice ==
 
+= 1.1. =
+* Please upgrade to this version which provides important fixes for this integration.
+
 = Version 1.0 =
 
 First release.
\ No newline at end of file
Index: rcp-affiliates-pro.php
===================================================================
--- rcp-affiliates-pro.php	(revision 882853)
+++ rcp-affiliates-pro.php	(working copy)
@@ -1,57 +1,90 @@
 <?php
 /*
-Plugin Name: Restrict Content Pro - Affiliates Pro
+Plugin Name: Restrict Content Pro - Affiliates / Pro / Enterprise
 Plugin URL: http://pippinsplugins.com/rcp-affiliates-pro
-Description: Restrict Content Pro Integration for Affiliates Pro
-Version: 1.0
+Description: Restrict Content Pro Integration for Affiliates, Affiliates Pro and Affiliates Enterprise
+Version: 1.1
 Author: Pippin Williamson
 Author URI: http://pippinsplugins.com
-Contributors: mordauk
+Contributors: mordauk, itthinx
 */
 
+// ***************************************************************************
+//
+// Set your referral rate below if you are using the Affiliates plugin.
+// This rate is NOT used with Affiliates Pro or Affiliates Enterprise.
+// The default rate is 0.1 granting 10% commissions.
+//
+// ***************************************************************************
+
+define( 'RCP_REFERRAL_RATE', 0.1 );
+
+// ***************************************************************************
+// The line above must look like this:
+//
+//     define( 'RCP_REFERRAL_RATE', 0.1 );
+//
+// You can change 0.1 to something else, for example 0.25 to grant 25%
+// commissions.
+//
+// Please DO NOT EDIT anything below (developers only).
+//
+// ***************************************************************************
+
 function rcp_award_commission( $payment_id, $payment_data, $amount ) {
+	global $wpdb;
+	if ( function_exists( '_affiliates_get_tablename' ) ) {
+		$referrals_table = _affiliates_get_tablename( 'referrals' );
+		if ( $referral_id = $wpdb->get_var( $wpdb->prepare( "SELECT referral_id FROM $referrals_table WHERE reference = %s", $payment_data['subscription_key'] ) ) ) {
+			if ( class_exists( 'Affiliates_Referral_WordPress' ) ) {
+				$r = new Affiliates_Referral_WordPress( $referral_id );
+				$r->update( array( 'status' => AFFILIATES_REFERRAL_STATUS_ACCEPTED ) );
+			} else if ( function_exists( 'affiliates_suggest_referral' ) ) {
+				affiliates_update_referral( $referral_id, array( 'status' => AFFILIATES_REFERRAL_STATUS_ACCEPTED ) );
+			}
+		}
+	}
+}
+add_action( 'rcp_insert_payment', 'rcp_award_commission', 10, 3 );
 
-  global $rcp_options;
+function aff_rcp_subscription_data( $subscription_data ) {
 
-	$user_info = maybe_unserialize( $payment_data['user_info'] );
+	global $rcp_options;
 
-  $user_link = '<a href="' . admin_url( 'admin.php?page=rcp-members&view_member=' . $payment_data['user_id'] ) . '">' . __('View User', 'rcp') . '</a>';
+	$user_link = '<a href="' . admin_url( 'admin.php?page=rcp-members&view_member=' . $subscription_data['user_id'] ) . '">' . __( 'View User', 'rcp' ) . '</a>';
 
+	$amount = floatval( $subscription_data['price'] );
+	if ( $subscription_data['auto_renew'] ) {
+		$amount += floatval( $subscription_data['fee'] );
+	}
+
 	$data = array(
-      'order_id' => array(
-          'title' => __('Payment #', 'rcp'),
-          'domain' => 'rcp',
-          'value' => esc_sql( $payment_id )
-      ),
-      'order_total' => array(
-          'title' => __('Total', 'rcp'),
-          'domain' =>  'rcp',
-          'value' => esc_sql( $amount )
-      ),
-      'referred_user' => array(
-      	'title' => __('Referred User', 'rcp'),
-      	'domain' => 'rcp',
-      	'value' => esc_sql( $user_link )
-      )
+		'subscription_key' => array(
+			'title'  => __( 'Subscription Key', 'rcp' ),
+			'domain' => 'rcp',
+			'value'  => esc_sql( $subscription_data['key'] )
+		),
+		'subscription_total' => array(
+			'title'  => __( 'Total', 'rcp' ),
+			'domain' =>  'rcp',
+			'value'  => esc_sql( $amount )
+		),
+		'referred_user' => array(
+			'title'  => __( 'Referred User', 'rcp' ),
+			'domain' => 'rcp',
+			'value'  => esc_sql( $user_link )
+		)
 	);
-	
-  $description = sprintf( __('Payment #%s', 'rcp'), $payment_id );
 
-  if( class_exists( 'Affiliates_Referral_WordPress' ) ) {
+	$description = sprintf( __('Subscription %s #%s', 'rcp'), $subscription_data['subscription_name'], $subscription_data['key'] );
 
-  	/*****************************************
-    * Record referral for pro version
-    *****************************************/
-    $r = new Affiliates_Referral_WordPress();
-    $r->evaluate( 0, $description, $data, $amount, null, $rcp_options['currency'], AFFILIATES_REFERRAL_STATUS_ACCEPTED, 'sale', $payment_id );
-
-  } elseif( function_exists( 'affiliates_suggest_referral' ) ) {
-    /*****************************************
-    * Record referral for free version
-    *****************************************/
-    $referral_rate = get_option( 'aff_def_ref_calc_value' );
-    $amount = round( floatval( $referral_rate ) * floatval( $amount ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS );
-    affiliates_suggest_referral( 0, $description, $data, $amount, $rcp_options['currency'] );
-  }
+	if( class_exists( 'Affiliates_Referral_WordPress' ) ) {
+		$r = new Affiliates_Referral_WordPress();
+		$r->evaluate( 0, $description, $data, $amount, null, $rcp_options['currency'], AFFILIATES_REFERRAL_STATUS_PENDING, 'subscription', $subscription_data['key'] );
+	} else if ( function_exists( 'affiliates_suggest_referral' ) ) {
+		$amount = round( floatval( RCP_REFERRAL_RATE ) * floatval( $amount ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS );
+		affiliates_suggest_referral( 0, $description, $data, $amount, $rcp_options['currency'], AFFILIATES_REFERRAL_STATUS_PENDING, 'subscription', $subscription_data['key'] );
+	}
+	return $subscription_data;
 }
-add_action('rcp_insert_payment', 'rcp_award_commission', 10, 3);
\ No newline at end of file
+add_filter( 'rcp_subscription_data', 'aff_rcp_subscription_data' );
