Giter Site home page Giter Site logo

Comments (22)

gioboa avatar gioboa commented on August 14, 2024

Hi, with Stripe do you have the confirmed order in your vendure environment?
@prasmalla do you have any feedback?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

Ok, it seems like I only see it in Stripe. In Vendure I see it as "Adding Items" not as Payment processed.
Edit: I can see the payments in Vendure now as Payment Settled. But the original issue is still there.

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

This is the Stripe Component

import {
	$,
	component$,
	noSerialize,
	useContext,
	useStore,
	useVisibleTask$,
} from '@builder.io/qwik';
import { useLocation } from '@builder.io/qwik-city';
import type { Stripe, StripeElements } from '@stripe/stripe-js';
import { loadStripe } from '@stripe/stripe-js';
import { APP_STATE } from '~/constants';
import { ENV_VARIABLES } from '~/env';
import { createStripePaymentIntentMutation } from '~/providers/shop/checkout/checkout';
import CreditCardIcon from '../icons/CreditCardIcon';
import XCircleIcon from '../icons/XCircleIcon';

let _stripe: Promise<Stripe | null>;
function getStripe(publishableKey: string) {
	if (!_stripe && publishableKey) {
		_stripe = loadStripe(publishableKey);
	}
	return _stripe;
}
const stripePromise = getStripe(ENV_VARIABLES.VITE_STRIPE_PUBLISHABLE_KEY);

