【问题标题】:How do call a method inside a component in OctoberCMS?如何在 OctoberCMS 中调用组件内的方法?
【发布时间】:2015-01-10 01:27:45
【问题描述】:

我不知道这是否可能,或者这是否完全疯狂,但我正在尝试使用 OctoberCMS Ajax Framework(我假设这在其背后使用 jQuery)从 AJAX 调用中执行 PHP 方法并且无法正常工作,因为我永远不会重定向到 PayPal 网站。我正在尝试使用的 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());
    }
}

发生了什么,因为没有执行重定向到 PayPal 并且页面多次卡住,迫使我关闭浏览器并再次重新打开,没有执行任何方法,也没有可见的错误。有可能做我想做的事吗?是不是疯了?如果有可能我的错误在哪里?

作为额外信息,我正在使用 Barryvdh Laravel-omnipay 包从 Laravel 中处理 Omnipay。

【问题讨论】:

  • 我没有使用过 Omnipay,但 Express Checkout 需要重定向到 paypal,那么您如何在 AJAX 中处理它? XMLHTTPRequest 不会遵循 HTTP 重定向。
  • @prodigitalson 这正是发生的“没有重定向到 PayPal”所以我应该如何处理这个问题?如何将此代码放入 OctoberCMS 页面生命周期?这就是我正在通过 Ajax 而不是通常的方式
  • 我对OctoberCMS一无所知,但通常你不会通过ajax发出明确的请求。是否需要 ajax 是因为 CMS 还是您可以通过直接 POST 处理快速付款方式?
  • @prodigitalson 这是主要问题,他们有一个奇怪的流程,不像我之前所说的那样典型,我不想使用 Ajax 框架,但我不知道如何在组件
  • 好的,听起来你真正的问题需要是How do call a method inside a component in OctoberCMS? 因为我认为这就是这里必须发生的事情:-)

标签: php jquery ajax omnipay octobercms


【解决方案1】:

简要浏览文档后,我的最佳猜测是您缺少purchase() 方法的必填字段。我相信您需要一个 card 参数(即使它是无效的)来处理它。

【讨论】:

  • This 回答说不需要你在哪里读到的?为什么如果我通过 PayPal 付款,即使是伪造的,我也应该使用 CC?
  • 啊,你是对的。 card 不是必需的,抱歉。这是我在网关方法下找到的here 的必填字段:token, amount, currency, description, transactionId, clientIp, returnUrl, cancelUrl。道歉。
  • 嗯,我认为这不是问题所在,因为并非所有这些参数都是必需的。看看here,你只会看到一些,还有这个评论All gateway methods take an $options array as an argument. Each gateway differs in which parameters are required, and the gateway will throw InvalidRequestException if you omit any required parameters.在文档中我没有得到任何InvalidRequestException
  • 我现在明白了。没有阅读整个文档:/
  • 你有没有试过设置gateway(从your link开头)然后在上面调用购买方法?
猜你喜欢
  • 2016-10-17
  • 2018-04-12
  • 1970-01-01
  • 2020-09-21
  • 2017-08-09
  • 2021-02-26
  • 1970-01-01
  • 2018-04-17
  • 1970-01-01
相关资源
最近更新 更多