2016-02-12 66 views
0

我使用这个包:如何用Laravel设置Omnipay?

https://github.com/barryvdh/laravel-omnipay

在我的控制器我说:

$params = [ 
      'amount' => '10', 
      'issuer' => 22, 
      'description' => 'desc', 
      'returnUrl' => URL::action('[email protected]', [43]), 
     ]; 
     $response = Omnipay::purchase($params)->send(); 

     if ($response->isSuccessful()) { 
      // payment was successful: update database 
      print_r($response); 
     } elseif ($response->isRedirect()) { 
      // redirect to offsite payment gateway 
      return $response->getRedirectResponse(); 
     } else { 
      // payment failed: display message to customer 
      echo $response->getMessage(); 
     } 

这里是我的omnipay.php的conf文件:

<?php 

return array(

    /** The default gateway name */ 
    'gateway' => 'PayPal_Express', 

    /** The default settings, applied to all gateways */ 
    'defaults' => array(
     'testMode' => true, 
    ), 

    /** Gateway specific parameters */ 
    'gateways' => array(
     'PayPal_Express' => array(
      'username' => '', 
      'landingPage' => array('billing', 'login'), 
     ), 
    ), 

); 

但得到这个错误:

call_user_func_array() expects parameter 1 to be a valid callback, class 'Omnipay\Common\GatewayFactory' does not have a method 'purchase'

任何人都可以帮我设置这个? 我在paypal上创建了应用程序,并且有关于它的详细信息,但不知道如何使用此API设置它...

回答

0

我建议您从PayPal Express切换到PayPal REST。它更新,并有更好的文档。

我已经浏览了laravel-omnipay软件包,我无法看到它的用例。我只是直接编码到omnipay包。

我建议您为每个事务创建一个唯一的事务ID,并将其作为returnUrl和cancelUrl的URL的一部分提供,以便您可以确定在返回和取消处理程序中处理的是哪个事务。

我认为你正在从字面上理解laravel-omnipay包中的例子。您不需要或不需要那些回显语句。您应该捕获purchase()的响应,即使它是redirectResponse并对其执行getTransactionReference()检查,因为稍后您将需要该事务引用,例如,进行交易查询。您应该在调用purchase()之前将其存储在您创建的交易记录中。

1

你可能在你的控制器使用

use Omnipay\Omnipay; 

,将其更改为

use Omnipay;