简体   繁体   English

如何在OctoberCMS的组件内部调用方法?

[英]How do call a method inside a component in OctoberCMS?

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. 我不知道这是否可行或完全疯狂,但我正在尝试使用OctoberCMS Ajax Framework从AJAX调用执行PHP方法(我假设它在其后使用jQuery),但由于我从未得到过支持而无法正常工作重定向到PayPal网站。 The PHP code I'm trying to get working is this one: 我正在尝试使用的PHP代码是以下代码:

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. 发生了什么,因为没有执行任何重定向到PayPal的操作,并且页面多次卡住,迫使我关闭浏览器并再次打开,因此没有执行任何方法,也没有可见错误。 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. 作为额外的信息,我正在使用Barryvdh Laravel-omnipay软件包从Laravel内部处理Omnipay。

After looking briefly through the documentation, my best guess is that you're missing a required field for the purchase() method. 在简要浏览文档之后,我的最佳猜测是您缺少purchase()方法的必填字段。 I believe you need a card parameter (even if it's an invalid one) to get it to process. 我相信您需要一个card参数(即使它是无效的参数)也可以进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM