使用coffeescript呼叫Stripe并在此行中获取undefined is not a function
:$.StripeJS.stripeResponseHandler($form)
我也尝试过:
@.stripeResponseHandler($form)
-和-
StripeJS.stripeResponseHandler($form)
代码:
class StripeJS
constructor: (formId) ->
@.setStripeResponseHandlerForForm(formId)
stripeResponseHandler = (status, response, $form) ->
console.log 'In stripeResponseHandler'
if (response.error)
#Clear the errors on the form
$form.find('.payment-errors').html ''
#Show the errors on the form
$form.find('.payment-errors').append ('<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
<li>' + response.error.message + '</li>
</div>')
$form.find('button').prop 'disabled', false
else
# response contains id and card, which contains additional card details
# Insert the token into the form so it gets submitted to the server
$('#stripe_card_token').val response.id
# and submit
$form.get(0).submit()
setStripeResponseHandlerForForm: (formId) ->
Stripe.setPublishableKey $('meta[name="stripe-key"]').attr('content')
$("#{formId}").submit (event) ->
console.log 'In setStripeResponseHandlerForForm'
$form = $(this)
# Disable the submit button to prevent repeated clicks
$form.find('button').prop 'disabled', true
console.log 'About to call out to Stripe'
Stripe.createToken $form, (status,response) ->
$.StripeJS.stripeResponseHandler($form)
console.log 'Back from calling stripe'
# Prevent the form from submitting with the default action
return false
$(document).ready ->
$.StripeJS = new StripeJS('#new_agent')