Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source callback #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add source callback #119

wants to merge 1 commit into from

Conversation

methyl
Copy link

@methyl methyl commented Sep 12, 2018

Checkout.js now supports source callback: https://stripe.com/docs/checkout#required

@fantapop
Copy link

I'm trying to test out your PR however its not working for me unless I pass both a source handler and a token handler.

If I use only the token handler, it passes a token as expected to the back end.
If I use only the source handler, it fails with this error and never calls the callback

Uncaught TypeError: this.fn is not a function
    at TokenCallback.trigger (checkout.js:3)
    at TokenCallback.trigger (checkout.js:3)
    at IframeView.onToken (checkout.js:3)
    at IframeView.closed (checkout.js:3)
    at Object.closed (checkout.js:3)
    at RPC.processMessage (checkout.js:2)
    at RPC.processMessage (checkout.js:2)
    at RPC.message (checkout.js:2)
    at checkout.js:2

If I pass both a token handler and a source handler it gives this error on form load:

index.js:2178 StripeCheckout.open: The options 'source' and 'token' can not be used at the same time.
You can learn about the available configuration options in the Checkout docs:
https://stripe.com/docs/checkout

But then calls the source handler with all of the correct details after the charge.

Note that I am not the maintainer, but I am looking forward to this support. Thanks for your additions here.

@fantapop
Copy link

@methyl any ideas here?

@methyl
Copy link
Author

methyl commented Sep 24, 2018

@fantapop I will be updating this PR this or the next week, I know the fix already and will make sure to fix it here as well

@fantapop
Copy link

fantapop commented Oct 3, 2018

@methyl have you had an time to look at this?

@methyl
Copy link
Author

methyl commented Oct 5, 2018

@fantapop since I had some other issues with this lib, I just went with lazy approach and pulled it directly into my source repo. The problem is that StripeCheckout API is broken and won't allow you to pass the source callback to the open method as allows to do with the token. The solution is to pass to StripeCheckout.configure(), if you do that it will recognize the callback correctly and your error will be gone.

  updateStripeHandler(prevSource) {
    if (!this.stripeHandler || this.props.source !== prevSource) {
      this.stripeHandler = StripeCheckout.configure({
        source: this.props.source,
        key: this.props.stripeKey,
      })
    }
  }
      
  onScriptLoaded = () => {
    if (!this.stripeHandler) {
      this.stripeHandler = StripeCheckout.configure({
        key: this.props.stripeKey,
        source: this.props.source,
      })
      if (this.hasPendingClick) {
        this.showStripeDialog()
      }
    }
  }

@fantapop
Copy link

fantapop commented Oct 5, 2018 via email

@Jarvl
Copy link

Jarvl commented Apr 3, 2019

Any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants