Я пытаюсь преобразовать запрос Cardinal XML API в PHP, чтобы я мог отправить запрос через Интернет. К сожалению, безуспешно, так как это дает мне следующую ошибку:
2010 Неверный формат запроса: пустой запрос
Я думаю, что я достигаю сервера, но что-то не так смой PHP-запрос.
Это мой PHP-код:
$soapUrl = "https://centineltest.cardinalcommerce.com/maps/txns.asp";
$xml_post_string =
"<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>
<soap:Body>
'cmpi_msg='
<CardinalMPI>
<MsgType>cmpi_lookup</MsgType>
<Version>1.7</Version>
<ProcessorId>252-01</ProcessorId>
<MerchantId>IVRTest</MerchantId>
<TransactionPwd>2h7mg3xN9JLQgQ</TransactionPwd>
<TransactionType>C</TransactionType>
<OrderNumber>CMY_IVR_Test1</OrderNumber>
<Amount>100</Amount>
<CurrencyCode>356</CurrencyCode>
<CardNumber>4000000000000002</CardNumber>
<CardExpMonth>05</CardExpMonth>
<CardExpYear>2020</CardExpYear>
<BillingFirstName>John</BillingFirstName>
<BillingLastName>Doe</BillingLastName>
<BillingAddress1>The Capital, C-70, G-Block</BillingAddress1>
<BillingAddress2/>
<BillingPhone>555-8675-309</BillingPhone>
<BillingCity>Mumbai</BillingCity>
<BillingState></BillingState>
<BillingPostalCode>400051</BillingPostalCode>
<BillingCountryCode>IN</BillingCountryCode>
<MessageCategory>01</MessageCategory>
<CategoryCode>01</CategoryCode>
<IPAddress>127.0.0.1</IPAddress>
<UserAgent>Jakarta Commons-HttpClient/3.1</UserAgent>
<Item_Name_1>iPod</Item_Name_1>
<Item_Desc_1>Apple iPod</Item_Desc_1>
<Item_Price_1>10000</Item_Price_1>
<Item_Quantity_1>1</Item_Quantity_1>
<Item_SKU_1>8675309</Item_SKU_1>
<DeviceChannel>browser</DeviceChannel>
<BrowserColorDepth>500</BrowserColorDepth>
<BrowserHeader>text/html,application/xhtml+xml,application/xml;q=0.9,</BrowserHeader>
<BrowserJavaEnabled>true</BrowserJavaEnabled>
<BrowserLanguage>English</BrowserLanguage>
<BrowserScreenHeight>980</BrowserScreenHeight>
<BrowserScreenWidth>1080</BrowserScreenWidth>
<BrowserTimeZone>-1:00</BrowserTimeZone>
<AuthenticationChannel>IVR</AuthenticationChannel>
<MobileIdFormat>I</MobileIdFormat>
<MobileId/>
<PareqChannel>Direct value</PareqChannel>
<ShoppingChannel>IVR</ShoppingChannel>
<TtpCredential/>
</CardinalMPI>
</soap:Body>
</soap:Envelope>";
$headers = array(
"POST /package/package_1.3/packageservices.asmx HTTP/1.1",
"Host: cybersource.cardinalcommerce.com",
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: ".strlen($xml_post_string)
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = simplexml_load_string($response2);
?>
Я заблудился о том, как кодировать параметр cmpi_msg, так как я впервые увидел запрос XML внутри параметра,Но чтобы отправить запрос в Centinel, мне нужно передать сообщение www-form-urlencoded в параметре cmpi_msg.
Когда я использую POSTMAN и отправляю тот же запрос, как показано ниже, я могу получитьуспешный ответ.
cmpi_msg='<CardinalMPI>
<MsgType>cmpi_lookup</MsgType>
<Version>1.7</Version>
<ProcessorId>252-01</ProcessorId>
<MerchantId>IVRTest</MerchantId>
<TransactionPwd>2h7mg3xN9JLQgQ</TransactionPwd>
<TransactionType>C</TransactionType>
<OrderNumber>CMY_IVR_Test1</OrderNumber>
<Amount>100</Amount>
<CurrencyCode>356</CurrencyCode>
<CardNumber>4000000000000002</CardNumber>
<CardExpMonth>05</CardExpMonth>
<CardExpYear>2020</CardExpYear>
<BillingFirstName>John</BillingFirstName>
<BillingLastName>Doe</BillingLastName>
<BillingAddress1>The Capital, C-70, G-Block</BillingAddress1>
<BillingAddress2/>
<BillingPhone>555-8675-309</BillingPhone>
<BillingCity>Mumbai</BillingCity>
<BillingState></BillingState>
<BillingPostalCode>400051</BillingPostalCode>
<BillingCountryCode>IN</BillingCountryCode>
<MessageCategory>01</MessageCategory>
<CategoryCode>01</CategoryCode>
<IPAddress>127.0.0.1</IPAddress>
<UserAgent>Jakarta Commons-HttpClient/3.1</UserAgent>
<Item_Name_1>iPod</Item_Name_1>
<Item_Desc_1>Apple iPod</Item_Desc_1>
<Item_Price_1>10000</Item_Price_1>
<Item_Quantity_1>1</Item_Quantity_1>
<Item_SKU_1>8675309</Item_SKU_1>
<DeviceChannel>browser</DeviceChannel>
<BrowserColorDepth>500</BrowserColorDepth>
<BrowserHeader>text/html,application/xhtml+xml,application/xml;q=0.9,</BrowserHeader>
<BrowserJavaEnabled>true</BrowserJavaEnabled>
<BrowserLanguage>English</BrowserLanguage>
<BrowserScreenHeight>980</BrowserScreenHeight>
<BrowserScreenWidth>1080</BrowserScreenWidth>
<BrowserTimeZone>-1:00</BrowserTimeZone>
<AuthenticationChannel>IVR</AuthenticationChannel>
<MobileIdFormat>I</MobileIdFormat>
<MobileId/>
<PareqChannel>Direct value</PareqChannel>
<ShoppingChannel>IVR</ShoppingChannel>
<TtpCredential/>
</CardinalMPI>'
Так что я думаю, что моя единственная ошибка связана с указанием параметра cmpi_msg. Надеюсь, вы можете помочь! Заранее спасибо!