Card.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Card
  5. *
  6. * @property string $id
  7. * @property string $object
  8. * @property string $account
  9. * @property string $address_city
  10. * @property string $address_country
  11. * @property string $address_line1
  12. * @property string $address_line1_check
  13. * @property string $address_line2
  14. * @property string $address_state
  15. * @property string $address_zip
  16. * @property string $address_zip_check
  17. * @property array $available_payout_methods
  18. * @property string $brand
  19. * @property string $country
  20. * @property string $currency
  21. * @property string $customer
  22. * @property string $cvc_check
  23. * @property bool $default_for_currency
  24. * @property string $dynamic_last4
  25. * @property int $exp_month
  26. * @property int $exp_year
  27. * @property string $fingerprint
  28. * @property string $funding
  29. * @property string $last4
  30. * @property StripeObject $metadata
  31. * @property string $name
  32. * @property string $recipient
  33. * @property string $tokenization_method
  34. *
  35. * @package Stripe
  36. */
  37. class Card extends ApiResource
  38. {
  39. const OBJECT_NAME = "card";
  40. use ApiOperations\Delete;
  41. use ApiOperations\Update;
  42. /**
  43. * @return string The instance URL for this resource. It needs to be special
  44. * cased because cards are nested resources that may belong to different
  45. * top-level resources.
  46. */
  47. public function instanceUrl()
  48. {
  49. if ($this['customer']) {
  50. $base = Customer::classUrl();
  51. $parent = $this['customer'];
  52. $path = 'sources';
  53. } elseif ($this['account']) {
  54. $base = Account::classUrl();
  55. $parent = $this['account'];
  56. $path = 'external_accounts';
  57. } elseif ($this['recipient']) {
  58. $base = Recipient::classUrl();
  59. $parent = $this['recipient'];
  60. $path = 'cards';
  61. } else {
  62. $msg = "Cards cannot be accessed without a customer ID, account ID or recipient ID.";
  63. throw new Error\InvalidRequest($msg, null);
  64. }
  65. $parentExtn = urlencode(Util\Util::utf8($parent));
  66. $extn = urlencode(Util\Util::utf8($this['id']));
  67. return "$base/$parentExtn/$path/$extn";
  68. }
  69. /**
  70. * @param array|string $_id
  71. * @param array|string|null $_opts
  72. *
  73. * @throws \Stripe\Error\InvalidRequest
  74. */
  75. public static function retrieve($_id, $_opts = null)
  76. {
  77. $msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
  78. "Retrieve a card using \$customer->sources->retrieve('card_id'), " .
  79. "\$recipient->cards->retrieve('card_id'), or";
  80. "\$account->external_accounts->retrieve('card_id') instead.";
  81. throw new Error\InvalidRequest($msg, null);
  82. }
  83. /**
  84. * @param string $_id
  85. * @param array|null $_params
  86. * @param array|string|null $_options
  87. *
  88. * @throws \Stripe\Error\InvalidRequest
  89. */
  90. public static function update($_id, $_params = null, $_options = null)
  91. {
  92. $msg = "Cards cannot be accessed without a customer, recipient or account ID. " .
  93. "Call save() on \$customer->sources->retrieve('card_id'), " .
  94. "\$recipient->cards->retrieve('card_id'), or";
  95. "\$account->external_accounts->retrieve('card_id') instead.";
  96. throw new Error\InvalidRequest($msg, null);
  97. }
  98. }