PaymentLink.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * A payment link is a shareable URL that will take your customers to a hosted payment page. A payment link can be shared and used multiple times.
  6. *
  7. * When a customer opens a payment link it will open a new <a href="https://stripe.com/docs/api/checkout/sessions">checkout session</a> to render the payment page. You can use <a href="https://stripe.com/docs/api/events/types#event_types-checkout.session.completed">checkout session events</a> to track payments through payment links.
  8. *
  9. * Related guide: <a href="https://stripe.com/docs/payment-links">Payment Links API</a>
  10. *
  11. * @property string $id Unique identifier for the object.
  12. * @property string $object String representing the object's type. Objects of the same type share the same value.
  13. * @property bool $active Whether the payment link's <code>url</code> is active. If <code>false</code>, customers visiting the URL will be shown a page saying that the link has been deactivated.
  14. * @property \Stripe\StripeObject $after_completion
  15. * @property bool $allow_promotion_codes Whether user redeemable promotion codes are enabled.
  16. * @property null|string|\Stripe\Application $application The ID of the Connect application that created the Payment Link.
  17. * @property null|int $application_fee_amount The amount of the application fee (if any) that will be requested to be applied to the payment and transferred to the application owner's Stripe account.
  18. * @property null|float $application_fee_percent This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account.
  19. * @property \Stripe\StripeObject $automatic_tax
  20. * @property string $billing_address_collection Configuration for collecting the customer's billing address. Defaults to <code>auto</code>.
  21. * @property null|\Stripe\StripeObject $consent_collection When set, provides configuration to gather active consent from customers.
  22. * @property string $currency Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>, in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
  23. * @property \Stripe\StripeObject[] $custom_fields Collect additional information from your customer using custom fields. Up to 3 fields are supported.
  24. * @property \Stripe\StripeObject $custom_text
  25. * @property string $customer_creation Configuration for Customer creation during checkout.
  26. * @property null|string $inactive_message The custom message to be displayed to a customer when a payment link is no longer active.
  27. * @property null|\Stripe\StripeObject $invoice_creation Configuration for creating invoice for payment mode payment links.
  28. * @property null|\Stripe\Collection<\Stripe\LineItem> $line_items The line items representing what is being sold.
  29. * @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.
  30. * @property \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.
  31. * @property null|string|\Stripe\Account $on_behalf_of The account on behalf of which to charge. See the <a href="https://support.stripe.com/questions/sending-invoices-on-behalf-of-connected-accounts">Connect documentation</a> for details.
  32. * @property null|\Stripe\StripeObject $payment_intent_data Indicates the parameters to be passed to PaymentIntent creation during checkout.
  33. * @property string $payment_method_collection Configuration for collecting a payment method during checkout. Defaults to <code>always</code>.
  34. * @property null|string[] $payment_method_types The list of payment method types that customers can use. When <code>null</code>, Stripe will dynamically show relevant payment methods you've enabled in your <a href="https://dashboard.stripe.com/settings/payment_methods">payment method settings</a>.
  35. * @property \Stripe\StripeObject $phone_number_collection
  36. * @property null|\Stripe\StripeObject $restrictions Settings that restrict the usage of a payment link.
  37. * @property null|\Stripe\StripeObject $shipping_address_collection Configuration for collecting the customer's shipping address.
  38. * @property \Stripe\StripeObject[] $shipping_options The shipping rate options applied to the session.
  39. * @property string $submit_type Indicates the type of transaction being performed which customizes relevant text on the page, such as the submit button.
  40. * @property null|\Stripe\StripeObject $subscription_data When creating a subscription, the specified configuration data will be used. There must be at least one line item with a recurring price to use <code>subscription_data</code>.
  41. * @property \Stripe\StripeObject $tax_id_collection
  42. * @property null|\Stripe\StripeObject $transfer_data The account (if any) the payments will be attributed to for tax reporting, and where funds from each payment will be transferred to.
  43. * @property string $url The public URL that can be shared with customers.
  44. */
  45. class PaymentLink extends ApiResource
  46. {
  47. const OBJECT_NAME = 'payment_link';
  48. use ApiOperations\Update;
  49. const BILLING_ADDRESS_COLLECTION_AUTO = 'auto';
  50. const BILLING_ADDRESS_COLLECTION_REQUIRED = 'required';
  51. const CUSTOMER_CREATION_ALWAYS = 'always';
  52. const CUSTOMER_CREATION_IF_REQUIRED = 'if_required';
  53. const PAYMENT_METHOD_COLLECTION_ALWAYS = 'always';
  54. const PAYMENT_METHOD_COLLECTION_IF_REQUIRED = 'if_required';
  55. const SUBMIT_TYPE_AUTO = 'auto';
  56. const SUBMIT_TYPE_BOOK = 'book';
  57. const SUBMIT_TYPE_DONATE = 'donate';
  58. const SUBMIT_TYPE_PAY = 'pay';
  59. /**
  60. * Creates a payment link.
  61. *
  62. * @param null|array $params
  63. * @param null|array|string $options
  64. *
  65. * @throws \Stripe\Exception\ApiErrorException if the request fails
  66. *
  67. * @return \Stripe\PaymentLink the created resource
  68. */
  69. public static function create($params = null, $options = null)
  70. {
  71. self::_validateParams($params);
  72. $url = static::classUrl();
  73. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  74. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  75. $obj->setLastResponse($response);
  76. return $obj;
  77. }
  78. /**
  79. * Returns a list of your payment links.
  80. *
  81. * @param null|array $params
  82. * @param null|array|string $opts
  83. *
  84. * @throws \Stripe\Exception\ApiErrorException if the request fails
  85. *
  86. * @return \Stripe\Collection<\Stripe\PaymentLink> of ApiResources
  87. */
  88. public static function all($params = null, $opts = null)
  89. {
  90. $url = static::classUrl();
  91. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  92. }
  93. /**
  94. * Retrieve a payment link.
  95. *
  96. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  97. * @param null|array|string $opts
  98. *
  99. * @throws \Stripe\Exception\ApiErrorException if the request fails
  100. *
  101. * @return \Stripe\PaymentLink
  102. */
  103. public static function retrieve($id, $opts = null)
  104. {
  105. $opts = \Stripe\Util\RequestOptions::parse($opts);
  106. $instance = new static($id, $opts);
  107. $instance->refresh();
  108. return $instance;
  109. }
  110. /**
  111. * Updates a payment link.
  112. *
  113. * @param string $id the ID of the resource to update
  114. * @param null|array $params
  115. * @param null|array|string $opts
  116. *
  117. * @throws \Stripe\Exception\ApiErrorException if the request fails
  118. *
  119. * @return \Stripe\PaymentLink the updated resource
  120. */
  121. public static function update($id, $params = null, $opts = null)
  122. {
  123. self::_validateParams($params);
  124. $url = static::resourceUrl($id);
  125. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  126. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  127. $obj->setLastResponse($response);
  128. return $obj;
  129. }
  130. /**
  131. * @param string $id
  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\Collection<\Stripe\LineItem> list of line items
  138. */
  139. public static function allLineItems($id, $params = null, $opts = null)
  140. {
  141. $url = static::resourceUrl($id) . '/line_items';
  142. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  143. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  144. $obj->setLastResponse($response);
  145. return $obj;
  146. }
  147. }