DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Trying To Use REST Method’s For POLi Integration In PHP , CURL

09.17.2008
| 4060 views |
  • submit to reddit
        // description of your code here

Does any body have an example of how we can use REST method for POLi payment gateway integration ? I have used CURL to send my request which is in XML format but is unable to get the proper response. the example which I tried is 
$xmlRequest = '
<?xml version="1.0" encoding="iso-8859-1"?>
<InitiateTransactionRequest xmlns="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <AuthenticationCode>xxx!</AuthenticationCode>
  <Transaction xmlns:dco="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.DCO">
    <dco:CurrencyAmount>1.00</dco:CurrencyAmount>
    <dco:CurrencyCode>AUD</dco:CurrencyCode>
    <dco:MerchantCheckoutURL>http://localhost/test/checkout</dco:MerchantCheckoutURL>
    <dco:MerchantCode>yyy</dco:MerchantCode>
    <dco:MerchantData>MerchantDataAssociatedWithTransaction</dco:MerchantData>
    <dco:MerchantDateTime>25 August 2008 14:31:32</dco:MerchantDateTime>
    <dco:MerchantHomePageURL>http://localhost/test/home</dco:MerchantHomePageURL>
    <dco:MerchantRef>MerchantReferenceAssociateWithTransaction</dco:MerchantRef>
    <dco:NotificationURL>http://localhost/test/notification</dco:NotificationURL>
    <dco:SelectedFICode i:nil="true" />
    <dco:SuccessfulURL>http://localhost/test/successful</dco:SuccessfulURL>
    <dco:Timeout>1000</dco:Timeout>
    <dco:UnsuccessfulURL>http://localhost/test/unsuccessful</dco:UnsuccessfulURL>
    <dco:UserIPAddress>192.100.100.42</dco:UserIPAddress>
  </Transaction>
</InitiateTransactionRequest>';

/* Use CURL to execute XML POST and write output into a string */

$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($xmlRequest) . "\r\n";
$header[] = $xmlRequest;
 
$ch = curl_init();

$fh = fopen('error.txt', 'w');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fh); 

curl_setopt( $ch, CURLOPT_URL, "http://merchantapi.rega-staging.polipayments.com/MerchantAPIService.svc/Xml/transaction/initiate"); # URL to post to
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); # This POST is special, and uses its specified Content-type
curl_setopt( $ch, CURLOPT_ERRORBUFFER, 1);
$result = curl_exec( $ch ); # run!
 
echo $result;

fclose($fh);
echo "<pre>".file_get_contents('error.txt').'</pre>';
unlink('error.txt'); 

curl_close($ch); 


I am getting the output 

* About to connect() to merchantapi.rega-staging.polipayments.com port 80 (#0)
*   Trying 212.188.185.73... * connected
* Connected to merchantapi.rega-staging.polipayments.com (212.188.185.73) port 80 (#0)
> POST /MerchantAPIService.svc/Xml/transaction/initiate HTTP/1.1
Host: merchantapi.rega-staging.polipayments.com
Accept: */*
Content-type: text/xml
Content-length: 1351

  xxx
  
    1.00
    AUD
    http://localhost/test/checkout
    yyy
    MerchantDataAssociatedWithTransaction
    25 August 2008 14:31:32
    http://localhost/test/home
    MerchantReferenceAssociateWithTransaction
    http://localhost/test/notification
    
    http://localhost/test/successful
    1000
    http://localhost/test/unsuccessful
    x.x.x.x
 
< HTTP/1.1 400 Bad Request
< Via: 1.1 DCSERVER
< Connection: Keep-Alive
< Proxy-Connection: Keep-Alive
< Content-Length: 0
< Date: Wed, 17 Sep 2008 04:46:51 GMT
< Server: Microsoft-IIS/6.0
< X-AspNet-Version: 2.0.50727
< Cache-Control: private
* Connection #0 to host merchantapi.rega-staging.polipayments.com left intact
    

Comments

Snippets Manager replied on Tue, 2009/03/03 - 5:56am

POLi gateway integration is also what I am looking for. I it there must be a way to use CURL for a request with lotus notes integration which will run the code in a XML pattern.

Snippets Manager replied on Sat, 2008/10/04 - 5:26am

Hi, You can avoid Bad Request error by adding below 2 lines curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); but after that it shows another error which i m not able to solve that is HTTP/1.1 404 Not Found If any one can help us then it would be nice