将Sagepay整合到Zend中

时间:2013-09-10 08:22:50

标签: php zend-framework payment-gateway sagepay

我目前有一个网站需要Sagepay集成,之前的网站已经成功集成了sagepay,但没有人使用过Zend,遗憾的是没有那么多关于使用Zend和Sagepay的文档,但是我发现了一个可以在这个链接:

http://code.google.com/p/zend-service-sagepay/source/browse/trunk/library/My/Sagepay.php?r=2

在这种情况下最佳做法是什么,我知道Sagepay提供了多种处理付款的方法,尽管它与网站集成得越多越好。

1 个答案:

答案 0 :(得分:1)

由于Sagepay API只是通过一堆curl请求访问,您可以使用Zends Client和Request对象。例如:

定义您要发布的数据 -

// Set the post data
$data = array(
    'VPSProtocol'       =>  '',
    'TxType'            =>  '',
    'Vendor'            =>  '',
    'VendorTxCode'      =>  '',
    'Amount'            =>  '',
    'Currency'          =>  '',
    'Description'       =>  '',
    'CardHolder'        =>  '',
    'CardNumber'        =>  '',
    'StartDate'         =>  '',
    'ExpiryDate'        =>  '',
    'IssueNumber'       =>  '',
    'CV2'               =>  '',
    'CardType'          =>  '',
    'AuthCode'          =>  '',
    'BillingSurname'    =>  '',
    'BillingFirstNames' =>  '',
    'BillingAddress1'   =>  '',
    'BillingAddress2'   =>  '',
    'BillingCity'       =>  '',
    'BillingPostCode'   =>  '',
    'BillingCountry'    =>  '',
    'BillingPhone'      =>  '',
    'DeliverySurname'   =>  '',
    'DeliveryFirstNames'=>  '',
    'DeliveryAddress1'  =>  '',
    'DeliveryAddress2'  =>  '',
    'DeliveryCity'      =>  '',
    'DeliveryPostCode'  =>  '',
    'DeliveryCountry'   =>  '',
    'DeliveryPhone'     =>  '',
    'CustomerEmail'     =>  '',
    'NotificationUrl'   =>  ''
)

然后创建新的客户端对象并将适配器设置为'CURL' -

$client = new Client();
$client->setAdapter(new Curl());

最后创建一个新的请求对象,并将客户端对象分派给请求。

$request = new Request();
$request->setUri('https://test.sagepay.com/gateway/service/vspdirect-register.vsp');
$request->setMethod(Request::METHOD_POST);
$request->setContent(http_build_query($data));

$response = $client->dispatch($request);
var_dump($response);
die;

通读this可能有所帮助。