export default component$(() => {
	const appState = useContext(APP_STATE);
	const baseUrl = useLocation().url.origin;
	const store = useStore({
		clientSecret: '',
		resolvedStripe: noSerialize({} as Stripe),
		stripeElements: noSerialize({} as StripeElements),
		error: '',
	});
	useVisibleTask$(async () => {
		store.clientSecret = await createStripePaymentIntentMutation();

		await stripePromise.then((stripe) => {
			store.resolvedStripe = noSerialize(stripe as Stripe);
			store.stripeElements = noSerialize(stripe?.elements({ clientSecret: store.clientSecret }));
			store.stripeElements?.create('payment').mount('#payment-form');
		});
	});

	return (
		<div class="flex flex-col items-center max-w-xs">
			<div id="payment-form" class="mb-8"></div>
			{store.error !== '' && (
				<div class="rounded-md bg-red-50 p-4 mb-8">
					<div class="flex">
						<div class="flex-shrink-0">
							<XCircleIcon />
						</div>
						<div class="ml-3">
							<h3 class="text-sm font-medium text-red-800">We ran into a problem with payment!</h3>
							<p class="text-sm text-red-700 mt-2">{store.error}</p>
						</div>
					</div>
				</div>
			)}

			<button
				class="flex px-6 bg-primary-600 hover:bg-primary-700 items-center justify-center space-x-2 py-3 border border-transparent text-base font-medium rounded-md shadow-sm text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
				disabled={!_stripe}
				onClick$={$(async () => {
					const result = await store.stripeElements?.submit();
					if (!result?.error) {
						const result = await store.resolvedStripe?.confirmPayment({
							elements: store.stripeElements,
							clientSecret: store.clientSecret,
							confirmParams: {
								return_url: `${baseUrl}/checkout/confirmation/${appState.activeOrder.code}`,
							},
						});

						if (result?.error) {
							store.error = result.error.message as string;
						}
					} else {
						store.error = result.error.message as string;
					}
				})}
			>
				<CreditCardIcon />
				<span>Pay with Stripe</span>
			</button>
		</div>
	);
});`

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

Ok, it seems like I only see it in Stripe. In Vendure I see it as "Adding Items" not as Payment processed.

Ignore this, I can see it in Vendure now - I just had to update the Stripe Webhook for the Stripe Test Environment. So it does show as Payment Settled as expected. But the issue with the Order Confirmation Page is still there

from storefront-qwik-starter.

prasmalla avatar prasmalla commented on August 14, 2024

have not seen this issue before, do you have a repo for us to reproduce this behavior?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

I have created a repo that demonstrates the error: one would need a Stripe test api though and the linked Vendure backend.
Here is the repo https://github.com/bulecampur/stripe-confirmation-page
Excuse the atrocious buttons, I have not configured the checkout pages yet so they are difficult to see. right now (basically white on white).
I am guessing since the Stripe Component redirects towards a page but the state has not changed to "Confirmation", the stripe link cannot find anything. This may also be why items are left in the cart. If we use the dummy payment provider, it generates the page through onForward$. Is this a correct assessment?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

So I looked further at it and the behavior now is the following:

  • .Stripe returns the return_url, but it does not load the confirmation page, yet.
  • When I refresh the link manually, it loads the confirmation and updates the cart.
  • When I click on another link (for example in navigation, which uses the Link component), it updates the cart

This could lead to confusion by the customers. Í tried to add a UseVisibileTask$ to automatically reload the page with useNavigate. But this does not work. Are there any suggestions? What could be the issue? Do you not see this issue in your implementation?

from storefront-qwik-starter.

gioboa avatar gioboa commented on August 14, 2024

I think the error is here
.Stripe returns the return_url, but it does not load the confirmation page, yet.
why is not working?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

Note that the error is on a deploy to Cloudflare pages.
Is it a routing error or is it a timing error? Maybe my Vendure has not transitioned to the state paymentSettled the moment the confirmation page is loaded? And only transitions after as the stripe plugin gets confirmation from stripe.
Does it work on your clean deploy of the qwik Vendure storefront?
I'm just throwing around guesses...

from storefront-qwik-starter.

gioboa avatar gioboa commented on August 14, 2024

maybe you can add a timeout here for testing purpose. You redirecting here, isn'it?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

maybe you can add a timeout here for testing purpose. You redirecting here, isn'it?

So when I come through stripe, it resolves (timeout 5000 ms), however the store.order is null. When I reload manually, it actually loads the order.

from storefront-qwik-starter.

gioboa avatar gioboa commented on August 14, 2024

🤔 Is It grabbing the correct order code from the URL?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

Yes, the order code is correct as per console.log

from storefront-qwik-starter.

gioboa avatar gioboa commented on August 14, 2024

You can execute the gql call in the browser by changing this code.
We can look at the network tab to see the response.

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

You can execute the gql call in the browser by changing this code. We can look at the network tab to see the response.

What should I change exactly?

So I tried to log what is happening. When I land via stripe and I console.log the activeOrder from the context, it still shows up. This should not happen right? Whereas the order retrieved by the query returns null. When I manually reload, the activeOrder does not show anymore meaning that it has transitioned and the order by code query now returns the correct order.

from storefront-qwik-starter.

gioboa avatar gioboa commented on August 14, 2024

I see. The order retrieved by the query should always return the confirmed order.

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

Ok, so it seems like there is a 5-10 seconds delay until the confirmed order is ready. Using window.reload with a timer eventually gets there. But can that be the solution though?

from storefront-qwik-starter.

gioboa avatar gioboa commented on August 14, 2024

Did you check the vendure dashboard?
Is it slow there too?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

The backend seems to work fine, it's probably just waiting for the stripe confirmation via webhook? that causes this time dissonance. For now I have patched this with:

useVisibleTask$(async () => { const delayDuration = 5000; // Set the delay duration in milliseconds setTimeout(async () => { // Check if store.order is null before calling the navigate function if (store.order === null) { // Reload the page if order is still null location.reload(); } }, delayDuration); });

from storefront-qwik-starter.

prasmalla avatar prasmalla commented on August 14, 2024

also using this in production on cloudflare with timeout to refresh the page but it's for the business logic. does it work without the refresh in your local env?

from storefront-qwik-starter.

bulecampur avatar bulecampur commented on August 14, 2024

I think you need to jump through additional hoops to test stripe locally, isn't that the case? So I did not test it locally yet.

from storefront-qwik-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.