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

[Discussion] - Support for Nuxt or SSR Vue #72

Closed
seenickcode opened this issue Aug 31, 2019 · 37 comments
Closed

[Discussion] - Support for Nuxt or SSR Vue #72

seenickcode opened this issue Aug 31, 2019 · 37 comments

Comments

@seenickcode
Copy link

Hello,

I'm using the refactor/v3 branch with a Nuxt application. Since Nuxt supports SSR, I get errors that 'window' and 'document' are undefined, naturally because the component gets rendered server side first.

What I did to try to get things to work is fork and create my own refactor/v3 branch. It looks like the changes I made are working, one just has to

  1. import their own stripe.js file in the head component, as this cannot be created during Vue's created() because your branch requires a reference to document

  2. simply customize successUrl and cancelUrl as one normally would, as your branch seems to use window.location....

Here's the fork if you are interested. Ensure you take a look at the refactor/v3 branch I have. https://github.com/seenickcode/vue-stripe-checkout/tree/refactor/v3

I'd like to know your thoughts and if this v3 you have can be supported by SSR Vue, esp with the popular Nuxt framework.

Thanks,

@jofftiquez
Copy link
Member

Hello @seenickcode thanks for the insight. I am considering to support Nuxt sooner or later, but for now, since this version is just a testing version and is highly subjected to breaking changes, I am still experimenting stuff. But yeah, we'll get there (Nuxt).

Your suggestions makes sense, I will try to implement them the soonest. Thank you for your help.

@rahulrumalla
Copy link

Heya. The changes proposed by @seenickcode worked perfectly for me using it with nuxt. Would be great to this in 🙏

@jofftiquez
Copy link
Member

Hello @seenickcode I merged the refactor/v3 branch to master. However, I wasn't able to implement your suggestions. I removed the part where you need to load the stripe checkout right away in the index.html because of performance issues. For some, it's not ok to load the scripts you don't need immediately. And I totally agree with that. Kindly see the updated documentation and let me know what you have in mind.

I am not that knowledgeable in Nuxt so I would appreciate if you could re-fork the latest master and make some suggestions on how to properly implement the latest version in Nuxt. I will do my best to accommodate any solution.

Thank you for your help. So much appreciated.

Let's keep this thread open for discussion.

@jofftiquez jofftiquez changed the title Support for Nuxt or SSR Vue [Discussion] - Support for Nuxt or SSR Vue Dec 15, 2019
@jofftiquez
Copy link
Member

Hello @seenickcode any updates? Thanks.

@DanielRivers
Copy link

I am needing this too, I will try forking and doing a pull request

@jofftiquez
Copy link
Member

Please do @DanielRivers thanks.

@weihao
Copy link

weihao commented Mar 27, 2020

@DanielRivers ^ updates?

@jofftiquez
Copy link
Member

jofftiquez commented Mar 28, 2020

Hello all, may I know how you implemented this? So I tried to tinker around nuxtjs these past few days because of this issue. As per @seenickcode's description, he is importing the scripts the "nuxt way" in the the nuxt config (?).

Anyways, I created this component with the stripe.js included in the component, but it will only load when needed.

In the component where I want to use the checkout, I just imported the checkout component like:

import { StripeCheckout } from 'vue-stripe-checkout';

—and used it as a normal component.

There are no extra configuration in the nuxt.config.js done.

I would create a nuxt example for this if I have time this weekend. For the meantime, kindly let me know if this will work for you guys. Thanks.

Also, one of my colleague tried this implementation as well. And according to him, it also works.

NOTE

This has been tested on the generated nuxt files using yarn generate.

@jofftiquez
Copy link
Member

@weihao please check as well. Referencing #98

@weihao
Copy link

weihao commented Mar 28, 2020

Hello all, may I know how you implemented this? So I tried to tinker around nuxtjs these past few days because of this issue. As per @seenickcode's description, he is importing the scripts the "nuxt way" in the the nuxt config (?).

