예제 #1
0
 /**
  * Converts a response from the Stripe API to the corresponding PHP object.
  *
  * @param array $resp The response from the Stripe API.
  * @param string $apiKey
  * @return Stripe_Object|array
  */
 public static function convertToStripeObject($resp, $apiKey)
 {
     $types = array('card' => 'M2_Stripe_Card', 'charge' => 'M2_Stripe_Charge', 'customer' => 'M2_Stripe_Customer', 'list' => 'M2_Stripe_List', 'invoice' => 'M2_Stripe_Invoice', 'invoiceitem' => 'M2_Stripe_InvoiceItem', 'event' => 'M2_Stripe_Event', 'transfer' => 'M2_Stripe_Transfer', 'plan' => 'M2_Stripe_Plan', 'recipient' => 'M2_Stripe_Recipient', 'refund' => 'M2_Stripe_Refund', 'subscription' => 'M2_Stripe_Subscription');
     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 = 'M2_Stripe_Object';
             }
             return M2_Stripe_Object::scopedConstructFrom($class, $resp, $apiKey);
         } else {
             return $resp;
         }
     }
 }
예제 #2
0
 /**
  * Refreshes this object using the provided values.
  *
  * @param array $values
  * @param string $apiKey
  * @param boolean $partial Defaults to false.
  */
 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 M2_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] = M2_Stripe_Object::scopedConstructFrom('M2_Stripe_AttachedObject', $v, $apiKey);
         } else {
             $this->_values[$k] = M2_Stripe_Util::convertToStripeObject($v, $apiKey);
         }
         $this->_transientValues->discard($k);
         $this->_unsavedValues->discard($k);
     }
 }