Well, the best thing to do is to have 2 separate scripts. One that generates the product keys, one that extends the trial. As far as generating the product keys, you should use our existing script: https://wyday.com/limelm/help/automate-license-generation-with-fastspring/
For the extension script you need to do the following:
1. Either prompt the user for the product key, or use the email address the user provides to find the product key: https://wyday.com/limelm/help/api/limelm.pkey.find/
2. Based on the product key found, get the product key id: https://wyday.com/limelm/help/api/limelm.pkey.getID/
3. Then set the custom license fields: https://wyday.com/limelm/help/api/limelm.pkey.setDetails/
Let me know if that helps.