ApiOperations
1 year ago
Apps
1 year ago
Billing
1 year ago
BillingPortal
1 year ago
Checkout
1 year ago
Climate
1 year ago
Entitlements
1 year ago
EventData
1 year ago
Events
1 year ago
Exception
1 year ago
FinancialConnections
1 year ago
Forwarding
1 year ago
HttpClient
1 year ago
Identity
1 year ago
Issuing
1 year ago
Radar
1 year ago
Reporting
1 year ago
Service
1 year ago
Sigma
1 year ago
Tax
1 year ago
Terminal
1 year ago
TestHelpers
1 year ago
Treasury
1 year ago
Util
1 year ago
V2
1 year ago
Account.php
1 year ago
AccountLink.php
1 year ago
AccountSession.php
1 year ago
ApiRequestor.php
1 year ago
ApiResource.php
2 years ago
ApiResponse.php
2 years ago
ApplePayDomain.php
1 year ago
Application.php
2 years ago
ApplicationFee.php
1 year ago
ApplicationFeeRefund.php
2 years ago
Balance.php
1 year ago
BalanceTransaction.php
1 year ago
BankAccount.php
1 year ago
BaseStripeClient.php
1 year ago
BaseStripeClientInterface.php
1 year ago
Capability.php
1 year ago
Card.php
1 year ago
CashBalance.php
2 years ago
Charge.php
1 year ago
Collection.php
1 year ago
ConfirmationToken.php
1 year ago
ConnectCollectionTransfer.php
2 years ago
CountrySpec.php
1 year ago
Coupon.php
1 year ago
CreditNote.php
1 year ago
CreditNoteLineItem.php
1 year ago
Customer.php
1 year ago
CustomerBalanceTransaction.php
2 years ago
CustomerCashBalanceTransaction.php
2 years ago
CustomerSession.php
1 year ago
Discount.php
1 year ago
Dispute.php
1 year ago
EphemeralKey.php
1 year ago
ErrorObject.php
1 year ago
Event.php
1 year ago
ExchangeRate.php
1 year ago
File.php
1 year ago
FileLink.php
1 year ago
FundingInstructions.php
2 years ago
Invoice.php
1 year ago
InvoiceItem.php
1 year ago
InvoiceLineItem.php
1 year ago
InvoiceRenderingTemplate.php
1 year ago
LineItem.php
1 year ago
LoginLink.php
1 year ago
Mandate.php
1 year ago
OAuth.php
2 years ago
OAuthErrorObject.php
1 year ago
PaymentIntent.php
1 year ago
PaymentLink.php
1 year ago
PaymentMethod.php
1 year ago
PaymentMethodConfiguration.php
1 year ago
PaymentMethodDomain.php
1 year ago
Payout.php
1 year ago
Person.php
1 year ago
Plan.php
1 year ago
Price.php
1 year ago
Product.php
1 year ago
ProductFeature.php
1 year ago
PromotionCode.php
1 year ago
Quote.php
1 year ago
Reason.php
1 year ago
RecipientTransfer.php
2 years ago
Refund.php
1 year ago
RelatedObject.php
1 year ago
RequestTelemetry.php
2 years ago
ReserveTransaction.php
2 years ago
Review.php
1 year ago
SearchResult.php
1 year ago
SetupAttempt.php
1 year ago
SetupIntent.php
1 year ago
ShippingRate.php
1 year ago
SingletonApiResource.php
2 years ago
Source.php
1 year ago
SourceMandateNotification.php
2 years ago
SourceTransaction.php
2 years ago
Stripe.php
1 year ago
StripeClient.php
1 year ago
StripeClientInterface.php
2 years ago
StripeObject.php
1 year ago
StripeStreamingClientInterface.php
2 years ago
Subscription.php
1 year ago
SubscriptionItem.php
1 year ago
SubscriptionSchedule.php
1 year ago
TaxCode.php
1 year ago
TaxDeductedAtSource.php
2 years ago
TaxId.php
1 year ago
TaxRate.php
1 year ago
ThinEvent.php
1 year ago
Token.php
1 year ago
Topup.php
1 year ago
Transfer.php
1 year ago
TransferReversal.php
1 year ago
UsageRecord.php
1 year ago
UsageRecordSummary.php
1 year ago
Webhook.php
1 year ago
WebhookEndpoint.php
1 year ago
WebhookSignature.php
2 years ago
StripeObject.php
520 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPForms\Vendor\Stripe; |
| 4 | |
| 5 | /** |
| 6 | * Class StripeObject. |
| 7 | * |
| 8 | * @property null|string $id |
| 9 | */ |
| 10 | class StripeObject implements \ArrayAccess, \Countable, \JsonSerializable |
| 11 | { |
| 12 | /** @var Util\RequestOptions */ |
| 13 | protected $_opts; |
| 14 | /** @var array */ |
| 15 | protected $_originalValues; |
| 16 | /** @var array */ |
| 17 | protected $_values; |
| 18 | /** @var Util\Set */ |
| 19 | protected $_unsavedValues; |
| 20 | /** @var Util\Set */ |
| 21 | protected $_transientValues; |
| 22 | /** @var null|array */ |
| 23 | protected $_retrieveOptions; |
| 24 | /** @var null|ApiResponse */ |
| 25 | protected $_lastResponse; |
| 26 | /** |
| 27 | * @return Util\Set Attributes that should not be sent to the API because |
| 28 | * they're not updatable (e.g. ID). |
| 29 | */ |
| 30 | public static function getPermanentAttributes() |
| 31 | { |
| 32 | static $permanentAttributes = null; |
| 33 | if (null === $permanentAttributes) { |
| 34 | $permanentAttributes = new Util\Set(['id']); |
| 35 | } |
| 36 | return $permanentAttributes; |
| 37 | } |
| 38 | /** |
| 39 | * Additive objects are subobjects in the API that don't have the same |
| 40 | * semantics as most subobjects, which are fully replaced when they're set. |
| 41 | * |
| 42 | * This is best illustrated by example. The `source` parameter sent when |
| 43 | * updating a subscription is *not* additive; if we set it: |
| 44 | * |
| 45 | * source[object]=card&source[number]=123 |
| 46 | * |
| 47 | * We expect the old `source` object to have been overwritten completely. If |
| 48 | * the previous source had an `address_state` key associated with it and we |
| 49 | * didn't send one this time, that value of `address_state` is gone. |
| 50 | * |
| 51 | * By contrast, additive objects are those that will have new data added to |
| 52 | * them while keeping any existing data in place. The only known case of its |
| 53 | * use is for `metadata`, but it could in theory be more general. As an |
| 54 | * example, say we have a `metadata` object that looks like this on the |
| 55 | * server side: |
| 56 | * |
| 57 | * metadata = ["old" => "old_value"] |
| 58 | * |
| 59 | * If we update the object with `metadata[new]=new_value`, the server side |
| 60 | * object now has *both* fields: |
| 61 | * |
| 62 | * metadata = ["old" => "old_value", "new" => "new_value"] |
| 63 | * |
| 64 | * This is okay in itself because usually users will want to treat it as |
| 65 | * additive: |
| 66 | * |
| 67 | * $obj->metadata["new"] = "new_value"; |
| 68 | * $obj->save(); |
| 69 | * |
| 70 | * However, in other cases, they may want to replace the entire existing |
| 71 | * contents: |
| 72 | * |
| 73 | * $obj->metadata = ["new" => "new_value"]; |
| 74 | * $obj->save(); |
| 75 | * |
| 76 | * This is where things get a little bit tricky because in order to clear |
| 77 | * any old keys that may have existed, we actually have to send an explicit |
| 78 | * empty string to the server. So the operation above would have to send |
| 79 | * this form to get the intended behavior: |
| 80 | * |
| 81 | * metadata[old]=&metadata[new]=new_value |
| 82 | * |
| 83 | * This method allows us to track which parameters are considered additive, |
| 84 | * and lets us behave correctly where appropriate when serializing |
| 85 | * parameters to be sent. |
| 86 | * |
| 87 | * @return Util\Set Set of additive parameters |
| 88 | */ |
| 89 | public static function getAdditiveParams() |
| 90 | { |
| 91 | static $additiveParams = null; |
| 92 | if (null === $additiveParams) { |
| 93 | // Set `metadata` as additive so that when it's set directly we remember |
| 94 | // to clear keys that may have been previously set by sending empty |
| 95 | // values for them. |
| 96 | // |
| 97 | // It's possible that not every object has `metadata`, but having this |
| 98 | // option set when there is no `metadata` field is not harmful. |
| 99 | $additiveParams = new Util\Set(['metadata']); |
| 100 | } |
| 101 | return $additiveParams; |
| 102 | } |
| 103 | public function __construct($id = null, $opts = null) |
| 104 | { |
| 105 | list($id, $this->_retrieveOptions) = Util\Util::normalizeId($id); |
| 106 | $this->_opts = Util\RequestOptions::parse($opts); |
| 107 | $this->_originalValues = []; |
| 108 | $this->_values = []; |
| 109 | $this->_unsavedValues = new Util\Set(); |
| 110 | $this->_transientValues = new Util\Set(); |
| 111 | if (null !== $id) { |
| 112 | $this->_values['id'] = $id; |
| 113 | } |
| 114 | } |
| 115 | // Standard accessor magic methods |
| 116 | public function __set($k, $v) |
| 117 | { |
| 118 | if (static::getPermanentAttributes()->includes($k)) { |
| 119 | throw new Exception\InvalidArgumentException("Cannot set {$k} on this object. HINT: you can't set: " . \implode(', ', static::getPermanentAttributes()->toArray())); |
| 120 | } |
| 121 | if ('' === $v) { |
| 122 | throw new Exception\InvalidArgumentException('You cannot set \'' . $k . '\'to an empty string. ' . 'We interpret empty strings as NULL in requests. ' . 'You may set obj->' . $k . ' = NULL to delete the property'); |
| 123 | } |
| 124 | $this->_values[$k] = Util\Util::convertToStripeObject($v, $this->_opts); |
| 125 | $this->dirtyValue($this->_values[$k]); |
| 126 | $this->_unsavedValues->add($k); |
| 127 | } |
| 128 | /** |
| 129 | * @param mixed $k |
| 130 | * |
| 131 | * @return bool |
| 132 | */ |
| 133 | public function __isset($k) |
| 134 | { |
| 135 | return isset($this->_values[$k]); |
| 136 | } |
| 137 | public function __unset($k) |
| 138 | { |
| 139 | unset($this->_values[$k]); |
| 140 | $this->_transientValues->add($k); |
| 141 | $this->_unsavedValues->discard($k); |
| 142 | } |
| 143 | public function &__get($k) |
| 144 | { |
| 145 | // function should return a reference, using $nullval to return a reference to null |
| 146 | $nullval = null; |
| 147 | if (!empty($this->_values) && \array_key_exists($k, $this->_values)) { |
| 148 | return $this->_values[$k]; |
| 149 | } |
| 150 | if (!empty($this->_transientValues) && $this->_transientValues->includes($k)) { |
| 151 | $class = static::class; |
| 152 | $attrs = \implode(', ', \array_keys($this->_values)); |
| 153 | $message = "Stripe Notice: Undefined property of {$class} instance: {$k}. " . "HINT: The {$k} attribute was set in the past, however. " . 'It was then wiped when refreshing the object ' . "with the result returned by Stripe's API, " . 'probably as a result of a save(). The attributes currently ' . "available on this object are: {$attrs}"; |
| 154 | Stripe::getLogger()->error($message); |
| 155 | return $nullval; |
| 156 | } |
| 157 | $class = static::class; |
| 158 | Stripe::getLogger()->error("Stripe Notice: Undefined property of {$class} instance: {$k}"); |
| 159 | return $nullval; |
| 160 | } |
| 161 | /** |
| 162 | * Magic method for var_dump output. Only works with PHP >= 5.6. |
| 163 | * |
| 164 | * @return array |
| 165 | */ |
| 166 | public function __debugInfo() |
| 167 | { |
| 168 | return $this->_values; |
| 169 | } |
| 170 | // ArrayAccess methods |
| 171 | /** |
| 172 | * @return void |
| 173 | */ |
| 174 | #[\ReturnTypeWillChange] |
| 175 | public function offsetSet($k, $v) |
| 176 | { |
| 177 | $this->{$k} = $v; |
| 178 | } |
| 179 | /** |
| 180 | * @return bool |
| 181 | */ |
| 182 | #[\ReturnTypeWillChange] |
| 183 | public function offsetExists($k) |
| 184 | { |
| 185 | return \array_key_exists($k, $this->_values); |
| 186 | } |
| 187 | /** |
| 188 | * @return void |
| 189 | */ |
| 190 | #[\ReturnTypeWillChange] |
| 191 | public function offsetUnset($k) |
| 192 | { |
| 193 | unset($this->{$k}); |
| 194 | } |
| 195 | /** |
| 196 | * @return mixed |
| 197 | */ |
| 198 | #[\ReturnTypeWillChange] |
| 199 | public function offsetGet($k) |
| 200 | { |
| 201 | return \array_key_exists($k, $this->_values) ? $this->_values[$k] : null; |
| 202 | } |
| 203 | /** |
| 204 | * @return int |
| 205 | */ |
| 206 | #[\ReturnTypeWillChange] |
| 207 | public function count() |
| 208 | { |
| 209 | return \count($this->_values); |
| 210 | } |
| 211 | public function keys() |
| 212 | { |
| 213 | return \array_keys($this->_values); |
| 214 | } |
| 215 | public function values() |
| 216 | { |
| 217 | return \array_values($this->_values); |
| 218 | } |
| 219 | /** |
| 220 | * This unfortunately needs to be public to be used in Util\Util. |
| 221 | * |
| 222 | * @param array $values |
| 223 | * @param null|array|string|Util\RequestOptions $opts |
| 224 | * @param 'v1'|'v2' $apiMode |
| 225 | * |
| 226 | * @return static the object constructed from the given values |
| 227 | */ |
| 228 | public static function constructFrom($values, $opts = null, $apiMode = 'v1') |
| 229 | { |
| 230 | $obj = new static(isset($values['id']) ? $values['id'] : null); |
| 231 | $obj->refreshFrom($values, $opts, \false, $apiMode); |
| 232 | return $obj; |
| 233 | } |
| 234 | /** |
| 235 | * Refreshes this object using the provided values. |
| 236 | * |
| 237 | * @param array $values |
| 238 | * @param null|array|string|Util\RequestOptions $opts |
| 239 | * @param bool $partial defaults to false |
| 240 | * @param 'v1'|'v2' $apiMode |
| 241 | */ |
| 242 | public function refreshFrom($values, $opts, $partial = \false, $apiMode = 'v1') |
| 243 | { |
| 244 | $this->_opts = Util\RequestOptions::parse($opts); |
| 245 | $this->_originalValues = self::deepCopy($values); |
| 246 | if ($values instanceof StripeObject) { |
| 247 | $values = $values->toArray(); |
| 248 | } |
| 249 | // Wipe old state before setting new. This is useful for e.g. updating a |
| 250 | // customer, where there is no persistent card parameter. Mark those values |
| 251 | // which don't persist as transient |
| 252 | if ($partial) { |
| 253 | $removed = new Util\Set(); |
| 254 | } else { |
| 255 | $removed = new Util\Set(\array_diff(\array_keys($this->_values), \array_keys($values))); |
| 256 | } |
| 257 | foreach ($removed->toArray() as $k) { |
| 258 | unset($this->{$k}); |
| 259 | } |
| 260 | $this->updateAttributes($values, $opts, \false, $apiMode); |
| 261 | foreach ($values as $k => $v) { |
| 262 | $this->_transientValues->discard($k); |
| 263 | $this->_unsavedValues->discard($k); |
| 264 | } |
| 265 | } |
| 266 | /** |
| 267 | * Mass assigns attributes on the model. |
| 268 | * |
| 269 | * @param array $values |
| 270 | * @param null|array|string|Util\RequestOptions $opts |
| 271 | * @param bool $dirty defaults to true |
| 272 | * @param 'v1'|'v2' $apiMode |
| 273 | */ |
| 274 | public function updateAttributes($values, $opts = null, $dirty = \true, $apiMode = 'v1') |
| 275 | { |
| 276 | foreach ($values as $k => $v) { |
| 277 | // Special-case metadata to always be cast as a StripeObject |
| 278 | // This is necessary in case metadata is empty, as PHP arrays do |
| 279 | // not differentiate between lists and hashes, and we consider |
| 280 | // empty arrays to be lists. |
| 281 | if ('metadata' === $k && \is_array($v)) { |
| 282 | $this->_values[$k] = StripeObject::constructFrom($v, $opts, $apiMode); |
| 283 | } else { |
| 284 | $this->_values[$k] = Util\Util::convertToStripeObject($v, $opts, $apiMode); |
| 285 | } |
| 286 | if ($dirty) { |
| 287 | $this->dirtyValue($this->_values[$k]); |
| 288 | } |
| 289 | $this->_unsavedValues->add($k); |
| 290 | } |
| 291 | } |
| 292 | /** |
| 293 | * @param bool $force defaults to false |
| 294 | * |
| 295 | * @return array a recursive mapping of attributes to values for this object, |
| 296 | * including the proper value for deleted attributes |
| 297 | */ |
| 298 | public function serializeParameters($force = \false) |
| 299 | { |
| 300 | $updateParams = []; |
| 301 | foreach ($this->_values as $k => $v) { |
| 302 | // There are a few reasons that we may want to add in a parameter for |
| 303 | // update: |
| 304 | // |
| 305 | // 1. The `$force` option has been set. |
| 306 | // 2. We know that it was modified. |
| 307 | // 3. Its value is a StripeObject. A StripeObject may contain modified |
| 308 | // values within in that its parent StripeObject doesn't know about. |
| 309 | // |
| 310 | $original = \array_key_exists($k, $this->_originalValues) ? $this->_originalValues[$k] : null; |
| 311 | $unsaved = $this->_unsavedValues->includes($k); |
| 312 | if ($force || $unsaved || $v instanceof StripeObject) { |
| 313 | $updateParams[$k] = $this->serializeParamsValue($this->_values[$k], $original, $unsaved, $force, $k); |
| 314 | } |
| 315 | } |
| 316 | // a `null` that makes it out of `serializeParamsValue` signals an empty |
| 317 | // value that we shouldn't appear in the serialized form of the object |
| 318 | return \array_filter($updateParams, function ($v) { |
| 319 | return null !== $v; |
| 320 | }); |
| 321 | } |
| 322 | public function serializeParamsValue($value, $original, $unsaved, $force, $key = null) |
| 323 | { |
| 324 | // The logic here is that essentially any object embedded in another |
| 325 | // object that had a `type` is actually an API resource of a different |
| 326 | // type that's been included in the response. These other resources must |
| 327 | // be updated from their proper endpoints, and therefore they are not |
| 328 | // included when serializing even if they've been modified. |
| 329 | // |
| 330 | // There are _some_ known exceptions though. |
| 331 | // |
| 332 | // For example, if the value is unsaved (meaning the user has set it), and |
| 333 | // it looks like the API resource is persisted with an ID, then we include |
| 334 | // the object so that parameters are serialized with a reference to its |
| 335 | // ID. |
| 336 | // |
| 337 | // Another example is that on save API calls it's sometimes desirable to |
| 338 | // update a customer's default source by setting a new card (or other) |
| 339 | // object with `->source=` and then saving the customer. The |
| 340 | // `saveWithParent` flag to override the default behavior allows us to |
| 341 | // handle these exceptions. |
| 342 | // |
| 343 | // We throw an error if a property was set explicitly but we can't do |
| 344 | // anything with it because the integration is probably not working as the |
| 345 | // user intended it to. |
| 346 | if (null === $value) { |
| 347 | return ''; |
| 348 | } |
| 349 | if ($value instanceof ApiResource && !$value->saveWithParent) { |
| 350 | if (!$unsaved) { |
| 351 | return null; |
| 352 | } |
| 353 | if (isset($value->id)) { |
| 354 | return $value; |
| 355 | } |
| 356 | throw new Exception\InvalidArgumentException("Cannot save property `{$key}` containing an API resource of type " . \get_class($value) . ". It doesn't appear to be persisted and is " . 'not marked as `saveWithParent`.'); |
| 357 | } |
| 358 | if (\is_array($value)) { |
| 359 | if (Util\Util::isList($value)) { |
| 360 | // Sequential array, i.e. a list |
| 361 | $update = []; |
| 362 | foreach ($value as $v) { |
| 363 | $update[] = $this->serializeParamsValue($v, null, \true, $force); |
| 364 | } |
| 365 | // This prevents an array that's unchanged from being resent. |
| 366 | if ($update !== $this->serializeParamsValue($original, null, \true, $force, $key)) { |
| 367 | return $update; |
| 368 | } |
| 369 | } else { |
| 370 | // Associative array, i.e. a map |
| 371 | return Util\Util::convertToStripeObject($value, $this->_opts)->serializeParameters(); |
| 372 | } |
| 373 | } elseif ($value instanceof StripeObject) { |
| 374 | $update = $value->serializeParameters($force); |
| 375 | if ($original && $unsaved && $key && static::getAdditiveParams()->includes($key)) { |
| 376 | $update = \array_merge(self::emptyValues($original), $update); |
| 377 | } |
| 378 | return $update; |
| 379 | } else { |
| 380 | return $value; |
| 381 | } |
| 382 | } |
| 383 | /** |
| 384 | * @return mixed |
| 385 | */ |
| 386 | #[\ReturnTypeWillChange] |
| 387 | public function jsonSerialize() |
| 388 | { |
| 389 | return $this->toArray(); |
| 390 | } |
| 391 | /** |
| 392 | * Returns an associative array with the key and values composing the |
| 393 | * Stripe object. |
| 394 | * |
| 395 | * @return array the associative array |
| 396 | */ |
| 397 | public function toArray() |
| 398 | { |
| 399 | $maybeToArray = function ($value) { |
| 400 | if (null === $value) { |
| 401 | return null; |
| 402 | } |
| 403 | return \is_object($value) && \method_exists($value, 'toArray') ? $value->toArray() : $value; |
| 404 | }; |
| 405 | return \array_reduce(\array_keys($this->_values), function ($acc, $k) use($maybeToArray) { |
| 406 | if ('_' === \substr((string) $k, 0, 1)) { |
| 407 | return $acc; |
| 408 | } |
| 409 | $v = $this->_values[$k]; |
| 410 | if (Util\Util::isList($v)) { |
| 411 | $acc[$k] = \array_map($maybeToArray, $v); |
| 412 | } else { |
| 413 | $acc[$k] = $maybeToArray($v); |
| 414 | } |
| 415 | return $acc; |
| 416 | }, []); |
| 417 | } |
| 418 | /** |
| 419 | * Returns a pretty JSON representation of the Stripe object. |
| 420 | * |
| 421 | * @return string the JSON representation of the Stripe object |
| 422 | */ |
| 423 | public function toJSON() |
| 424 | { |
| 425 | return \json_encode($this->toArray(), \JSON_PRETTY_PRINT); |
| 426 | } |
| 427 | public function __toString() |
| 428 | { |
| 429 | $class = static::class; |
| 430 | return $class . ' JSON: ' . $this->toJSON(); |
| 431 | } |
| 432 | /** |
| 433 | * Sets all keys within the StripeObject as unsaved so that they will be |
| 434 | * included with an update when `serializeParameters` is called. This |
| 435 | * method is also recursive, so any StripeObjects contained as values or |
| 436 | * which are values in a tenant array are also marked as dirty. |
| 437 | */ |
| 438 | public function dirty() |
| 439 | { |
| 440 | $this->_unsavedValues = new Util\Set(\array_keys($this->_values)); |
| 441 | foreach ($this->_values as $k => $v) { |
| 442 | $this->dirtyValue($v); |
| 443 | } |
| 444 | } |
| 445 | protected function dirtyValue($value) |
| 446 | { |
| 447 | if (\is_array($value)) { |
| 448 | foreach ($value as $v) { |
| 449 | $this->dirtyValue($v); |
| 450 | } |
| 451 | } elseif ($value instanceof StripeObject) { |
| 452 | $value->dirty(); |
| 453 | } |
| 454 | } |
| 455 | /** |
| 456 | * Produces a deep copy of the given object including support for arrays |
| 457 | * and StripeObjects. |
| 458 | * |
| 459 | * @param mixed $obj |
| 460 | */ |
| 461 | protected static function deepCopy($obj) |
| 462 | { |
| 463 | if (\is_array($obj)) { |
| 464 | $copy = []; |
| 465 | foreach ($obj as $k => $v) { |
| 466 | $copy[$k] = self::deepCopy($v); |
| 467 | } |
| 468 | return $copy; |
| 469 | } |
| 470 | if ($obj instanceof StripeObject) { |
| 471 | return $obj::constructFrom(self::deepCopy($obj->_values), clone $obj->_opts); |
| 472 | } |
| 473 | return $obj; |
| 474 | } |
| 475 | /** |
| 476 | * Returns a hash of empty values for all the values that are in the given |
| 477 | * StripeObject. |
| 478 | * |
| 479 | * @param mixed $obj |
| 480 | */ |
| 481 | public static function emptyValues($obj) |
| 482 | { |
| 483 | if (\is_array($obj)) { |
| 484 | $values = $obj; |
| 485 | } elseif ($obj instanceof StripeObject) { |
| 486 | $values = $obj->_values; |
| 487 | } else { |
| 488 | throw new Exception\InvalidArgumentException('empty_values got unexpected object type: ' . \get_class($obj)); |
| 489 | } |
| 490 | return \array_fill_keys(\array_keys($values), ''); |
| 491 | } |
| 492 | /** |
| 493 | * @return null|ApiResponse The last response from the Stripe API |
| 494 | */ |
| 495 | public function getLastResponse() |
| 496 | { |
| 497 | return $this->_lastResponse; |
| 498 | } |
| 499 | /** |
| 500 | * Sets the last response from the Stripe API. |
| 501 | * |
| 502 | * @param ApiResponse $resp |
| 503 | */ |
| 504 | public function setLastResponse($resp) |
| 505 | { |
| 506 | $this->_lastResponse = $resp; |
| 507 | } |
| 508 | /** |
| 509 | * Indicates whether or not the resource has been deleted on the server. |
| 510 | * Note that some, but not all, resources can indicate whether they have |
| 511 | * been deleted. |
| 512 | * |
| 513 | * @return bool whether the resource is deleted |
| 514 | */ |
| 515 | public function isDeleted() |
| 516 | { |
| 517 | return isset($this->_values['deleted']) ? $this->_values['deleted'] : \false; |
| 518 | } |
| 519 | } |
| 520 |