Example #1
0
 public static function fromJson($json)
 {
     if (!isset($json->item) && !isset($json->checkout)) {
         throw new \Exception('both checkout and item are null');
     }
     if (isset($json->item) && isset($json->checkout)) {
         throw new \Exception('both checkout and item are non-null, only expected one of checkout or item');
     }
     $r = new Transaction();
     $r->setId($json->id);
     $r->setExternalId(isset($json->external_id) ? $json->external_id : null);
     $r->setCreated($json->created);
     $r->setState($json->state);
     $r->setRevisionNumber($json->revision_number);
     $r->setProject($json->project);
     $r->setItem(isset($json->item) ? Item::fromJson($json->item) : null);
     $r->setCheckout(isset($json->checkout) ? Checkout::fromJson($json->checkout) : null);
     $r->setCustomer(Customer::fromJson($json->customer));
     $r->setPrice(Price::fromJson($json->price));
     $r->setPaymentMethod($json->payment_method);
     $r->setTest(isset($json->test) ? $json->test : false);
     return $r;
 }