Coupon Code & Discounts
You can do it pretty easily by creating Stripe::Coupon directly and adding the coupon either to the Customer or the Subscription if you only want to apply it to one or the other.
For example, just pass in the coupon option when creating a subscription. Pay will just forward any extra attributes to Stripe::Subscription#create.
https://stripe.com/docs/api/subscriptions/create#create_subscription-coupon
And you can update the customer with a coupon as well if you'd like apply it to any of their future purchases.
For example, just pass in the coupon option when creating a subscription. Pay will just forward any extra attributes to Stripe::Subscription#create.
https://stripe.com/docs/api/subscriptions/create#create_subscription-coupon
And you can update the customer with a coupon as well if you'd like apply it to any of their future purchases.
EDIT: So the error was in my f.text_field in _stripe.html.erb. Changing it to
Has anybody been able to add this to their app successfully? I'm getting stuck on how to get the coupon code value from the stripe form.
I don't know how to get a `coupon` into the subscription_params from the stripe form.
To start, I've added a coupon field to my accounts table and added `:coupon` to the strong params in the subscriptions & accounts controllers.
I added a coupon code field to my _stripe.html.erb form:
<%= f.text_field :coupon, class: "form-control", placeholder: "Coupon Code", required: false %>
fixed it! Hopefully this helps someone else get coupon code fields implemented! Has anybody been able to add this to their app successfully? I'm getting stuck on how to get the coupon code value from the stripe form.
I don't know how to get a `coupon` into the subscription_params from the stripe form.
To start, I've added a coupon field to my accounts table and added `:coupon` to the strong params in the subscriptions & accounts controllers.
I added a coupon code field to my _stripe.html.erb form:
<div x-data="{ open: false }" class=""> <p class="hover:underline text-xs text-neutral-7 pb-4" @click="open = !open">Have a coupon code?</p> <div x-show="open" id="coupon-field" class="form-group"> <%= f.label :coupon %> <%= f.text_field :coupon, name: nil, class: "form-control", placeholder: "Coupon Code", required: false, data: { target: "stripe.coupon" } %> </div> </div> <%= f.hidden_field :plan, value: @plan.try(:id) %> <div class="text-center"> <%= f.button local_assigns.fetch(:button, 'Subscribe'), id: 'submit-button', class: "btn btn-primary", data: { action: "click->stripe#submit", disable_with: disable_with("Processing...") } %> </div> <% end %>
I also assumed it needed to be passed in subscriptions#create:
coupon = current_account.coupon current_account.subscribe(plan: processor_id, trial_period_days: @plan.trial_period_days, coupon: coupon)
But I'm stuck on how to get the coupon from the field to the controller. I thought maybe I could add a line in the handlePaymentMethod on stripe_controller.js (edit: nope! you don't need to change stripe_controller at all)
this.addHiddenField("account[card_token]", coupon)
...but I have no coupon coming through in the params. Any ideas on how to send that data?
:insert "I have no idea what I'm doing dog" meme here:
Notifications
You’re not receiving notifications from this thread.