简体   繁体   中英

Apply Stripe Coupon

I'm using Stripe's default form for payment processing. How can I add a coupon field? I've created a coupon, but I'm not sure how I would process the coupon code.

<form class="efocus" action="form_process.php?source=payment" method="post">
    <input type="hidden" name="fee" value="1795">
    <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
          data-key="<?php echo $stripe['publishable_key']; ?>"
          data-amount=1795 data-description="Month-to-month Package">
    </script>
</form>

Is this possible or do I need to build a custom form?

You can't Add a coupon Field to the Pop Up Form shown by using the stripe JS. Hopefully they will add this ability. It would be extremely helpful.

You can still add a the coupon code field between the form tags, but that field will not appear in the form that pops up. It will appear underneath the actual stripe checkout button.

<form class="efocus" action="form_process.php?source=payment" method="post">
<input type="hidden" name="fee" value="1795">
<script
    src="https://checkout.stripe.com/v2/checkout.js" 
    class="stripe-button"
    data-key="<?php echo $stripe['publishable_key']; ?>"
    data-amount=1795 data-description="Month-to-month Package">
</script>

<input type="text" name="discount" value="YOUR_DISCOUNT_ID_HERE" />

</form>

This is definitely not ideal. Since there will now be an input field under the button. So you may want to code your own Stripe Form?

Anyone who tells you that you can add Fields to the POP up form, please get a link to where it says that in the documentation, or a link to any working example, demo, etc anywhere on the internet.

You can't add a coupon to Checkout. Checkout only creates the token to charge the customer. The coupon is applied when the token is returned to the server. Here's a code sample from stripe

stripe.Customer.create(
  source=token,
  plan="basic_monthly",
  email="payinguser@example.com",
  coupon="coupon_ID"
)

This should be a comment, but I don't yet have enough reputation.

Here's a simple checkout form to get you going, per @Brev Tiw's suggestion to build one:

<form action="" method="POST" id="payment-form">
    <span class="payment-errors"></span>

    <div class="row">
      <div class="3u -4u 12u$(small)">
       <label>
         <span>Coupon Code</span>
         <input type="text" size="20" data-stripe="coupon" placeholder="" value=""/>
       </label>
      </div>
    </div>


    <div class="row">
      <div class="3u -4u 12u$(small)">
       <label>
         <span>Card Number</span>
         <input type="text" size="20" data-stripe="number"/>
       </label>
      </div>

      <div class="1u 12u$(small)">
        <label>
         <span>CVC</span>
          <input type="text" size="4" data-stripe="cvc"/>
        </label>
      </div>
    </div>

    <div class="row">
      <div class="2u -4u 12u$(small)">
        <span><strong>Exp. Month</strong></span>
        <div class="select-wrapper">
                    <select data-stripe="exp-month" name="exp-month" id="exp-month">
                        <option value="01">01</option>
                        <option value="02">02</option>
                        <option value="03">03</option>
                        <option value="04">04</option>
                        <option value="05">05</option>
                        <option value="06">06</option>
                        <option value="07">07</option>
                        <option value="08">08</option>
                        <option value="09">09</option>
                        <option value="10">10</option>
                        <option value="11">11</option>
                        <option value="12">12</option>
                    </select>
        </div></div>


        <div class="2u 12u$(small)">
        <span><strong>Exp. Year</strong></span>
        <div class="select-wrapper">
                    <select data-stripe="exp-year" name="exp-year" id="exp-year">
                        <option value="2015">2015</option>
                        <option value="2016">2016</option>
                        <option value="2017">2017</option>
                        <option value="2018">2018</option>
                        <option value="2019">2019</option>
                        <option value="2020">2020</option>
                        <option value="2021">2021</option>
                        <option value="2022">2022</option>
                        <option value="2023">2023</option>
                        <option value="2024">2024</option>
                        <option value="2025">2025</option>
                    </select>
        </div><br />
    </div><br />
    </div>

    <div>

     <div>
        <h1></h1>
     <input type="submit" value="Pay now" class="special" />
    </div>
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM