public class

StripeCouponClient

extends Object
java.lang.Object
   ↳ com.wsl.modules.stripe.client.StripeCouponClient

Class Overview

Encapsulates Coupon-related Stripe API calls.

Summary

Public Constructors
StripeCouponClient()
Public Methods
Coupon createCoupon(String id, String duration, int amountOff, String currency, int durationInMonths, int maxRedemptions, int percentOff, String redeemBy, Map<String, Object> metadata)
Create a Coupon
Object deleteCoupon(String id)
Delete a Coupon
CouponCollection listAllCoupons(String createdTimestamp, TimeRange created, String endingBefore, int limit, String startingAfter)
List all Coupons
Coupon retrieveCoupon(String id)
Retrieve a Coupon
Coupon updateCoupon(String id, Map<String, Object> metadata)
Update a Coupon Updates the metadata of a coupon.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StripeCouponClient ()

Public Methods

public Coupon createCoupon (String id, String duration, int amountOff, String currency, int durationInMonths, int maxRedemptions, int percentOff, String redeemBy, Map<String, Object> metadata)

Create a Coupon

Parameters
id Unique string of your choice that will be used to identify this coupon when applying it a customer. This is often a specific code you’ll give to your customer to use when signing up (e.g. FALL25OFF). If you don’t want to specify a particular code, you can leave the ID blank and we’ll generate a random code for you.
duration Specifies how long the discount will be in effect. Can be forever, once, or repeating.
amountOff A positive integer representing the amount to subtract from an invoice total (required if percent_off is not passed)
currency Currency of the amount_off parameter (required if amount_off is passed)
durationInMonths Required only if duration is repeating If duration is repeating, a positive integer that specifies the number of months the discount will be in effect
maxRedemptions A positive integer specifying the number of times the coupon can be redeemed before it’s no longer valid. For example, you might have a 50% off coupon that the first 20 readers of your blog can use.
percentOff A positive integer between 1 and 100 that represents the discount the coupon will apply (required if amount_off is not passed)
redeemBy Unix timestamp specifying the last time at which the coupon can be redeemed. After the redeem_by date, the coupon can no longer be applied to new customers.
metadata A set of key/value pairs that you can attach to a coupon object. It can be useful for storing additional information about the coupon in a structured format.
Returns
  • Coupon created
Throws
StripeConnectorException when there is a problem with the Connector

public Object deleteCoupon (String id)

Delete a Coupon

Parameters
id The ID of the coupon to be deleted.
Returns
  • An object with the deleted coupon's ID and a deleted flag upon success. Otherwise, this call throws an error, such as if the coupon has already been deleted.
Throws
StripeConnectorException when there is a problem with the Connector

public CouponCollection listAllCoupons (String createdTimestamp, TimeRange created, String endingBefore, int limit, String startingAfter)

List all Coupons

Parameters
createdTimestamp A filter on the list based on the object created field. The value can be a string with an integer Unix timestamp,...
created ... or it can be a dictionary with the following options: gt, gte, lt, lte
endingBefore A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_bar, your subsequent call can include ending_before=obj_bar in order to fetch the previous page of the list.
limit A limit on the number of objects to be returned. Limit can range between 1 and 100 items.
startingAfter A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include starting_after=obj_foo in order to fetch the next page of the list.
Returns
  • A Map with a data property that contains an array of up to limit coupons, starting after coupon starting_after. Each entry in the array is a separate coupon object. If no more coupons are available, the resulting array will be empty. This request should never throw an error.
Throws
StripeConnectorException when there is a problem with the Connector

public Coupon retrieveCoupon (String id)

Retrieve a Coupon

Parameters
id The ID of the desired coupon.
Returns
  • Coupon retrieved
Throws
StripeConnectorException when there is a problem with the Connector

public Coupon updateCoupon (String id, Map<String, Object> metadata)

Update a Coupon Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable.

Parameters
id The ID of the coupon to be updated.
metadata A set of key/value pairs that you can attach to a coupon object. It can be useful for storing additional information about the coupon in a structured format.
Returns
  • Coupon updated
Throws
StripeConnectorException when there is a problem with the Connector