We store the affiliate id with the basket, because the IPN that pays the basket could come hours later, days even, which would cause problems as the user won't exist. If you used onCPayAfterPaymentStatusUpdateEvent then it's not an issue as you've access to the user object. You'd basically modify the plugins usage of onCPayAfterPaymentStatusUpdateEvent and check if the have that field completed. Example as follows.
IN: components/com_comprofiler/plugin/user/plug_cbpaidsubscriptions/plugin/cbsubspostafpro/cbsubs.postafpro.php
ON: Line 90
FROM:
Code:
$affiliateID = $integrationParams->get( 'postafpro_affiliateid', null );
TO:
Code:
if ( $user->get( 'FIELD_NAME' ) ) {
$affiliateID = $user->get( 'FIELD_NAME' );
} else {
$affiliateID = $integrationParams->get( 'postafpro_affiliateid', null );
}
You can replace FIELD_NAME with whatever field you'd like to use. It'll check if it has a value and if it does it'll use it as the affiliate id otherwise it'll fallback to the basket stored affiliate id, which came from the cookie. Since this is done when the basket is actually paid and the subscription is becoming active it'd be completely reliable where as onCPayBeforeStorePaymentBasketUpdated may or may not have an empty user object.