context = window rest = context.JK.Rest() logger = context.JK.logger LocationActions = context.LocationActions UserStore = context.UserStore @Subscription = React.createClass({ mixins: [Reflux.listenTo(@LocationStore, "onLocationsChanged")] getInitialState: () -> { clicked: false, selectedCountry: null, selectedPlan: null, subscription: null } onLocationsChanged: (countries) -> console.log("countries in ", countries) @setState({countries: countries}) onCountryChanged: (e) -> val = $(e.target).val() @setState({selectedCountry: val}) currentCountry: () -> this.state.selectedCountry || this.props.selectedCountry || '' onPlanChanged: (e) -> val = $(e.target).val() @setState({selectedPlan: val}) currentPlan: () -> this.state.selectedPlan || this.props.selectedPlan || '' openBrowser: () -> context.JK.popExternalLink("https://www.jamkazam.com/client#/subscription") onRecurlyToken: (err, token_data) -> if err console.log("error", err) # handle error using err.code and err.fields else # recurly.js has filled in the 'token' field, so now we can submit the # form to your server console.log("eintercepted", token_data) rest.createSubscription({plan_code: @state.selectedPlan, recurly_token: token_data.id}) onFormSubmit: (event) -> form = event.target console.log("ok work this", form) event.preventDefault() recurly.token(@elements, form, @onRecurlyToken) configureRecurly: () => unless window.configuredRecurly window.recurly.configure(gon.global.recurly_public_api_key) window.configuredRecurly = true componentDidMount: () -> LocationActions.load() @configureRecurly() @elements = recurly.Elements() cardElement = @elements.CardElement( inputType: 'mobileSelect', style: { fontSize: '1em', lineHeight: '42px', placeholder: { color: 'gray !important', fontWeight: 'bold', content: { number: 'Card number', cvv: 'CVC' } }, backgroundColor: 'white' invalid: { fontColor: 'red' } } ) console.log("attaching", $('#subscription-elements')) cardElement.attach('#subscription-elements') @root = $(@getDOMNode()) document.querySelector('#subscription-form').addEventListener('submit', @onFormSubmit.bind(this)) defaultText: () -> 'Select Country' render: () -> if @state.countries? countries = [``] for countryId, countryInfo of @state.countries countries.push(``) country = @state.countries[this.currentCountry()] else countries = [] countryJsx = ` ` plan_codes = [``] for plan in gon.global.subscription_codes plan_codes.push(``) plansJsx = ` ` `