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
|
$shopperArray = array(
"email" => "a.asdfg@yopmail.com",
"firstname" => "fghgh",
"lastname" => "alix",
"street" => "yourstreet",
"postalcode" => "12345",
"city" => "yourcity",
"telephone" => "1335484866",
"countrycode" => "IT"
);
$orderContent = '
<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. '. $shopperArray["lastname"] .',<br>'. $shopperArray["street"] .',<br>'. $shopperArray["postalcode"] .' '. $shopperArray["city"] .',<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. '. $shopperArray["lastname"] .',<br>'. $shopperArray["street"] .',<br>'. $shopperArray["postalcode"] .' '. $shopperArray["city"] .',<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 Global Services<br>This name may appear on your bank statement<br>http://www.asdfg.com</td></tr>
</table></center>
';
function StartXML() {
$this->xml = '
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE paymentService PUBLIC "-//test/DTD test PaymentService v1//EN" "http://dtd.test.com/ddd.dtd">
<paymentService version="1.4" merchantCode="'.$this->merchantCode.'">
<submit>
<order orderCode = "'.$this->orderId.'">
<description>'.$this->description.'</description>
<amount value="'.$this->totalammount.'" currencyCode = "EUR" exponent = "2">\n
';
}
function FillDataXML($invoiceData) {
$this->xml .= '
<orderContent>
<![CDATA['.$invoiceData.']]>
</orderContent>
<paymentMethodMask>
<include code="ALL"/>
</paymentMethodMask>
';
}
function FillShopperXML($shopperArray) {
$this->xml .= '
<shopper>
<shopperEmailAddress>'.$shopperArray["email"].'</shopperEmailAddress>
</shopper>
<shippingAddress>
<address>
<firstName>'.$shopperArray["firstname"].'</firstName>
<lastName>'.$shopperArray["lastname"].'</lastName>
<street>'.$shopperArray["street"].'</street>
<postalCode>'.$shopperArray["postalcode"].'</postalCode>
<city>'.$shopperArray["city"].'</city>
<countryCode>'.$shopperArray["countrycode"].'</countryCode>
<telephoneNumber>'.$shopperArray["telephone"].'</telephoneNumber>
</address>
</shippingAddress>\n
';
}
function EndXML() {
$this->xml .= '
</order>
</submit>
</paymentService>
';
}
$_bibit->StartXML();
$_bibit->FillDataXML($orderContent);
$_bibit->FillShopperXML($shopperArray);
$_bibit->EndXML();
$_bibit->xml = utf8_encode($_bibit->xml);
$bibitResult = $_bibit->CreateConnection();
$resultArray = array(
"currentTag" => "",
"orderCode" => "",
"referenceID" => "",
"errorcode" => "",
"url_togoto" => ""
);
function CreateConnection() {
$ch = curl_init ($this->url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->xml); //$xml is the xml string
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
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 Bibit
curl_close ($ch);
if ( $result == false )
print 'Curl could not retrieve page "'.$this->url.'", curl_exec returns false';
return $result;
}
ParseXML($bibitResult);
print "<p style=\"font-weight: bold;\">Reply from the bibit server:</p>";
echo "<pre>";
print_r($resultArray);
echo "</pre>";
function StartElement($parser, $name, $attrs)
{
global $resultArray;
$resultArray['currentTag'] = $name;
switch ($name) {
case "ERROR":
$resultArray['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":
$resultArray['referenceID'] = $attrs['ID'];//for storage in your own database
break;
case "ORDERSTATUS":
$resultArray['ordercode'] = $attrs['ORDERCODE'];
break;
default:
break;
}
}
function EndElement($parser, $name) {
global $resultArray;
$resultArray['currentTag'] = "";
}
function CharacterData($parser, $result) {
global $resultArray;
switch ($resultArray['currentTag']) {
case "REFERENCE":
//there is a REFERENCE so there must be an url which was provided by bibit for the actual payment. echo $result;
$resultArray['url_togoto'] = $result;
break;
default:
break;
}
}
function ParseXML($bibitResult) {
$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, $bibitResult))
{
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);
} |
Partager