How do call a method inside a component in OctoberCMS?

1.4k views Asked by At

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 OctoberCMS Ajax Framework(I assume that this uses jQuery behind it) and is not working because I never get redirect to PayPal site. The PHP code I'm trying to get working is this one:

protected function onExecutePurchaseMethod()
{
    Omnipay::gateway('PayPal_Express');

    $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 since none redirect to PayPal is executed and page is getting stuck many times forcing me to close the browser and reopen again, no method is executed and no visible errors. It's possible to do what I'm trying to do? Is not a madness? If it's possible where is my error?

As extra info I'm using Barryvdh Laravel-omnipay package for handle Omnipay from within Laravel.

1

There are 1 answers

7
cchapman On BEST ANSWER

After looking briefly through the documentation, my best guess is that you're missing a required field for the purchase() method. I believe you need a card parameter (even if it's an invalid one) to get it to process.