I have created a simple extension in EE to handle PayPal payments on submission of a Channel Form, which seems to be working up to a point.
My problem is how do I get the extension to handle the response after the return from PayPal?
My send parameters need to include a 'returnURL' which means that PayPal redirects to this page on successful completion - obviously this means the function in the extension is no longer in play!
Here's the logic in the extension:
$response = $gateway->purchase($args)->send();
if ($response->isSuccessful()) {
// do something with the response
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
The issue is that on returning from the redirect to the offsite gateway,the 'isSuccessful' branch doesn't get executed, I am just redirected to the page specified in the 'returnURL' parameter sent with the initial request.
How do I process the return from PayPal so I can send the completePurchase() request within the extension?
EDIT I've just had a thought - should I make the returnURL an '?ACT' and add an entry to the actions table to call the next function in the extension?
... I'll try it
EDIT
Except you can't use actions with extensions, only modules. And you can't use hooks in modules, only extensions. As I need to hook into the form submit AND use an action to process the return, it' back to the drawing board :-(