2015-12-12 57 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()编写单元测试会怎么样? –