Omnipay用SagePay服务器方法

时间:2014-07-14 11:04:17

标签: omnipay

有没有人有一个例子我可以使用Omnipay整合SagePay服务器集成方法(从网站上取款)?不幸的是,文档有点稀疏,我只是陷入混乱,我打算使用什么方法!

这是我的代码(我正在使用CodeIgniter):

use Omnipay\Omnipay;

class Payment_gateway extends CI_Controller {

//live details
private $live_merchant_id = 'xxx';
//test details
private $test_merchant_id = 'yyy';

//payment settings
private $test_mode = TRUE;
private $merchant_id = '';
private $gateway = NULL;

public function __construct() 
{
    parent::__construct();

    if ($this->test_mode) :
        $this->merchant_id = $this->test_merchant_id;
    else :
        $this->merchant_id = $this->live_merchant_id;
    endif;


    $this->gateway = Omnipay::create('SagePay_Server');
    $this->gateway->setVendor($this->merchant_id);
    $this->gateway->setTestMode($this->test_mode);
    $this->gateway->setSimulatorMode($this->test_mode);
}


public function index()
{

    $response = $this->gateway->Purchase();

    var_dump($response);

}
}

我使用上面的代码获得了一个响应对象。如果我尝试使用:

if ($response->isRedirect()) :
        $response->redirect(); // this will automatically forward the customer
else :
    // not successful
endif;

而是我收到错误:

致命错误:调用未定义的方法Omnipay \ SagePay \ Message \ ServerPurchaseRequest :: isRedirect()

如果我尝试使用:

$response = $this->gateway->Purchase()->send();

我收到一条消息,说明需要某些参数,所以如果我将它们添加到:

$response = $this->gateway->Purchase(array(
        'returnUrl' => 'http://www.madeupdomain.com/',
        'amount' => '10.00'
    ))->send();

我收到错误:

卡参数是必需的。

如果我尝试:

$response = $this->gateway->completePurchase(array(
        'transactionId' => 111,
        'transactionReference' => 'Online payment'
    ))->send();

我明白了:

来自支付网关的响应无效

更新 我错误解释了“卡参数是必需的”错误,因为我没有将任何信用卡详细信息传递给SagePay而不是我没有在完成购买功能中传递卡片数组,例如,我的索引功能应该如下所示:

public function index()
{    
$response = $this->gateway->Purchase(array(
        'description'=> 'Online order',
        'currency'=> 'GBP',
        'transactionId'=> mt_rand(99, 9999),
        'transactionReference' => 'test order',
        'amount'=> '1.00',
        'returnUrl' => 'http://www.test.com/returnURL/',
        'cancelUrl' => 'http://www.test.com/cancelURL/',
        'card' => array(
            'email' =>  'test@test.com',
            'clientIp' => '123.123.123.123',
            'firstName' => 'Joe',
            'LastName' => 'Bloggs',
            'billingAddress1' => 'Address 1',
            'billingAddress2' => 'Address 2',
            'billingCity' => 'City',
            'billingPostcode' => 'AB1 1BA',
            'billingCountry' => 'GB',
            'billingPhone' => '01234 567 890'
        )))->send();

     $response = $this->gateway->Purchase($this->params)->send();
   if ($response->isRedirect()) {
        $response->redirect();
    } else {
        echo '<pre> ';
        var_dump($response);
        echo '</pre> ';
        exit;
        }
    }

这给了我一个全新的问题,但我想我现在正在使用正确的功能。

0 个答案:

没有答案