public static function convertToStripeObject($resp, $apiKey)
 {
     $types = array('card' => 'Stripe_Card', 'charge' => 'Stripe_Charge', 'customer' => 'Stripe_Customer', 'list' => 'Stripe_List', 'invoice' => 'Stripe_Invoice', 'invoiceitem' => 'Stripe_InvoiceItem', 'event' => 'Stripe_Event', 'transfer' => 'Stripe_Transfer', 'plan' => 'Stripe_Plan', 'recipient' => 'Stripe_Recipient');
     if (self::isList($resp)) {
         $mapped = array();
         foreach ($resp as $i) {
             array_push($mapped, self::convertToStripeObject($i, $apiKey));
         }
         return $mapped;
     } else {
         if (is_array($resp)) {
             if (isset($resp['object']) && is_string($resp['object']) && isset($types[$resp['object']])) {
                 $class = $types[$resp['object']];
             } else {
                 $class = 'Stripe_Object';
             }
             return Stripe_Object::scopedConstructFrom($class, $resp, $apiKey);
         } else {
             return $resp;
         }
     }
 }
Example #2
0
 public static function convertToStripeObject($resp, $apiKey)
 {
     $types = array('charge' => 'Stripe_Charge', 'customer' => 'Stripe_Customer', 'invoice' => 'Stripe_Invoice', 'invoiceitem' => 'Stripe_InvoiceItem');
     if (self::isList($resp)) {
         $mapped = array();
         foreach ($resp as $i) {
             array_push($mapped, self::convertToStripeObject($i, $apiKey));
         }
         return $mapped;
     } else {
         if (is_array($resp)) {
             $resp = self::arrayClone($resp);
             if (isset($resp['object']) && isset($types[$resp['object']])) {
                 $class = $types[$resp['object']];
             } else {
                 $class = 'Stripe_Object';
             }
             return Stripe_Object::scopedConstructFrom($class, $resp, $apiKey);
         } else {
             return $resp;
         }
     }
 }
Example #3
0
 public function refreshFrom($values, $apiKey, $partial = false)
 {
     $this->_apiKey = $apiKey;
     // Wipe old state before setting new.  This is useful for e.g. updating a
     // customer, where there is no persistent card parameter.  Mark those values
     // which don't persist as transient
     if ($partial) {
         $removed = new Stripe_Util_Set();
     } else {
         $removed = array_diff(array_keys($this->_values), array_keys($values));
     }
     foreach ($removed as $k) {
         if (self::$_permanentAttributes->includes($k)) {
             continue;
         }
         unset($this->{$k});
     }
     foreach ($values as $k => $v) {
         if (self::$_permanentAttributes->includes($k)) {
             continue;
         }
         if (self::$_nestedUpdatableAttributes->includes($k) && is_array($v)) {
             $this->_values[$k] = Stripe_Object::scopedConstructFrom('Stripe_AttachedObject', $v, $apiKey);
         } else {
             $this->_values[$k] = Stripe_Util::convertToStripeObject($v, $apiKey);
         }
         $this->_transientValues->discard($k);
         $this->_unsavedValues->discard($k);
     }
 }
 public static function init()
 {
     self::$_permanentAttributes = new Stripe_Util_Set(array('_apiKey', 'id'));
 }
Example #5
0
 public function refreshFrom($values, $apiKey, $partial = false)
 {
     $this->_apiKey = $apiKey;
     if ($partial) {
         $removed = new Stripe_Util_Set();
     } else {
         $removed = array_diff(array_keys($this->_values), array_keys($values));
     }
     foreach ($removed as $k) {
         if (self::$permanentAttributes->includes($k)) {
             continue;
         }
         unset($this->{$k});
     }
     foreach ($values as $k => $v) {
         if (self::$permanentAttributes->includes($k) && isset($this[$k])) {
             continue;
         }
         if (self::$nestedUpdatableAttributes->includes($k) && is_array($v)) {
             $this->_values[$k] = Stripe_Object::scopedConstructFrom('Stripe_AttachedObject', $v, $apiKey);
         } else {
             $this->_values[$k] = Stripe_Util::convertToStripeObject($v, $apiKey);
         }
         $this->_transientValues->discard($k);
         $this->_unsavedValues->discard($k);
     }
 }
Example #6
0
 public static function init()
 {
     self::$_permanentAttributes = new Stripe_Util_Set(array('_apiKey'));
     self::$_ignoredAttributes = new Stripe_Util_Set(array('id', '_apiKey', 'object'));
 }
Example #7
0
 public function testKeys()
 {
     $s = new Stripe_Object();
     $s->foo = 'a';
     $this->assertEqual($s->keys(), array('foo'));
 }