Anyways, I created this component with the stripe.js included in the component, but it will only load when needed.

In the component where I want to use the checkout, I just imported the checkout component like:

import { StripeCheckout } from 'vue-stripe-checkout';

—and used it as a normal component.

There are no extra configuration in the nuxt.config.js done.

I would create a nuxt example for this if I have time this weekend. For the meantime, kindly let me know if this will work for you guys. Thanks.

Also, one of my colleague tried this implementation as well. And according to him, it also works.

NOTE

This has been tested on the generated nuxt files using yarn generate.

I tried this and I got an error:

ReferenceError

window is not defined

image

window is not defined due to SSR.

Code:

<template>
  <client-only>
    <stripe-checkout
      ref="checkoutRef"
      :pk="publishableKey"
      :items="items"
      :successUrl="successUrl"
      :cancelUrl="cancelUrl"
    >
      <template slot="checkout-button">
        <button @click="checkout">Shutup and take my money!</button>
      </template>
    </stripe-checkout>
  </client-only>
</template>

<script>
import { StripeCheckout } from 'vue-stripe-checkout'
export default {
  components: {
    StripeCheckout
  },
  data: () => ({
    loading: false,
    publishableKey: process.env.PUBLISHABLE_KEY,
    items: [
      {
        sku: 'sku_FdQKocNoVzznpJ',
        quantity: 1
      }
    ],
    successUrl: 'your-success-url',
    cancelUrl: 'your-cancel-url'
  }),
  methods: {
    checkout () {
      this.$refs.checkoutRef.redirectToCheckout()
    }
  }
}
</script>

@jofftiquez
Copy link
Member

@weihao thank you for confirming. I will check this.

@weihao
Copy link

weihao commented Mar 28, 2020

@weihao thank you for confirming. I will check this.

Thanks for the support! Please keep us updated.

@jofftiquez
Copy link
Member

UPDATE: After trying a couple of things, I finally came up with something. I will make a test branch for this so we can all test it.

@weihao
Copy link

weihao commented Mar 31, 2020

UPDATE: After trying a couple of things, I finally came up with something. I will make a test branch for this so we can all test it.

Awesome, let me know and I can help out testing.

@btraxinger
Copy link

Hello @jofftiquez, were you able to make a test branch? I would gladly give you a hand testing this if needed.

@platform-kit
Copy link

I ran into this issue using this component with Gridsome. Was able to get around it by creating a duplicate of vue-stripe-checkout.js, wrapping its content in if(typeof window != 'undefined') and importing that instead.

@jofftiquez
Copy link
Member

Thanks @platform-kit for the updates.

Everyone, I'm sorry I've been really busy lately. Please kindly try the workaround solutions requested here. I will fix this soon.

@peterhoffren
Copy link

I ran into this issue using this component with Gridsome. Was able to get around it by creating a duplicate of vue-stripe-checkout.js, wrapping its content in if(typeof window != 'undefined') and importing that instead.

Im trying to get NuxtJS working with the vue-stripe-checkout, Can you explain just a bit how you managed to get this working? Thanks!

@platform-kit
Copy link

platform-kit commented Apr 29, 2020

@peterhoffren -

Duplicate the file "vue-stripe-checkout.js" from the node_modules/vue-stripe-checkout (this package). Add

if(typeof window != 'undefined') {

at the very beginning of that file, and } at the end.

Then import this file instead of the original.

@rktmatt
Copy link

rktmatt commented May 26, 2020

Hello all, may I know how you implemented this? So I tried to tinker around nuxtjs these past few days because of this issue. As per @seenickcode's description, he is importing the scripts the "nuxt way" in the the nuxt config (?).

In nuxt, you can load stripe only in your component, so you won't have to load stripe on all pages.

