How to send commission to affiliates at time of Renewal

Hi
For renewal of the account i use crontab to execute
renewal_auto_monthly_transaction.rake file which make auto renewal for
every 30 days billing cycle. My problem is for every renewal of the
account means the amount charged for the renewal on that 20 percent
commission must be added to affiliate.

Affiliates provide an api JavaScript which one sign up thank you i
pasted the code which takes parameters amount,
user name, transaction id and adds to the 3rd party affiliates
account.

But for Renewal how can we add 3rd party JavaScript api(well this
script cannot be used in rake file)…is there any alternative
solution for this…?