I don't know if this is possible or if it's a complete madness but I'm trying to execute a PHP method from AJAX call using Ajax Framework since I don't know how to fit this in a component code or in a plugin code and get it working with page lifecycle but is not working because I never get redirect to PayPal site as should be. The code below uses Omnipay library to redirect users outside OctoberCMS and execute a purchase method on PayPal page. I should say this is not the payment method at all, is some kind of confirmation, so when users click "Ok" or "Cancel" in both cases it will be redirected back to OctoberCMS site so I can process the flow in any case. The PHP code I'm trying to get working is this one:
public function onExecutePurchaseMethod()
{
echo Session::get('amountToReload');
$params = [
'username' => $this->username,
'password' => $this->password,
'signature' => $this->signature,
'testMode' => $this->sandboxMode,
'amount' => Session::get('amountToReload'),
'cancelUrl' => url( 'payment/step4', "", $secure = null ),
'returnUrl' => url( 'payment/step2', "", $secure = null ),
'currency' => 'USD'
];
$response = Omnipay::purchase($params)->send();
if ($response->isSuccessful()) {
var_dump($response);
} else {
var_dump($response->getMessage());
}
}
What is happening is none redirection to PayPal is executed and page is getting stuck many times forcing me to close the browser and reopen again, no method is executed, no visible errors, no redirection to PayPal site. It's possible to do what I'm trying to do? Is not a madness? If it's possible where is my error?
Last updated