private static function check($obj, $key) { if (!isset($obj->{$key})) { throw new \RuntimeException(sprintf('Beanstream response did not include "%s"', $key)); } if (!is_string($obj->{$key})) { throw new \RuntimeException(sprintf('Beanstream response contains "%s" as %s, expected string', $key, \CivicInfoBC\Reflection::GetType($obj->{$key}))); } }
private static function send_impl(Transaction $trans, $obj) { $body = \CivicInfoBC\Form::Encode($obj); try { return self::send_impl_impl($trans, $body); } catch (\Exception $e) { $result = new EXactError(); $result->request = $body; $result->type = \CivicInfoBC\Reflection::GetType($e); $result->code = $e->getCode(); $result->message = $e->getMessage(); $trans->exact = $result; return false; } }
public function CreateReceipt(Transaction $trans) { $result = $trans->beanstream; if (!($result instanceof BeanstreamSuccess || $result instanceof BeanstreamFailure)) { throw new \LogicException(sprintf('Cannot create a receipt for %s', \CivicInfoBC\Reflection::GetType($result))); } $hco = $trans->hosted_checkout; $master = $this->get_master($hco->title); $p = $this->get_payment($hco); $inner = $this->get('receipt'); $master->inner = $p; $p->inner = $inner; $inner->transaction = $trans; $inner->metadata = $this->get_metadata($trans); return $master; }
/** * 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; }
public function SaveTransaction(\CivicInfoBC\Beanstream\Transaction $t) { $m = $t->metadata; if (!is_object($m)) { throw new \LogicException(sprintf('Expected "metadata" property of transaction to be object, got %s', \CivicInfoBC\Reflection::GetType($m))); } $obj = (object) array('hosted_checkout_id' => $t->hosted_checkout->id, 'modified' => new \DateTime(), 'ip' => $t->ip, 'amount' => $t->amount, 'name' => $t->name, 'last_four' => $t->last_four, 'email' => $t->email, 'token' => $t->token, 'metadata' => \CivicInfoBC\JSON::Encode($m), 'beanstream_request' => null, 'beanstream_status' => null, 'beanstream_response' => null, 'beanstream_body' => null, 'beanstream_failure_type' => null, 'beanstream_failure_message' => null, 'beanstream_success_auth_code' => null, 'beanstream_success_transaction_id' => null, 'beanstream_success_type' => null, 'beanstream_error_type' => null, 'beanstream_error_code' => null, 'beanstream_error_message' => null, 'exact_request' => null, 'exact_success' => null, 'exact_status' => null, 'exact_response' => null, 'exact_body' => null, 'exact_error_type' => null, 'exact_error_code' => null, 'exact_error_message' => null); $result = $t->beanstream; if (!is_null($result)) { self::save_beanstream($result, $obj); } $result = $t->exact; if (!is_null($result)) { self::save_exact($result, $obj); } if (is_null($t->id)) { // TODO: Do this with a trigger? $obj->created = $t->created = $obj->modified; $t->id = $this->conn->Insert('transactions', $obj); return; } $obj->id = $t->id; $this->conn->Update('transactions', 'id', $obj); }
private static function expected($key, $expected, $actual) { self::BadRequest(new \InvalidArgumentException(sprintf('Expected "%s" to be %s, got %s', $key, $expected, \CivicInfoBC\Reflection::GetType($actual)))); }