我正在寫一個PHP腳本,將信用卡&客戶詳細信息發送到我的網站,將這些詳細信息無形地發送到Worldpay的服務器進行處理,然後根據響應(付費,失敗等)採取行動。Worldpay直接XML PHP集成
我的問題是,我發送我的XML時似乎無法使用Worldpay進行身份驗證 - 我用適當的商家代碼替換了MYMERCHANTCODE
。這是我使用的代碼 - 它是基於Worldpay's example:
require_once 'HTTP/Request.php';
$xml='<?xml version="1.0"? encoding="UTF-8"?>
<!DOCTYPE paymentService PUBLIC "-//WorldPay//DTD WorldPay PaymentService v1//EN""http://dtd.worldpay.com/paymentService_v1.dtd">
<paymentService version="1.4" merchantCode="MYMERCHANTCODE">
<submit>
<order orderCode="T0211010">
<description>20 Tulip Bulbs from MYMERCHANT Webshops</description>
<amount value="2600" currencyCode="EUR" exponent="2"/>
<paymentDetails>
<VISA-SSL>
<cardNumber>4444333322221111</cardNumber>
<expiryDate>
<date month="09" year="2009"/>
</expiryDate>
<cardHolderName>J. Shopper</cardHolderName>
<cvc>123</cvc>
<cardAddress>
<address>
<street>47A Queensbridge Rd</street>
<postalCode>CB94BQ</postalCode>
<countryCode>GB</countryCode>
</address>
</cardAddress>
</VISA-SSL>
<session shopperIPAddress="123.123.123.123" id="0215ui8ib1" />
</paymentDetails>
<shopper>
<shopperEmailAddress>[email protected]</shopperEmailAddress>
<browser> [This example uses firefox 3.5.5 to demonstrate]
<acceptHeader>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</acceptHeader>
<userAgentHeader>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)</userAgentHeader>
</browser>
</shopper>
</order>
</submit>
</paymentService>';
$dest='https://secure-test.wp3.rbsworldpay.com/jsp/merchant/xml/paymentService.jsp'; //for sandbox
//$dest='https://secure.wp3.rbsworldpay.com/jsp/merchant/xml/paymentService.jsp' //for production
$req =& new HTTP_Request($dest);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader('Connection', 'keep-alive');
$req->addRawPostData($xml);
$req->sendRequest();
$req->getResponseBody();
echo nl2br(htmlentities($req->getResponseBody()));
當我運行這個,這是什麼是輸出:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
是否有人可以幫助這一點?該文件說,將您的IP地址添加到您的Worldpay帳戶的請求中,我認爲我已經正確地完成了該請求。
非常感謝
UPDATE:
我剛剛意識到,如果我的網址前,如加我的商家ID & XML密碼:
$dest='https://MERCHANTID:[email protected]/jsp/merchant/xml/paymentService.jsp';
然後它認證,所以我會回答我自己的問題。
嗨,我也嘗試使用XML的直接方法來實現在PHP網站WorldPay工作,但每當我嘗試連接,我得到錯誤說您無權查看該文件..你能告訴我是你測試本地主機上的支付網關。 – user434509
不,我正在一個正確的域上的活服務器上測試它。讓我知道,如果我可以進一步幫助。 – SammyBlackBaron
@SammyBlackBaron商戶ID是大寫的呀? –