debugLog; } /** * Function to create debug line * * @param string $title * @param string $json * @param string $xml */ public function createDebugLine($title, $json = null, $xml = null) { $datetime = date("Y-m-d H:i:s"); $this->debugLog .= $datetime . ': ' . $title . "\n"; if (!is_null($json)) { $this->debugLog .= json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) . "\n"; } if (!is_null($xml)) { $out = $this->formatXmlString($xml); $this->debugLog .= print_r($out, true) . "\n"; } $this->debugLog .= "\n"; } /** * Function markup xml to make it readable in debug * * @param string $xml */ private function formatXmlString($xml) { $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml); $token = strtok($xml, "\n"); $result = ''; $pad = 0; $matches = array(); while ($token !== false) : if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) : $indent=0; elseif (preg_match('/^<\/\w/', $token, $matches)) : $pad--; $indent = 0; elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) : $indent = 1; else : $indent = 0; endif; $line = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT); $result .= $line . "\n"; $token = strtok("\n"); $pad += $indent; endwhile; return $result; } /** * Manually assign order country, this overrides value that is set in order data * Since we have default value stored in $country field, to preserve compatibility, use another field to track * selected country preference * @param $country */ public function setCountry($country) { $this->selectedCountry = strtoupper($country); } /** * Assign order country from address data if not set explicitly by services method call * By default is set to NL during object initialization * * @param $order */ public function resolveOrderCountry($order) { if (!$this->selectedCountry) { switch ($order['billtoaddress']['isocountrycode']) { case 'BE': $this->country = 'BE'; break; case 'DE': $this->country = 'DE'; break; case 'CH': $this->country = 'CH'; break; case 'AT': $this->country = 'AT'; break; case 'SE': $this->country = 'SE'; break; case 'FI': $this->country = 'FI'; break; case 'NO': $this->country = 'NO'; break; case 'DK': $this->country = 'DK'; break; } } else { $this->country = $this->selectedCountry; } } }