2015-12-12 94 views
3

我有測試代碼,但我如何配置PayPal支付?如何使用Omnipay for Laravel 5?

這是測試代碼,但如果我想用貝寶來做呢?我應該怎麼做?

$cardInput = [ 
     'number'  => '4444333322221111', 
     'firstName' => 'MR. WALTER WHITE', 
     'expiryMonth' => '03', 
     'expiryYear' => '16', 
     'cvv'   => '333', 
    ]; 

    $card = Omnipay::creditCard($cardInput); 
    $response = Omnipay::purchase([ 
     'amount' => '100.00', 
     'returnUrl' => 'http://bobjones.com/payment/return', 
     'cancelUrl' => 'http://bobjones.com/payment/cancel', 
     'card'  => $cardInput 
    ])->send(); 

    dd($response->getMessage()); 

這裏的文檔:https://github.com/ignited/laravel-omnipay

感謝的

回答

2

我建議你檢查出OmniPay docs對於這樣的問題,因爲這將讓您瞭解如何創建不同的供應商付款的參考點。

需要注意的是,除非你是在美國,你的用戶會被重定向到PayPal進入他們的信用卡詳細信息等

但作爲一個例子,它會是這個樣子是很重要的:

public function postPayment() 
    { 
      $params = array(
        'cancelUrl'  => 'http://localhost/cancel_order', 
        'returnUrl'  => 'http://localhost/payment_success', 
        'name'  => //Fetch product name, 
        'description' => //Fetch product description, 
        'amount' => //Fetch product price, 
        'currency' => //Fetch the currency 
      ); 

      Session::put('params', $params); 
      Session::save(); 

     $gateway = Omnipay::create('PayPal_Express'); 
     $gateway->setUsername('paypal account'); 
     $gateway->setPassword('paypal password'); 
     $gateway->setSignature('paypal-signature'); 

     $gateway->setTestMode(true); 

     $response = $gateway->purchase($params)->send(); 

從那裏您只需使用響應來確定如何處理付款。

雖然爲Laravel 4.2編寫,但this guide可能有助於指導您學習如何使用OmniPay。

+0

如果我們需要爲postPayment()編寫單元測試會怎麼樣? –