def get_context_data(self, **kwargs):
        """
        Creates and returns a Stripe Checkout Session
        """
        # Get Parent Context
        context = super().get_context_data(**kwargs)

        # to initialise Stripe.js on the front end
        context["STRIPE_PUBLIC_KEY"] = (
            djstripe_settings.djstripe_settings.STRIPE_PUBLIC_KEY
        )

        success_url = self.request.build_absolute_uri(
            reverse("djstripe_example:success")
        )
        cancel_url = self.request.build_absolute_uri(reverse("home"))

        # get the id of the Model instance of djstripe_settings.djstripe_settings.get_subscriber_model()
        # here we have assumed it is the Django User model. It could be a Team, Company model too.
        # note that it needs to have an email field.
        id = self.request.user.id

        # example of how to insert the SUBSCRIBER_CUSTOMER_KEY: id in the metadata
        # to add customer.subscriber to the newly created/updated customer.
        metadata = {
            str(djstripe_settings.djstripe_settings.SUBSCRIBER_CUSTOMER_KEY): id
        }
        session_dict = {
            "payment_method_types": ["card"],
            # payment_method_types=["bacs_debit"],  # for bacs_debit
            "payment_intent_data": {
                "setup_future_usage": "off_session",
                # so that the metadata gets copied to the associated Payment Intent and Charge Objects
                "metadata": metadata,
            },
            "line_items": [
                {
                    "price_data": {
                        "currency": "usd",
                        # "currency": "gbp",  # for bacs_debit
                        "unit_amount": 2000,
                        "product_data": {
                            "name": "Sample Product Name",
                            "images": ["https://i.imgur.com/EHyR2nP.png"],
                            "description": "Sample Description",
                        },
                    },
                    "quantity": 1,
                },
            ],
            "mode": "payment",
            "success_url": success_url,
            "cancel_url": cancel_url,
            "metadata": metadata,
        }

        try:
            # retreive the Stripe Customer.
            customer = models.Customer.objects.get(subscriber=self.request.user)

            print("Customer Object in DB.")

            # ! Note that Stripe will always create a new Customer Object if customer id not provided
            # ! even if customer_email is provided!
            session = stripe.checkout.Session.create(
                customer=customer.id, **session_dict
            )

        except models.Customer.DoesNotExist:
            print("Customer Object not in DB.")

            session = stripe.checkout.Session.create(**session_dict)

        context["CHECKOUT_SESSION_ID"] = session.id

        return context

        Creates and returns a Stripe Checkout Session
        
tests/apps/example/views.py