This content originally appeared on DEV Community and was authored by Manoj Gohel
Hello Folks, Here's a detailed explanation of Stripe Coupons, Promotional Codes, and Discounts, along with examples to illustrate the differences between them.
1. Coupons
Coupons are reusable discount codes created in Stripe that can be applied to invoices or subscriptions. They can offer a percentage discount, a fixed amount off, or a free trial period. Coupons are generally created to be used by multiple customers.
Example: Creating a coupon in Stripe
\Stripe\Stripe::setApiKey('your_stripe_secret_key');
$coupon = \Stripe\Coupon::create([
'percent_off' => 25,
'duration' => 'once',
]);
echo 'Coupon ID: ' . $coupon->id;
This creates a coupon that gives a 25% discount for a single use.
2. Promotional Codes
Promotional Codes are codes that customers can enter to receive a discount. These codes are linked to Coupons in Stripe and can be limited to specific customers, products, or other criteria. Promotional Codes add an extra layer of control over how and when discounts are applied.
Example: Creating a promotional code for an existing coupon
\Stripe\Stripe::setApiKey('your_stripe_secret_key');
$promoCode = \Stripe\PromotionCode::create([
'coupon' => 'coupon_id', // The ID of the existing coupon
'code' => 'SUMMER21', // The promotional code customers will use
'restrictions' => [
'first_time_transaction' => true,
],
]);
echo 'Promotional Code ID: ' . $promoCode->id;
This creates a promotional code "SUMMER21" that applies the existing coupon only for first-time transactions.
3. Discounts
Discounts represent the actual application of a Coupon or Promotional Code to a customer’s invoice or subscription. Discounts are the realized reductions in price that customers see on their bills.
Example: Applying a coupon to a customer’s subscription
\Stripe\Stripe::setApiKey('your_stripe_secret_key');
$subscription = \Stripe\Subscription::create([
'customer' => 'customer_id',
'items' => [['price' => 'price_id']],
'coupon' => 'coupon_id', // Applying the coupon directly to the subscription
]);
echo 'Subscription ID: ' . $subscription->id;
This creates a subscription for a customer and applies the coupon to give the discount.
Summary
- Coupons are reusable discount entities that can offer percentage discounts, fixed amounts off, or free trials.
- Promotional Codes are specific codes linked to coupons that customers can use to get a discount. They offer additional control and restrictions over coupon usage.
- Discounts are the actual reductions applied to customer invoices or subscriptions, reflecting the usage of Coupons or Promotional Codes.
Example Workflow
- Create a Coupon:
$coupon = \Stripe\Coupon::create([
'percent_off' => 20,
'duration' => 'repeating',
'duration_in_months' => 3,
]);
- Create a Promotional Code for the Coupon:
$promoCode = \Stripe\PromotionCode::create([
'coupon' => $coupon->id,
'code' => 'WELCOME2024',
'restrictions' => [
'first_time_transaction' => true,
],
]);
- Apply the Promotional Code to a Customer’s Subscription:
$subscription = \Stripe\Subscription::create([
'customer' => 'customer_id',
'items' => [['price' => 'price_id']],
'promotion_code' => $promoCode->id,
]);
In this workflow:
- A coupon offers a 20% discount for the first 3 months.
- A promotional code "WELCOME2024" is created for the coupon, restricted to first-time transactions.
- The promotional code is applied to a customer’s subscription, resulting in a discount for the customer.
This structure allows you to manage and apply discounts in a flexible and controlled manner, tailoring promotions to specific customer needs and business goals.
This content originally appeared on DEV Community and was authored by Manoj Gohel
Manoj Gohel | Sciencx (2024-06-27T12:07:59+00:00) Stripe Coupons, Promotional Codes, and Discounts, along with examples. Retrieved from https://www.scien.cx/2024/06/27/stripe-coupons-promotional-codes-and-discounts-along-with-examples/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.