ApiOperations
6 months ago
Apps
6 months ago
Billing
6 months ago
BillingPortal
6 months ago
Checkout
6 months ago
Climate
6 months ago
Entitlements
6 months ago
EventData
6 months ago
Events
6 months ago
Exception
6 months ago
FinancialConnections
6 months ago
Forwarding
6 months ago
HttpClient
6 months ago
Identity
6 months ago
Issuing
6 months ago
Radar
6 months ago
Reporting
6 months ago
Service
6 months ago
Sigma
6 months ago
Tax
6 months ago
Terminal
6 months ago
TestHelpers
6 months ago
Treasury
6 months ago
Util
6 months ago
V2
6 months ago
Account.php
6 months ago
AccountLink.php
6 months ago
AccountSession.php
6 months ago
ApiRequestor.php
6 months ago
ApiResource.php
6 months ago
ApiResponse.php
6 months ago
ApplePayDomain.php
6 months ago
Application.php
6 months ago
ApplicationFee.php
6 months ago
ApplicationFeeRefund.php
6 months ago
Balance.php
6 months ago
BalanceTransaction.php
6 months ago
BankAccount.php
6 months ago
BaseStripeClient.php
6 months ago
BaseStripeClientInterface.php
6 months ago
Capability.php
6 months ago
Card.php
6 months ago
CashBalance.php
6 months ago
Charge.php
6 months ago
Collection.php
6 months ago
ConfirmationToken.php
6 months ago
ConnectCollectionTransfer.php
6 months ago
CountrySpec.php
6 months ago
Coupon.php
6 months ago
CreditNote.php
6 months ago
CreditNoteLineItem.php
6 months ago
Customer.php
6 months ago
CustomerBalanceTransaction.php
6 months ago
CustomerCashBalanceTransaction.php
6 months ago
CustomerSession.php
6 months ago
Discount.php
6 months ago
Dispute.php
6 months ago
EphemeralKey.php
6 months ago
ErrorObject.php
6 months ago
Event.php
6 months ago
ExchangeRate.php
6 months ago
File.php
6 months ago
FileLink.php
6 months ago
FundingInstructions.php
6 months ago
Invoice.php
6 months ago
InvoiceItem.php
6 months ago
InvoiceLineItem.php
6 months ago
InvoicePayment.php
6 months ago
InvoiceRenderingTemplate.php
6 months ago
LineItem.php
6 months ago
LoginLink.php
6 months ago
Mandate.php
6 months ago
OAuth.php
6 months ago
OAuthErrorObject.php
6 months ago
PaymentIntent.php
6 months ago
PaymentLink.php
6 months ago
PaymentMethod.php
6 months ago
PaymentMethodConfiguration.php
6 months ago
PaymentMethodDomain.php
6 months ago
Payout.php
6 months ago
Person.php
6 months ago
Plan.php
6 months ago
Price.php
6 months ago
Product.php
6 months ago
ProductFeature.php
6 months ago
PromotionCode.php
6 months ago
Quote.php
6 months ago
Reason.php
6 months ago
RecipientTransfer.php
6 months ago
Refund.php
6 months ago
RelatedObject.php
6 months ago
RequestTelemetry.php
6 months ago
ReserveTransaction.php
6 months ago
Review.php
6 months ago
SearchResult.php
6 months ago
SetupAttempt.php
6 months ago
SetupIntent.php
6 months ago
ShippingRate.php
6 months ago
SingletonApiResource.php
6 months ago
Source.php
6 months ago
SourceMandateNotification.php
6 months ago
SourceTransaction.php
6 months ago
Stripe.php
6 months ago
StripeClient.php
6 months ago
StripeClientInterface.php
6 months ago
StripeObject.php
6 months ago
StripeStreamingClientInterface.php
6 months ago
Subscription.php
6 months ago
SubscriptionItem.php
6 months ago
SubscriptionSchedule.php
6 months ago
TaxCode.php
6 months ago
TaxDeductedAtSource.php
6 months ago
TaxId.php
6 months ago
TaxRate.php
6 months ago
ThinEvent.php
6 months ago
Token.php
6 months ago
Topup.php
6 months ago
Transfer.php
6 months ago
TransferReversal.php
6 months ago
Webhook.php
6 months ago
WebhookEndpoint.php
6 months ago
WebhookSignature.php
6 months ago
Coupon.php
143 lines
| 1 | <?php |
| 2 | |
| 3 | // File generated from our OpenAPI spec |
| 4 | namespace AmeliaVendor\Stripe; |
| 5 | |
| 6 | /** |
| 7 | * A coupon contains information about a percent-off or amount-off discount you |
| 8 | * might want to apply to a customer. Coupons may be applied to <a href="https://stripe.com/docs/api#subscriptions">subscriptions</a>, <a href="https://stripe.com/docs/api#invoices">invoices</a>, |
| 9 | * <a href="https://stripe.com/docs/api/checkout/sessions">checkout sessions</a>, <a href="https://stripe.com/docs/api#quotes">quotes</a>, and more. Coupons do not work with conventional one-off <a href="https://stripe.com/docs/api#create_charge">charges</a> or <a href="https://stripe.com/docs/api/payment_intents">payment intents</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 null|int $amount_off Amount (in the <code>currency</code> specified) that will be taken off the subtotal of any invoices for this customer. |
| 14 | * @property null|(object{products: string[]}&StripeObject) $applies_to |
| 15 | * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. |
| 16 | * @property null|string $currency If <code>amount_off</code> has been set, the three-letter <a href="https://stripe.com/docs/currencies">ISO code for the currency</a> of the amount to take off. |
| 17 | * @property null|StripeObject $currency_options Coupons defined in each available currency option. Each key must be a three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a> and a <a href="https://stripe.com/docs/currencies">supported currency</a>. |
| 18 | * @property string $duration One of <code>forever</code>, <code>once</code>, or <code>repeating</code>. Describes how long a customer who applies this coupon will get the discount. |
| 19 | * @property null|int $duration_in_months If <code>duration</code> is <code>repeating</code>, the number of months the coupon applies. Null if coupon <code>duration</code> is <code>forever</code> or <code>once</code>. |
| 20 | * @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. |
| 21 | * @property null|int $max_redemptions Maximum number of times this coupon can be redeemed, in total, across all customers, before it is no longer valid. |
| 22 | * @property null|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. |
| 23 | * @property null|string $name Name of the coupon displayed to customers on for instance invoices or receipts. |
| 24 | * @property null|float $percent_off Percent that will be taken off the subtotal of any invoices for this customer for the duration of the coupon. For example, a coupon with percent_off of 50 will make a $ (or local equivalent)100 invoice $ (or local equivalent)50 instead. |
| 25 | * @property null|int $redeem_by Date after which the coupon can no longer be redeemed. |
| 26 | * @property int $times_redeemed Number of times this coupon has been applied to a customer. |
| 27 | * @property bool $valid Taking account of the above properties, whether this coupon can still be applied to a customer. |
| 28 | */ |
| 29 | class Coupon extends ApiResource |
| 30 | { |
| 31 | const OBJECT_NAME = 'coupon'; |
| 32 | use \AmeliaVendor\Stripe\ApiOperations\Update; |
| 33 | const DURATION_FOREVER = 'forever'; |
| 34 | const DURATION_ONCE = 'once'; |
| 35 | const DURATION_REPEATING = 'repeating'; |
| 36 | /** |
| 37 | * You can create coupons easily via the <a |
| 38 | * href="https://dashboard.stripe.com/coupons">coupon management</a> page of the |
| 39 | * Stripe dashboard. Coupon creation is also accessible via the API if you need to |
| 40 | * create coupons on the fly. |
| 41 | * |
| 42 | * A coupon has either a <code>percent_off</code> or an <code>amount_off</code> and |
| 43 | * <code>currency</code>. If you set an <code>amount_off</code>, that amount will |
| 44 | * be subtracted from any invoice’s subtotal. For example, an invoice with a |
| 45 | * subtotal of <currency>100</currency> will have a final total of |
| 46 | * <currency>0</currency> if a coupon with an <code>amount_off</code> of |
| 47 | * <amount>200</amount> is applied to it and an invoice with a subtotal of |
| 48 | * <currency>300</currency> will have a final total of <currency>100</currency> if |
| 49 | * a coupon with an <code>amount_off</code> of <amount>200</amount> is applied to |
| 50 | * it. |
| 51 | * |
| 52 | * @param null|array{amount_off?: int, applies_to?: array{products?: string[]}, currency?: string, currency_options?: array<string, array{amount_off: int}>, duration?: string, duration_in_months?: int, expand?: string[], id?: string, max_redemptions?: int, metadata?: null|array<string, string>, name?: string, percent_off?: float, redeem_by?: int} $params |
| 53 | * @param null|array|string $options |
| 54 | * |
| 55 | * @return Coupon the created resource |
| 56 | * |
| 57 | * @throws Exception\ApiErrorException if the request fails |
| 58 | */ |
| 59 | public static function create($params = null, $options = null) |
| 60 | { |
| 61 | self::_validateParams($params); |
| 62 | $url = static::classUrl(); |
| 63 | list($response, $opts) = static::_staticRequest('post', $url, $params, $options); |
| 64 | $obj = \AmeliaVendor\Stripe\Util\Util::convertToStripeObject($response->json, $opts); |
| 65 | $obj->setLastResponse($response); |
| 66 | return $obj; |
| 67 | } |
| 68 | /** |
| 69 | * You can delete coupons via the <a |
| 70 | * href="https://dashboard.stripe.com/coupons">coupon management</a> page of the |
| 71 | * Stripe dashboard. However, deleting a coupon does not affect any customers who |
| 72 | * have already applied the coupon; it means that new customers can’t redeem the |
| 73 | * coupon. You can also delete coupons via the API. |
| 74 | * |
| 75 | * @param null|array $params |
| 76 | * @param null|array|string $opts |
| 77 | * |
| 78 | * @return Coupon the deleted resource |
| 79 | * |
| 80 | * @throws Exception\ApiErrorException if the request fails |
| 81 | */ |
| 82 | public function delete($params = null, $opts = null) |
| 83 | { |
| 84 | self::_validateParams($params); |
| 85 | $url = $this->instanceUrl(); |
| 86 | list($response, $opts) = $this->_request('delete', $url, $params, $opts); |
| 87 | $this->refreshFrom($response, $opts); |
| 88 | return $this; |
| 89 | } |
| 90 | /** |
| 91 | * Returns a list of your coupons. |
| 92 | * |
| 93 | * @param null|array{created?: array|int, ending_before?: string, expand?: string[], limit?: int, starting_after?: string} $params |
| 94 | * @param null|array|string $opts |
| 95 | * |
| 96 | * @return Collection<Coupon> of ApiResources |
| 97 | * |
| 98 | * @throws Exception\ApiErrorException if the request fails |
| 99 | */ |
| 100 | public static function all($params = null, $opts = null) |
| 101 | { |
| 102 | $url = static::classUrl(); |
| 103 | return static::_requestPage($url, Collection::class, $params, $opts); |
| 104 | } |
| 105 | /** |
| 106 | * Retrieves the coupon with the given ID. |
| 107 | * |
| 108 | * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key |
| 109 | * @param null|array|string $opts |
| 110 | * |
| 111 | * @return Coupon |
| 112 | * |
| 113 | * @throws Exception\ApiErrorException if the request fails |
| 114 | */ |
| 115 | public static function retrieve($id, $opts = null) |
| 116 | { |
| 117 | $opts = \AmeliaVendor\Stripe\Util\RequestOptions::parse($opts); |
| 118 | $instance = new static($id, $opts); |
| 119 | $instance->refresh(); |
| 120 | return $instance; |
| 121 | } |
| 122 | /** |
| 123 | * Updates the metadata of a coupon. Other coupon details (currency, duration, |
| 124 | * amount_off) are, by design, not editable. |
| 125 | * |
| 126 | * @param string $id the ID of the resource to update |
| 127 | * @param null|array{currency_options?: array<string, array{amount_off: int}>, expand?: string[], metadata?: null|array<string, string>, name?: string} $params |
| 128 | * @param null|array|string $opts |
| 129 | * |
| 130 | * @return Coupon the updated resource |
| 131 | * |
| 132 | * @throws Exception\ApiErrorException if the request fails |
| 133 | */ |
| 134 | public static function update($id, $params = null, $opts = null) |
| 135 | { |
| 136 | self::_validateParams($params); |
| 137 | $url = static::resourceUrl($id); |
| 138 | list($response, $opts) = static::_staticRequest('post', $url, $params, $opts); |
| 139 | $obj = \AmeliaVendor\Stripe\Util\Util::convertToStripeObject($response->json, $opts); |
| 140 | $obj->setLastResponse($response); |
| 141 | return $obj; |
| 142 | } |
| 143 | } |