2016-02-12 105 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;