Example #1
0
 /**
  *	Parses a string into an EXactLineItem.
  *
  *	\param [in] $str
  *		The string to parse.
  *
  *	\return
  *		An EXactLineItem object.
  */
 public static function ParseLineItem($str)
 {
     if (!is_string($str)) {
         throw new \InvalidArgumentException(sprintf('Expected $str to be a string, got %s', \CivicInfoBC\Reflection::GetType($str)));
     }
     $arr = \CivicInfoBC\Regex::Match('/^(.*?)<\\|>(.*?)<\\|>(.*?)<\\|>(\\d+?)<\\|>(\\d+?(?:\\.\\d{2}))<\\|>((?:yes|no))<\\|>$/ui', $str);
     if (is_null($arr)) {
         throw new \InvalidArgumentException(sprintf('Failed to parse "%s" as E-Xact line item', $str));
     }
     $retr = new EXactLineItem();
     //	Does it make sense for these values to be null?
     //	Assuming "yes" for now
     $retr->id = self::filter($arr[1]);
     $retr->name = self::filter($arr[2]);
     $retr->description = self::filter($arr[3]);
     $retr->quantity = intval($arr[4]);
     $retr->price = floatval($arr[5]);
     $retr->taxable = \CivicInfoBC\String::Equals($arr[6], 'yes', true);
     return $retr;
 }
 private static function message($type, $str)
 {
     //	Beanstream returns a completely insane error message format
     //	on user errors:
     //
     //	-	Each error message is preceded by "<LI>", which could be
     //		construed as an attempt to make an HTML list with each
     //		error as an element, but there's no "</LI>", so I'm unsure
     //		what it's actually for
     //	-	Each error is separated by "<br>", which is perhaps supposed
     //		to put them each on their own line, but they're each supposed
     //		to be a list item (see above), so why would this ever be necessary?
     //		Plus if there's only one error it will be followed by a "<br>" anyway,
     //		which is almost as degenerate as the fact that libpq puts CRLF at
     //		the end of its error messages
     //
     //	So even if returning HTML error messages to an API wasn't
     //	completely abominable (having to run a weird recursive search
     //	for text nodes using libxml on your error messages to get something
     //	that can be portably/conveniently displayed in mediums other than
     //	the browser is a good sign of degeneracy) the "HTML" (no closing <LI>
     //	tag means it's not actually HTML, since HTML requires paired opening
     //	and closing tags) makes no sense, therefore we sanitize it out.
     if ($type !== 'user') {
         return $str;
     }
     //	Remove the <LI> tags
     $str = \CivicInfoBC\Regex::Replace('/<li>/ui', '', $str);
     //	Remove the <br> tags and the white space around them
     //	and replace with LF
     $str = \CivicInfoBC\Regex::Replace('/\\s*<br>\\s*/ui', "\n", $str);
     //	Remove the trailing LF
     $str = \CivicInfoBC\Regex::Replace('/\\n$/u', '', $str);
     return $str;
 }
 private function beanstream_user_error(\CivicInfoBC\Beanstream\Transaction $trans)
 {
     $arr = \CivicInfoBC\Regex::Split('/\\r?\\n/u', $trans->beanstream->message);
     return $this->templates->CreateForm($trans, $arr);
 }