1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
<?php
$merchantCode="teste"; // Don't put this in a public readable place
$password="test"; // Don't put this in a public readable place
$orderCode="example".time();
// Shopper specific details
$shopperEmailAddress="alix@yopmail.com";
$shopperID="shopper-123456";
$firstName="John";
$lastName="Doe";
$shopperStreet="11 Hereortherestreet";
$postalCode="1234 KL";
$shopperCity="myCiti";
$shopperTelephone="00123456789";
$countryCode="TP";
$url ="https://url-de-test.jsp";//it is better to keep this url outside your HTML dir which has public (internet) access
//$xml is the order string to send to bibit
$xml="
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE paymentService PUBLIC '-//test/DTD test PaymentService v1//EN' 'http://dtd.teste.com/paymentService_v1.dtd'>
<paymentService version='1.0' merchantCode='teste'>
<submit>
<order orderCode = '".time()."'>
<description>PDD webshop</description>
<amount value='1982' currencyCode = 'EUR' exponent = '2'/>
<orderContent>
<![CDATA[
<center><table>
<tr><td bgcolor='#CCCCCC'>Your Internet Order:</td><td colspan='2' bgcolor='#ffff00' align='right'>AY 845</td></tr>
<tr><td bgcolor='#ffff00'>Description:</td><td>14 Tulip bulbs</td><td align='right'>1,00</td></tr>
<tr><td colspan='2'>Subtotal:</td><td align='right'>14,00</td></tr>
<tr><td colspan='2'>VAT: 13%</td><td align='right'>1,82</td></tr>
<tr><td colspan='2'>Shipping and Handling:</td><td align='right'>4,00</td></tr>
<tr><td colspan='2' bgcolor='#c0c0c0'>Total cost:</td><td bgcolor='#c0c0c0' align='right'>Euro 19,82</td></tr>
<tr><td colspan='3'> </td></tr>
<tr><td bgcolor='#ffff00' colspan='3'>Your billing address:</td></tr>
<tr><td colspan='3'>Mr. $lastName,<br>$shopperStreet,<br>$postalCode $shopperCity,<br>Thisplace.</td></tr>
<tr><td colspan='3'> </td></tr>
<tr><td bgcolor='#ffff00' colspan='3'>Your shipping address:</td></tr>
<tr><td colspan='3'>Mr. $lastName,<br>$shopperStreet,<br>$postalCode $shopperCity,<br>Thisplace.</td></tr>
<tr><td colspan='3'> </td></tr>
<tr><td bgcolor='#ffff00' colspan='3'>Our contact information:</td></tr>
<tr><td colspan='3'>ACME Webshops Int. Inc.,<br>11 Strangewood Blv.,<br>1255 KZ Thisisit,<br>Nowhereatall.<br><br>acmeweb@acme.inc<br>(555) 1235 456</td></tr>
<tr><td colspan='3'> </td></tr>
<tr><td bgcolor='#c0c0c0' colspan='3'>Billing notice:</td></tr>
<tr><td colspan='3'>Your payment will be handled by test Global Payments Services<br>This name may appear on your bank statement<br>http://www.teste.com</td></tr>
</table></center>
]]>
</orderContent>
<paymentMethodMask>
<include code='ALL'/>
</paymentMethodMask>
<shopper>
<shopperEmailAddress>$shopperEmailAddress</shopperEmailAddress> <authenticatedShopperID>$shopperID</authenticatedShopperID>
</shopper>
<shippingAddress>
<address>
<firstName>$firstName</firstName>
<lastName>$lastName</lastName>
<street>$shopperStreet</street>
<postalCode>$postalCode</postalCode>
<city>$shopperCity</city>
<countryCode>$countryCode</countryCode>
<telephoneNumber>$shopperTelephone</telephoneNumber>
</address>
</shippingAddress>
</order>
</submit>
</paymentService>";
//$xml is the order string to send to bibit
//let's make the socket connection
//make socket connection with bibit
//the curl library is used. make sure you have it installed propperly
// more info: http://www.php.net/manual/en/ref.curl.php
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$xml); //$xml is the xml string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
// echo "ch: $ch<HR>" ;
$result = curl_exec ($ch); // result will contain XML reply from test curl_close ($ch);
if ( $result == false )
{
$this->error = "Curl could not retrieve page '$this->url', curl_exec returns false";
return $result;
}
//now we have the result from test containing the xml answer. we need to parse this through the XML parser
// initialize parser //using SAX parser
//
//more info on SAX/PHP on these urls
// http://www.devshed.com/Server_Side/XML/XMLwithPHP/XMLwithPHP1/page1.html
// http://www.php.net/manual/en/ref.xml.php
function startElement($parser, $name, $attrs)
{
global $currentTag,$ordercode,$referenceID,$errorcode,$url_togoto;
$currentTag = $name;
switch ($name) {
case "ERROR":
/*
THERE IS AN XML ERROR REPLY
1 : internal error, could be everything
2 : parse error, invalid xml
3 : invalid number of transactions in batch
4 : security error
5 : invalid request
6 : invalid content, occurs when xml is valid but content of xml not
7 : payment details in the order element are incorrect
*/
$errorcode = $attrs['CODE']; //example of how to catch the error code number (i.e. 1 to 7)
$url_error="error_order.php";
break;
case "REFERENCE":
$referenceID = $attrs['ID'];//for storage in your own database
break;
case "ORDERSTATUS":
$ordercode = $attrs['ORDERCODE'];
break;
default:
break;
}
}
//////////////////
function endElement($parser, $name) {
global $currentTag;
$currentTag = "";
}
/////////////////
function characterData($parser, $result) {
global $currentTag;
global $url_togoto;
switch ($currentTag) {
case "REFERENCE":
//there is a REFERENCE so there must be an url which was provided by test for the actual payment. echo $result;
$url_togoto=$result;
break;
default:
break;
}
}
global $currentTag,$ordercode,$referenceID,$errorcode,$url_togoto;//define globals
$xml_parser = xml_parser_create();
// set callback functions
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $result))
{
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
// clean up
xml_parser_free($xml_parser);
//now we have a few important variables. Depending on what variables are set you can now perform an action like storing id's in your database or refer to a different url.
echo "ordercode=$ordercode<BR>";
echo "referenceID=$referenceID<BR>";
echo "errorcode=$errorcode<BR>";
echo "url_togoto=$url_togoto<BR>";
?> |
Partager