将Sagepay集成到Zend中


Integrating Sagepay into Zend

我目前有一个需要Sagepay集成的网站,以前的网站已经成功集成了sagepay,但是没有一个使用Zend,不幸的是,没有那么多关于将Zend与Sagepay一起使用的文档,但是我找到了一个模块可以在此链接中工作:

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

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

由于Sagepay API只是通过一堆curl请求访问的,因此您可以使用Zends客户端和请求对象。例如:

定义您要发布的数据 -

// 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;

通读一下可能会有所帮助。