ga-wdi-boston / team-project

Other
2 stars 39 forks source link

Having trouble with Stripe front end api call #387

Closed 3point14guy closed 7 years ago

3point14guy commented 7 years ago

I am getting stuck when calling my ajax request from my events file. I am not getting a specific error, the program just pauses in the debugger in the handleToken function where api.makeCharge(token) is called.

We've been looking at the line but still aren't sure what we are overlooking. As there is no error message, it is making trouble shooting challenging. The syntax seems to match other working calls.


'use strict'

const api = require('./api')
// const ui = require('./ui')
// const store = require('../store.js')
const checkoutHandler = StripeCheckout.configure({
  // need to replace with Myles' working test key
  key: 'pk_test_J1qT8OyJKarB6FWIxgXVDyaG',
  locale: 'auto'
})
const handleToken = function (token) {
  console.log(token)
  console.log('handleToken function started')
  // will need function for total cost of order
  // token.amount = (store.totalCost * 100)
  token.amount = (9.99 * 100)
  **api.makeCharge(token)**
  console.log('made it past api.makeCharge in events')
    .then(() => {
      console.log('handleToken success')
      // need a clear cart function
    })
    // code to display the order

    .catch(() => {
      console.log('handleToken error')
    })
    // .catch(ui.tokenFailure)
}

const onCheckout = function (ev) {
  checkoutHandler.open({
    name: 'Fencer.com',
    description: 'Some really cool stuff!',
    token: handleToken
  })
}

const addStripeHandlers = () => {
  $('#buttonCheckout').on('click', onCheckout)
}

module.exports = {
  addStripeHandlers
}
benjimelito commented 7 years ago

One possible issue is that you cannot have a .then() after a console.log statement, you can only have a .then() after a promise (in this case, your api call). Try removing your console.log directly after the api.makeCharge call.

3point14guy commented 7 years ago

Ok, I took it back out. Same result.

I only put that console log in there after we started having problems with that line...just to double check our progress.

3point14guy commented 7 years ago

We found the problem. There were no brackets on the model export.