Source.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Source
  5. *
  6. * @property string $id
  7. * @property string $object
  8. * @property int $amount
  9. * @property string $client_secret
  10. * @property mixed $code_verification
  11. * @property int $created
  12. * @property string $currency
  13. * @property string $flow
  14. * @property bool $livemode
  15. * @property StripeObject $metadata
  16. * @property mixed $owner
  17. * @property mixed $receiver
  18. * @property mixed $redirect
  19. * @property string $statement_descriptor
  20. * @property string $status
  21. * @property string $type
  22. * @property string $usage
  23. *
  24. * @package Stripe
  25. */
  26. class Source extends ApiResource
  27. {
  28. const OBJECT_NAME = "source";
  29. use ApiOperations\Create;
  30. use ApiOperations\Retrieve;
  31. use ApiOperations\Update;
  32. /**
  33. * @param array|null $params
  34. * @param array|string|null $options
  35. *
  36. * @return Source The detached source.
  37. */
  38. public function detach($params = null, $options = null)
  39. {
  40. self::_validateParams($params);
  41. $id = $this['id'];
  42. if (!$id) {
  43. $class = get_class($this);
  44. $msg = "Could not determine which URL to request: $class instance "
  45. . "has invalid ID: $id";
  46. throw new Error\InvalidRequest($msg, null);
  47. }
  48. if ($this['customer']) {
  49. $base = Customer::classUrl();
  50. $parentExtn = urlencode(Util\Util::utf8($this['customer']));
  51. $extn = urlencode(Util\Util::utf8($id));
  52. $url = "$base/$parentExtn/sources/$extn";
  53. list($response, $opts) = $this->_request('delete', $url, $params, $options);
  54. $this->refreshFrom($response, $opts);
  55. return $this;
  56. } else {
  57. $message = "This source object does not appear to be currently attached "
  58. . "to a customer object.";
  59. throw new Error\Api($message);
  60. }
  61. }
  62. /**
  63. * @param array|null $params
  64. * @param array|string|null $options
  65. *
  66. * @return Source The detached source.
  67. *
  68. * @deprecated Use the `detach` method instead.
  69. */
  70. public function delete($params = null, $options = null)
  71. {
  72. $this->detach($params, $options);
  73. }
  74. /**
  75. * @param array|null $params
  76. * @param array|string|null $options
  77. *
  78. * @return Collection The list of source transactions.
  79. */
  80. public function sourceTransactions($params = null, $options = null)
  81. {
  82. $url = $this->instanceUrl() . '/source_transactions';
  83. list($response, $opts) = $this->_request('get', $url, $params, $options);
  84. $obj = Util\Util::convertToStripeObject($response, $opts);
  85. $obj->setLastResponse($response);
  86. return $obj;
  87. }
  88. /**
  89. * @param array|null $params
  90. * @param array|string|null $options
  91. *
  92. * @return Source The verified source.
  93. */
  94. public function verify($params = null, $options = null)
  95. {
  96. $url = $this->instanceUrl() . '/verify';
  97. list($response, $opts) = $this->_request('post', $url, $params, $options);
  98. $this->refreshFrom($response, $opts);
  99. return $this;
  100. }
  101. }