Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Coupons

bradrydzewski edited this page Jun 5, 2012 · 5 revisions

The coupon object

A coupon contains information about a percent-off discount you might want to apply to a customer. Coupons only apply to invoices created for recurring subscriptions and invoice items; they do not apply to one-off charges.

Godoc:
http://go.pkgdoc.org/github.com/bradrydzewski/go.stripe#Coupon

Official Stripe Documentation:
https://stripe.com/docs/api#coupon_object

Create a coupon

You can create coupons easily via the coupon management page of the Stripe dashboard. Coupon creation is also accessible via the API if you need to create coupons on the fly.

stripe.SetKey("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE")

params := stripe.CouponParams{
	Id:         "test coupon 1",
	PercentOff: 5,
	Duration:   DurationOnce,
}

coupon, err := stripe.Coupons.Create(&params)

Input Parameters:
http://go.pkgdoc.org/github.com/bradrydzewski/go.stripe#CouponParams

Official Stripe Documentation:
https://stripe.com/docs/api#create_coupon

Retrieve a coupon

Retrieves the coupon with the given ID.

stripe.SetKey("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE")

coupon, err := stripe.Coupons.Retrieve("JAVA-COUPON-0013fe18-a231-461f-b681-1b882e225fd7")

Official Stripe Documentation:
https://stripe.com/docs/api#retrieve_coupon

Delete a coupon

You can delete coupons via the coupon management page of the Stripe dashboard. However, deleting a coupon does not affect any customers who have already applied the coupon; it means that new customers can't redeem the coupon. You can also delete coupons via the API.

stripe.SetKey("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE")

_, err := stripe.Coupons.Delete("JAVA-COUPON-0013fe18-a231-461f-b681-1b882e225fd7")

Official Stripe Documentation:
https://stripe.com/docs/api#delete_coupon

List all coupons

Returns a list of your coupons.

stripe.SetKey("vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE")

coupons, err := stripe.Coupons.List()

By default, List() will only return 10 results at a time. To cycle through all Coupons you can use ListN(), which accepts a start and offset parameter:

// get a list of 10 coupons, starting at position 40 in the list of coupons
coupons, err := stripe.Coupons.ListN(10, 40)

Official Stripe Documentation:
https://stripe.com/docs/api#list_coupons

Clone this wiki locally