export default {
  head () {
    return {
      script: [
          {
          hid: 'stripe',
          src: 'https://js.stripe.com/v3'
          }
      ]
    }
  },

Looking forward to seeing this module perfectly working for nuxt.

@alzmob
Copy link

alzmob commented Jul 24, 2020

Stripe is working well locally, but I cannot see "card input" on server.
What is the reason?

@Jesus82
Copy link

Jesus82 commented Jul 30, 2020

@jofftiquez is this still in the roadmap? I want to upgrade my stripe version to support 2-way-authentication and I would like to know if I can make this work with Nuxt :)

@jofftiquez
Copy link
Member

Hello @Jesus82 as a matter of fact, yes, this is still in the roadmap. Lemme see if I can raise the priority on my schedule. I'll let you guys know. Thanks.

jennie added a commit to jennie/vue-stripe-checkout that referenced this issue Sep 5, 2020
@Rouzy777
Copy link

Rouzy777 commented Sep 7, 2020

Hello guys! I'm solved "window is not defined" problem by modifying vue-stripe-checkout files directly in node_modules. But when I'm deploying my nuxt project to netlify - it doesn't see my edited and fixed file. How can I solve this?

@platform-kit
Copy link

@Rouzy777 see my comment above. You'll need to save the modified file in a directory other than node_modules and import from there, since the node_modules directory is rebuilt upon deployment.

@Rouzy777
Copy link

Rouzy777 commented Sep 7, 2020

@platform-kit Many thanks!

@jofftiquez
Copy link
Member

Hello all, I've been working with nuxt a lot recently, while I can't really get back to this yet, I think I already have some solutions in mind that I can test in the next days. I apologize for having this issue open for so long. I will do my best to find time to fix this. Thanks and stay safe y'all.

@jofftiquez
Copy link
Member

Hello all, I hope you'll find time to read this. This is just to summarize the current state of the project, and its future.

@jofftiquez
Copy link
Member

Hello all! Here's a big update for y'all! The good news is, there are NO changes in vue-stripe-checkout at all to support nuxt implementation. Like I said, I am working a lot with nuxt recently, so I incorporated all of my learning to this solution I created.

Please check this new repository I created https://github.com/jofftiquez/vue-stripe-checkout-nuxt-demo

This demo repo also has the complete step by step guide on how to use vue-stripe-checkout in nuxt. This has been tested in both SPA and SSR mode. Likes to the demo are also included in the README

Please take your time to check it out. And let me know what you think. Thank you all for being patient with this project.

@jofftiquez
Copy link
Member

Hello guys, may I have your feedback on this? I will be closing this issue in few days if don't get anymore issues regarding Nuxt.js thank you.

@platform-kit
Copy link

@jofftiquez I don't use nuxt, but I am curious about whether the changes you make will affect vue-stripe-checkout's use in Gridsome? Is the fix Nuxt-specfic?

@jofftiquez
Copy link
Member

@jofftiquez I don't use nuxt, but I am curious about whether the changes you make will affect vue-stripe-checkout's use in Gridsome? Is the fix Nuxt-specfic?

No @platform-kit, there are actually no actual changes made to the codebase. I just created a guide on how to properly use it with nuxt.js. There should be no changes to the way the plugin works in any way. :)

@platform-kit
Copy link

@jofftiquez Then it would seem that a fix is still required to make it useable in Gridsome. Shall I open a new issue?

@jofftiquez
Copy link
Member

@jofftiquez Then it would seem that a fix is still required to make it useable in Gridsome. Shall I open a new issue?

Hmm gridsome. I'm not quite familiar with it yet. Yes please that would be awesome. So that we could also have a separate thread for it. Thanks!

@jhull
Copy link

jhull commented Sep 30, 2020

I would love to give feedback (and am excited about your new direction with this) - but I'm having issues with managing subscriptions - just don't know how to set it up properly. Any guidance?

@jofftiquez
Copy link
Member

Hello @jhull would you mind making a new issue for that? Thank you :)

@jofftiquez
Copy link
Member

Hello all! Thank you all for participating in this issue, and for being patient. All help is so much appreciated. I will be closing this issue now. Happy coding everyone! <3

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

No branches or pull requests