SetupIntent.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * A SetupIntent guides you through the process of setting up and saving a customer's payment credentials for future payments.
  6. * For example, you can use a SetupIntent to set up and save your customer's card without immediately collecting a payment.
  7. * Later, you can use <a href="https://stripe.com/docs/api#payment_intents">PaymentIntents</a> to drive the payment flow.
  8. *
  9. * Create a SetupIntent when you're ready to collect your customer's payment credentials.
  10. * Don't maintain long-lived, unconfirmed SetupIntents because they might not be valid.
  11. * The SetupIntent transitions through multiple <a href="https://docs.stripe.com/payments/intents#intent-statuses">statuses</a> as it guides
  12. * you through the setup process.
  13. *
  14. * Successful SetupIntents result in payment credentials that are optimized for future payments.
  15. * For example, cardholders in <a href="https://stripe.com/guides/strong-customer-authentication">certain regions</a> might need to be run through
  16. * <a href="https://docs.stripe.com/strong-customer-authentication">Strong Customer Authentication</a> during payment method collection
  17. * to streamline later <a href="https://docs.stripe.com/payments/setup-intents">off-session payments</a>.
  18. * If you use the SetupIntent with a <a href="https://stripe.com/docs/api#setup_intent_object-customer">Customer</a>,
  19. * it automatically attaches the resulting payment method to that Customer after successful setup.
  20. * We recommend using SetupIntents or <a href="https://stripe.com/docs/api#payment_intent_object-setup_future_usage">setup_future_usage</a> on
  21. * PaymentIntents to save payment methods to prevent saving invalid or unoptimized payment methods.
  22. *
  23. * By using SetupIntents, you can reduce friction for your customers, even as regulations change over time.
  24. *
  25. * Related guide: <a href="https://docs.stripe.com/payments/setup-intents">Setup Intents API</a>
  26. *
  27. * @property string $id Unique identifier for the object.
  28. * @property string $object String representing the object's type. Objects of the same type share the same value.
  29. * @property null|string|\Stripe\Application $application ID of the Connect application that created the SetupIntent.
  30. * @property null|bool $attach_to_self <p>If present, the SetupIntent's payment method will be attached to the in-context Stripe Account.</p><p>It can only be used for this Stripe Account’s own money movement flows like InboundTransfer and OutboundTransfers. It cannot be set to true when setting up a PaymentMethod for a Customer, and defaults to false when attaching a PaymentMethod to a Customer.</p>
  31. * @property null|\Stripe\StripeObject $automatic_payment_methods Settings for dynamic payment methods compatible with this Setup Intent
  32. * @property null|string $cancellation_reason Reason for cancellation of this SetupIntent, one of <code>abandoned</code>, <code>requested_by_customer</code>, or <code>duplicate</code>.
  33. * @property null|string $client_secret <p>The client secret of this SetupIntent. Used for client-side retrieval using a publishable key.</p><p>The client secret can be used to complete payment setup from your frontend. It should not be stored, logged, or exposed to anyone other than the customer. Make sure that you have TLS enabled on any page that includes the client secret.</p>
  34. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  35. * @property null|string|\Stripe\Customer $customer <p>ID of the Customer this SetupIntent belongs to, if one exists.</p><p>If present, the SetupIntent's payment method will be attached to the Customer on successful setup. Payment methods attached to other Customers cannot be used with this SetupIntent.</p>
  36. * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
  37. * @property null|string[] $flow_directions <p>Indicates the directions of money movement for which this payment method is intended to be used.</p><p>Include <code>inbound</code> if you intend to use the payment method as the origin to pull funds from. Include <code>outbound</code> if you intend to use the payment method as the destination to send funds to. You can include both if you intend to use the payment method for both purposes.</p>
  38. * @property null|\Stripe\StripeObject $last_setup_error The error encountered in the previous SetupIntent confirmation.
  39. * @property null|string|\Stripe\SetupAttempt $latest_attempt The most recent SetupAttempt for this SetupIntent.
  40. * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
  41. * @property null|string|\Stripe\Mandate $mandate ID of the multi use Mandate generated by the SetupIntent.
  42. * @property null|\Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  43. * @property null|\Stripe\StripeObject $next_action If present, this property tells you what actions you need to take in order for your customer to continue payment setup.
  44. * @property null|string|\Stripe\Account $on_behalf_of The account (if any) for which the setup is intended.
  45. * @property null|string|\Stripe\PaymentMethod $payment_method ID of the payment method used with this SetupIntent.
  46. * @property null|\Stripe\StripeObject $payment_method_configuration_details Information about the payment method configuration used for this Setup Intent.
  47. * @property null|\Stripe\StripeObject $payment_method_options Payment method-specific configuration for this SetupIntent.
  48. * @property string[] $payment_method_types The list of payment method types (e.g. card) that this SetupIntent is allowed to set up.
  49. * @property null|string|\Stripe\Mandate $single_use_mandate ID of the single_use Mandate generated by the SetupIntent.
  50. * @property string $status <a href="https://stripe.com/docs/payments/intents#intent-statuses">Status</a> of this SetupIntent, one of <code>requires_payment_method</code>, <code>requires_confirmation</code>, <code>requires_action</code>, <code>processing</code>, <code>canceled</code>, or <code>succeeded</code>.
  51. * @property string $usage <p>Indicates how the payment method is intended to be used in the future.</p><p>Use <code>on_session</code> if you intend to only reuse the payment method when the customer is in your checkout flow. Use <code>off_session</code> if your customer may or may not be in your checkout flow. If not provided, this value defaults to <code>off_session</code>.</p>
  52. */
  53. class SetupIntent extends ApiResource
  54. {
  55. const OBJECT_NAME = 'setup_intent';
  56. use ApiOperations\Update;
  57. const CANCELLATION_REASON_ABANDONED = 'abandoned';
  58. const CANCELLATION_REASON_DUPLICATE = 'duplicate';
  59. const CANCELLATION_REASON_REQUESTED_BY_CUSTOMER = 'requested_by_customer';
  60. const STATUS_CANCELED = 'canceled';
  61. const STATUS_PROCESSING = 'processing';
  62. const STATUS_REQUIRES_ACTION = 'requires_action';
  63. const STATUS_REQUIRES_CONFIRMATION = 'requires_confirmation';
  64. const STATUS_REQUIRES_PAYMENT_METHOD = 'requires_payment_method';
  65. const STATUS_SUCCEEDED = 'succeeded';
  66. /**
  67. * Creates a SetupIntent object.
  68. *
  69. * After you create the SetupIntent, attach a payment method and <a
  70. * href="/docs/api/setup_intents/confirm">confirm</a> it to collect any required
  71. * permissions to charge the payment method later.
  72. *
  73. * @param null|array $params
  74. * @param null|array|string $options
  75. *
  76. * @throws \Stripe\Exception\ApiErrorException if the request fails
  77. *
  78. * @return \Stripe\SetupIntent the created resource
  79. */
  80. public static function create($params = null, $options = null)
  81. {
  82. self::_validateParams($params);
  83. $url = static::classUrl();
  84. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  85. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  86. $obj->setLastResponse($response);
  87. return $obj;
  88. }
  89. /**
  90. * Returns a list of SetupIntents.
  91. *
  92. * @param null|array $params
  93. * @param null|array|string $opts
  94. *
  95. * @throws \Stripe\Exception\ApiErrorException if the request fails
  96. *
  97. * @return \Stripe\Collection<\Stripe\SetupIntent> of ApiResources
  98. */
  99. public static function all($params = null, $opts = null)
  100. {
  101. $url = static::classUrl();
  102. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  103. }
  104. /**
  105. * Retrieves the details of a SetupIntent that has previously been created.
  106. *
  107. * Client-side retrieval using a publishable key is allowed when the
  108. * <code>client_secret</code> is provided in the query string.
  109. *
  110. * When retrieved with a publishable key, only a subset of properties will be
  111. * returned. Please refer to the <a href="#setup_intent_object">SetupIntent</a>
  112. * object reference for more details.
  113. *
  114. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  115. * @param null|array|string $opts
  116. *
  117. * @throws \Stripe\Exception\ApiErrorException if the request fails
  118. *
  119. * @return \Stripe\SetupIntent
  120. */
  121. public static function retrieve($id, $opts = null)
  122. {
  123. $opts = \Stripe\Util\RequestOptions::parse($opts);
  124. $instance = new static($id, $opts);
  125. $instance->refresh();
  126. return $instance;
  127. }
  128. /**
  129. * Updates a SetupIntent object.
  130. *
  131. * @param string $id the ID of the resource to update
  132. * @param null|array $params
  133. * @param null|array|string $opts
  134. *
  135. * @throws \Stripe\Exception\ApiErrorException if the request fails
  136. *
  137. * @return \Stripe\SetupIntent the updated resource
  138. */
  139. public static function update($id, $params = null, $opts = null)
  140. {
  141. self::_validateParams($params);
  142. $url = static::resourceUrl($id);
  143. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  144. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  145. $obj->setLastResponse($response);
  146. return $obj;
  147. }
  148. /**
  149. * @param null|array $params
  150. * @param null|array|string $opts
  151. *
  152. * @throws \Stripe\Exception\ApiErrorException if the request fails
  153. *
  154. * @return \Stripe\SetupIntent the canceled setup intent
  155. */
  156. public function cancel($params = null, $opts = null)
  157. {
  158. $url = $this->instanceUrl() . '/cancel';
  159. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  160. $this->refreshFrom($response, $opts);
  161. return $this;
  162. }
  163. /**
  164. * @param null|array $params
  165. * @param null|array|string $opts
  166. *
  167. * @throws \Stripe\Exception\ApiErrorException if the request fails
  168. *
  169. * @return \Stripe\SetupIntent the confirmed setup intent
  170. */
  171. public function confirm($params = null, $opts = null)
  172. {
  173. $url = $this->instanceUrl() . '/confirm';
  174. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  175. $this->refreshFrom($response, $opts);
  176. return $this;
  177. }
  178. /**
  179. * @param null|array $params
  180. * @param null|array|string $opts
  181. *
  182. * @throws \Stripe\Exception\ApiErrorException if the request fails
  183. *
  184. * @return \Stripe\SetupIntent the verified setup intent
  185. */
  186. public function verifyMicrodeposits($params = null, $opts = null)
  187. {
  188. $url = $this->instanceUrl() . '/verify_microdeposits';
  189. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  190. $this->refreshFrom($response, $opts);
  191. return $this;
  192. }
  193. }