Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe checkout.js with coupons

I'm using Stripe's checkout.js because it's so easy to setup and use. Is there a way to add coupons?

<script src="https://checkout.stripe.com/v2/checkout.js"
    class="stripe-button"
    data-key="pk_test_czwzkTp2tactuLOEOqbMTRzG"
    data-amount="2000"
    data-name="Demo Site"
    data-description="2 widgets ($20.00)"
    data-image="/128x128.png">
</script>
like image 554
Manuel Avatar asked Aug 01 '13 01:08

Manuel


People also ask

Can you use coupon codes with Stripe?

You can use coupons and promotion codes to: Apply discounts to every invoice, only one invoice, or for a certain length of time. Reduce invoice amounts by a percentage or a flat amount. Apply discounts to every subscription a customer has or only specific ones.

Can I use a 100% off coupon in Checkout Stripe?

From Stripe Support: "I'd say that you cannot add a 100% off discount in Stripe Checkout. It doesn't allow purchase below the minimum charge amount for one-time payments.

How do I customize my Checkout page on Stripe?

You can customize the look and feel of Checkout in the Stripe Dashboard. Go to Branding Settings where you can: Upload a logo or icon. Customize the Checkout page's background color, button color, font, and shapes.

Is Stripe Checkout deprecated?

Stripe will not be updating the Stripe Checkout modal to comply with Strong Customer Authentication (SCA) and as a result they no longer recommend using that integration.


4 Answers

Stripe Checkout does not currently support coupons. It's not listed in the documentation, for either the button or the custom integration.

One might wonder if there is some secret feature. However, using undocumented features, especially when it comes to your payment processor is a bad idea. Full stop.


This being Stack Overflow - let's keep digging!

Fire up jsfiddle. Paste your code into the html section. Open up developer tools so you can see network requests.

There is a en.json, which is a internationalized strings file. If there is an input for coupons, there ought to be a label saying "Enter Coupon Code" or something similar. There is none. (Sure, there is the possibility that Stripe decided to hard code this particular string, but that seems unlikely).

https://checkout.stripe.com/v3/data/languages/en.json

You can also see that inner.js is used to power the popup. Copy the source into a js beautifier and you find that there is no mention. In fact, you can see the code that parses the options and none of them have to do with coupons.

"lib/optionParser": function(exports, require, module) {     (function() {         var BOOLEAN_OPTIONS, DEFAULTS, STRING_OPTIONS, URL_OPTIONS, extractValue, helpers, toBoolean, _;         _ = require("vendor/lodash");         helpers = require("lib/helpers");         DEFAULTS = {             currency: "usd",             allowRememberMe: true         };         BOOLEAN_OPTIONS = ["billingAddress", "shippingAddress", "notrack", "nostyle", "allowRememberMe", "allowPhoneVerification", "zipCode", "trace", "alipayReusable", "bitcoin"];         STRING_OPTIONS = ["key", "amount", "name", "description", "panelLabel", "currency", "email", "locale", "alipay"];         URL_OPTIONS = ["url", "referrer", "image"]; 

You can see how each of the options here align one to one with the options that available for custom integration, which map to the options for the button (you just need to use hyphens instead of camelcase)

At this point, you can keep digging if you want to convince yourself further, but I'd be reaching out to Stripe Support and making a feature request. Happy digging!

like image 176
Liyan Chang Avatar answered Sep 29 '22 05:09

Liyan Chang


Checkout only creates the token. The coupon is applied to the customer after the token is returned to the server and customer is charged.

stripe.Customer.create(
  source=token,
  plan="basic_monthly",
  email="[email protected]",
  coupon="coupon_ID"
)
like image 35
joshlsullivan Avatar answered Sep 29 '22 06:09

joshlsullivan


Stripe have finally answered our prayers after having discount codes for Stripe checkout/payments on the roadmap for years

Discount codes are now here for Stripe checkout.

See here: https://stripe.com/docs/payments/checkout/discounts

You can also manually create it here: https://dashboard.stripe.com/coupons/create

For customer-facing promo codes, which is probably what we want, check out here: https://stripe.com/docs/billing/subscriptions/discounts/codes

(Technically, coupons are merchant-facing and promo codes are customer-facing)

like image 36
mding5692 Avatar answered Sep 29 '22 05:09

mding5692


If you want to pass a coupon code to your back end, you can just add an input field for it within the form. It won't alter the amounts in the pop-up form from stripe however, unless you wanted to get sophisticated and call additional javascript to check the parameters of the entered coupon code and change the stripe script parameters.

You can include any inputs you need within the form tags so long as they are not used by stripe.

<form action="/your-server-side-code" method="POST">
  Coupon Code: <input type="text" name="coupon_code">
  <br>
  <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="pk_test_czwzkTp2tactuLOEOqbMTRzG" data-amount="2000" data-name="Demo Site" data-description="2 widgets ($20.00)" data-image="/128x128.png">
  </script>
</form>
like image 26
Robert Kluver Avatar answered Sep 29 '22 06:09

Robert Kluver