Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
transaction_dataset.inc
1 <?php
29 {
30 
36  private $_transaction;
37 
43  private $_purchaser;
44 
45 
51  private $_line_items;
52 
53 
59  private $_line_item_count;
60 
65  function __construct()
66  {
67  $this->_line_item_count = 0;
68 
69  }//end constructor
70 
71 
79  {
80 
81  $line_items = Array();
82 
83  foreach($this->_line_items as $id => $line_item) {
84  $line_items["LineItem id=\"".$id."\""] = $line_item;
85  }
86 
87  $dataset = Array(
88  "NewTransactionDataset" => Array(
89  "Purchaser" => $this->_purchaser,
90  "Transaction" => $this->_transaction,
91  "0" => $line_items,
92  ),
93  );
94 
95  return $dataset;
96  }
97 
105  {
106  // Get the new transaction XSD content
107  $new_transaction_xsd = $this->_getNewTransactionXSD();
108 
109  // Get the new transaction xml namespace from the xsd content and add it to the new transaction dataset
110  preg_match('|xmlns="(.*?)"|msi', $new_transaction_xsd, $match);
111  $xml_ns = (isset($match[1])) ? $match[1] : '';
112 
113  // Get the new transaction dataset in XML format
114  $new_transaction_dataset = $this->_convertToXML($this->getTransactionDatasetArray());
115 
116 
117  if ($xml_ns) {
118  $new_transaction_dataset = str_replace("<NewTransactionDataset>", "<NewTransactionDataset xmlns=\"$xml_ns\">", $new_transaction_dataset);
119  }
120 
121  return $new_transaction_xsd.$new_transaction_dataset;
122  }
123 
124 
148  function _convertToXML($str)
149  {
150  if (!is_array($str))
151  return $str;
152 
153  $xml = '';
154  foreach($str as $key => $value) {
155  if (is_int($key))
156  $xml .= $this->_convertToXML($value);
157  else
158  $xml .= "\n<$key>".$this->_convertToXML($value)."</".preg_replace('|\s.*$|', '', $key).">";
159  }
160 
161  return $xml;
162  }
163 
164 
180  function addPurchaserRow($fname, $sname, $email, $address1, $address2, $suburb, $city, $postcode)
181  {
182  $this->_purchaser = Array(
183  0 => Array(
184  "Firstname" => $fname,
185  "Surname" => $sname,
186  "AddressLine1" => $address1,
187  "City" => $city,
188  ),
189  );
190 
191  // These fields are not mandatory
192  if (!empty($email)) {
193  $this->_purchaser[0]["Email"] = $email;
194  }
195  if (!empty($address2)) {
196  $this->_purchaser[0]["AddressLine2"] = $address2;
197  }
198  if (!empty($suburb)) {
199  $this->_purchaser[0]["Suburb"] = $suburb;
200  }
201  if (!empty($postcode)) {
202  $this->_purchaser[0]["Postcode"] = $postcode;
203  }
204 
205  return TRUE;
206  }
207 
208 
223  function addTransactionRow($reference_id, $credit_card, $expiry_date, $card_holder_name, $merchant_id='', $payment_model='', $gst_rate=0)
224  {
225  $this->_transaction = Array(
226  0 => Array(
227  "ReferenceId" => $reference_id,
228  "CreditCard" => $credit_card,
229  "ExpiryDate" => $expiry_date,
230  "CardHolderName" => $card_holder_name,
231  "GstRate" => $gst_rate,
232  ),
233  );
234 
235 
236  // MerchantId and PaymentModel are not mandatory fields
237  if (!empty($merchant_id)) {
238  $this->_transaction[0]['MerchantId'] = $merchant_id;
239  }
240  if (!empty($payment_model)) {
241  $this->_transaction[0]['PaymentModel'] = $payment_model;
242  }
243 
244  return TRUE;
245  }
246 
247 
266  function addLineItemRow($application_username, $name, $description, $quantity, $refund_type, $refund_expiry_date, $amount, $product_code, $financial_code, $financial_values, $additional_info)
267  {
268  // Set the refernece id based on the transaction reference id
269  $reference_id = $this->_transaction[0]['ReferenceId'].'/'.$this->_line_item_count++;
270 
271  $line_item_dataset = Array(
272  "ReferenceId" => $reference_id,
273  "Name" => $name,
274  "Description" => $description,
275  "Quantity" => $quantity,
276  "RefundType" => $refund_type,
277  "Amount" => $amount,
278  );
279 
280  // These fields are not mandatory
281  if (!empty($application_username)) {
282  $line_item_dataset["ApplicationUsername"] = $application_username;
283  }
284  if (!empty($refund_expiry_date)) {
285  $line_item_dataset["RefundExpiryDate"] = $refund_expiry_date;
286  }
287  if (!empty($product_code)) {
288  $line_item_dataset["ProductCode"] = $product_code;
289  }
290  if (!empty($financial_code)) {
291  $line_item_dataset["FinancialCode"] = $financial_code;
292  }
293  if (!empty($financial_values)) {
294  $line_item_dataset["FinancialValues"] = $financial_values;
295  }
296  if (!empty($additional_info)) {
297  $line_item_dataset["AdditionalInfo"] = $additional_info;
298  }
299 
300  $this->_line_items[$reference_id] = $line_item_dataset;
301 
302  return TRUE;
303 
304  }
305 
306 
314  {
315  $new_transaction_xsd = <<<XSD_CONTENT
316 
317 <xs:schema id="Transaction" targetNamespace="http://www.paymentgateway.co.nz/_schemas/Transaction.xsd"
318 elementFormDefault="qualified" attributeFormDefault="qualified"
319 xmlns="http://www.paymentgateway.co.nz/_schemas/Transaction.xsd"
320 xmlns:mstns="http://www.paymentgateway.co.nz/_schemas/Transaction.xsd"
321 xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
322 <xs:element name="NewTransactionDataset" msdata:IsDataSet="true">
323 <xs:complexType>
324 <xs:choice maxOccurs="unbounded">
325 <xs:element name="Purchaser">
326 <xs:complexType>
327 <xs:sequence>
328 <xs:element name="Firstname" type="xs:string" />
329 <xs:element name="Surname" type="xs:string" />
330 <xs:element name="Email" type="xs:string" minOccurs="0" />
331 <xs:element name="AddressLine1" type="xs:string" />
332 <xs:element name="AddressLine2" type="xs:string" minOccurs="0" />
333 <xs:element name="Suburb" type="xs:string" minOccurs="0" />
334 <xs:element name="City" type="xs:string" />
335 <xs:element name="PostCode" type="xs:int" minOccurs="0" />
336 </xs:sequence>
337 </xs:complexType>
338 </xs:element>
339 <xs:element name="Transaction">
340 <xs:complexType>
341 <xs:sequence>
342 <xs:element name="ReferenceId" type="xs:string" />
343 <xs:element name="CreditCard" type="xs:string" />
344 <xs:element name="ExpiryDate" type="xs:string" />
345 <xs:element name="CardHolderName" type="xs:string" />
346 <xs:element name="MerchantId" type="xs:int" minOccurs="0" />
347 <xs:element name="PaymentModel" type="xs:string" minOccurs="0" />
348 <xs:element name="GstRate" type="xs:decimal" minOccurs="0" />
349 </xs:sequence>
350 </xs:complexType>
351 </xs:element>
352 <xs:element name="LineItem">
353 <xs:complexType>
354 <xs:sequence>
355 <xs:element name="ReferenceId" type="xs:string" />
356 <xs:element name="ApplicationUsername" type="xs:string" minOccurs="0" />
357 <xs:element name="Name" type="xs:string" />
358 <xs:element name="Description" type="xs:string" />
359 <xs:element name="Quantity" type="xs:int" />
360 <xs:element name="RefundType" type="xs:string" />
361 <xs:element name="RefundExpiryDate" type="xs:dateTime" minOccurs="0" />
362 <xs:element name="Amount" type="xs:decimal" />
363 <xs:element name="ProductCode" type="xs:string" minOccurs="0" />
364 <xs:element name="FinancialCode" type="xs:string" minOccurs="0" />
365 <xs:element name="FinancialValues" type="xs:string" minOccurs="0" />
366 <xs:element name="AdditionalInfo" type="xs:string" minOccurs="0" />
367 </xs:sequence>
368 </xs:complexType>
369 </xs:element>
370 </xs:choice>
371 </xs:complexType>
372 <xs:key name="NewTransactionDatasetKey1" msdata:PrimaryKey="true">
373 <xs:selector xpath=".//mstns:LineItem" />
374 <xs:field xpath="mstns:ReferenceId" />
375 </xs:key>
376 <xs:key name="NewTransactionDatasetKey2" msdata:PrimaryKey="true">
377 <xs:selector xpath=".//mstns:Transaction" />
378 <xs:field xpath="mstns:ReferenceId" />
379 </xs:key>
380 </xs:element>
381 </xs:schema>
382 
383 XSD_CONTENT;
384 
385  return $new_transaction_xsd;
386 
387  }//end _getNewTransactionXSD()
388 
389 
390 }//end class
391 
392 ?>