Vue Stripe
HomeGitHubTwitterOSSPHP
Vue 2 Version
Vue 2 Version
  • 🎊Welcome!
  • 💳Stripe Checkout
    • Getting Started
    • One-time Payment
    • Subscriptions
    • Sessions
    • Sessions Generator
    • Google & Apple Pay
  • 💸Stripe Elements
    • Getting Started
    • Separate Card Fields
    • Card
    • Payment
  • 🔌Vue Stripe Plugin
  • 🫂Community
  • Others
    • 💜Partners
Powered by GitBook
On this page
  • Demo
  • 1. Prepare checkout data [frontend]
  • 2. Create a Session [backend]
  • 3. Checkout using Session id [frontend]

Was this helpful?

Edit on GitHub
Export as PDF
  1. Stripe Checkout

Sessions Generator

Interactive session generator to demo checkout using sessions.

PreviousSessionsNextGoogle & Apple Pay

Last updated 3 years ago

Was this helpful?

Take note that Session ids are generated from the backend. To know more about sessions visit the documentation.

Demo

1. Prepare checkout data [frontend]

Prerequisite:

{
  "success_url": "https://vuestripe.com/stripe-checkout/sessions-generator?state=success",
  "cancel_url": "https://vuestripe.com/stripe-checkout/sessions-generator?state=cancel",
  "payment_method_types": [
    "card"
  ],
  "line_items": [
    {
      "price": "price_1I1xv3EfCmJMLhhrJ5vdGxy6",
      "quantity": 1
    }
  ],
  "mode": "payment"
}

2. Create a Session [backend]

3. Checkout using Session id [frontend]

Follow this sample code below:

<template>
  <div>
    <stripe-checkout
      ref="checkoutRef"
      :pk="publishableKey"
      :session-id="sessionId"
    />
    <button @click="submit">Checkout!</button>
  </div>
</template>

<script>
import { StripeCheckout } from '@vue-stripe/vue-stripe';
export default {
  components: {
    StripeCheckout,
  },
  data () {
    this.publishableKey = process.env.STRIPE_PUBLISHABLE_KEY;
    return {
      loading: false,
      sessionId: 'session-id', // session id from backend
    };
  },
  methods: {
    submit () {
      // You will be redirected to Stripe's secure checkout page
      this.$refs.checkoutRef.redirectToCheckout();
    },
  },
};
</script>

Create a session using the data from Step 1. Note that the "mode"="payment" means that you are creating a one-time payment session. .

💳
Session Generator Demo
Enable Checkout, and Create Products
Node.js sample here