modempay.coupons.create() to provide percentage or fixed-amount discounts (in GMD), set duration, redemption limits, and restrictions like minimum purchase amounts. Manage them with methods like retrieve, list, update, or delete. Apply coupons to a PaymentIntent to instantly reduce the transaction amount, perfect for promotions or loyalty rewards. Simple, flexible, and developer-friendly!
Creating a Coupon
Usemodempay.coupons.create() to create a coupon. Coupons can offer a fixed amount or percentage discount and support options like duration, redemption limits, and restrictions.
Example: Creating a 15% Off Coupon for a Market Promotion
name: Descriptive name (e.g., “Market Fest”).percent_off: Percentage discount (e.g., 15 for 15%). Use amount_off for fixed amounts.currency: Set to “GMD” for all amounts.duration: “once”, “repeating”, or “forever”.duration_in_months: Required if duration is “repeating”.max_redemptions: Maximum uses of the coupon.redeem_by: Expiry date.restrictions: Conditions like minimum_amount or first_time_transaction.
Retrieving a Coupon
Fetch a specific coupon’s details usingmodempay.coupons.retrieve().
Listing Coupons
View all coupons withmodempay.coupons.list(), with options to paginate or filter.
Updating a Coupon
Modify a coupon’s properties (e.g., name, redemption limits) usingmodempay.coupons.update().
Deleting a Coupon
Permanently remove a coupon withmodempay.coupons.delete().
Applying a Coupon to a Payment Intent
Apply a coupon to a PaymentIntent to discount the transaction. Include the coupon ID in thecoupon field when creating a PaymentIntent.
- Modem Pay validates the coupon’s restrictions (e.g.,
minimum_amount,first_time_transaction). - If valid, the discount (
percent_offoramount_off) is applied to thePaymentIntent’s amount. - The coupon’s
times_redeemedincrements upon successful application.
Best Practices
- Validate Restrictions: Ensure the coupon’s
minimum_amountaligns with your pricing. - Test Thoroughly: Use test API keys to simulate coupon scenarios.
- Monitor Usage: Track active coupons and redemptions with
modempay.coupons.list().
Troubleshooting
- Invalid Coupon: Verify the coupon ID and ensure
valid: true. - Restrictions Not Met: Check if the
PaymentIntentmeetsminimum_amountorfirst_time_transactionrequirements. - API Errors: Confirm API key setup and network connectivity.