Ayrad
Ayrad

Reputation: 4056

stripe credit card form error - the exp_month parameter should be an integer

I have a multi-step form with the second page being the billing information.

When I try to press the next button to go to the billing page, I receive the error:

*"the exp_month parameter should be an integer instead is undefined"*

My fields look like this:

<div class="field">
    <%= label_tag :card_number, "Card Number" %>
    <%= text_field_tag :card_number, nil, name:nil %>
</div>
<br/>
<div class="field">
    <%= label_tag :card_code, "Security Code (CVV)" %>
    <%= text_field_tag :card_code, nil, name:nil %>
</div>
<br/>
  <div class="field">
    <%= label_tag :card_month, "Expiration Date" %>
    <%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>
    <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
  </div>

CoffeeScript:

jQuery ->
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
  payment.setupForm()

payment =
  setupForm: ->
    $('#new_post').submit ->
      $('input[type=submit]').attr 'disabled', no
      payment.processCard()
      false

  processCard: ->
    card =
      number: $('#card_number').val()
      cvc: $('#card_code').val()
      expMonth: $('#card_month').val()
      expYear: $('#card_year').val()
    Stripe.createToken(card, payment.handleStripeResponse)

  handleStripeResponse: (status, response) ->
    if status is 200
      alert response.id
    else
      alert response.error.message

Upvotes: 0

Views: 1724

Answers (1)

mu is too short
mu is too short

Reputation: 434585

From the fine manual:

Creating a Card Token
[...]
exp_month: required
Two digit number representing the card's expiration month.

Notice that it says exp_month (and exp_year) rather than expMonth? You're sending in expMonth and expYear:

processCard: ->
  card =
    number: $('#card_number').val()
    cvc: $('#card_code').val()
    expMonth: $('#card_month').val()
    expYear: $('#card_year').val()
  Stripe.createToken(card, payment.handleStripeResponse)

and Stripe is complaining about a missing exp_month. Change the parameter names to exp_month and exp_year:

processCard: ->
  card =
    number: $('#card_number').val()
    cvc: $('#card_code').val()
    exp_month: $('#card_month').val()
    exp_year: $('#card_year').val()
  Stripe.createToken(card, payment.handleStripeResponse)

and you should have better luck.

Upvotes: 1

Related Questions