For-Hives/ForVoyez

Improve: plans, passer par checkouts à la place de la création unique et d'une boucle

Closed this issue · 4 comments

On boucle sur tout les variants pour créer des url de checkout

Pour améliorer ça & éviter de spam lemonsqueezy et avoir des temps de réponses énorme ( 60+s )
j'essaye de passer par :
image

(listCheckouts())
-> sauf que je reçois des données archi chimique, c'est incompréhensible...
image

Comment ça se fait que ça renvoie 1700 items ?? j'arrive pas à comprendre comment c'est possible

@LightInn aucune idée ;(

j'ai trouvé un moyen en faisant des chimistery, je pense qu'on est pas mal :

export async function getCheckouts(plans) {
	await initLemonSqueezy()

	const STORE_ID = getStoreId()
	const user = await currentUser()

	if (!user) {
		console.error('User is not authenticated.')
		throw new Error('User is not authenticated.')
	}

	const check = await listCheckouts({
		product_options: {
			redirectUrl: `${process.env.NEXT_PUBLIC_URL}/app/playground`,
		},
		checkoutData: {
			custom: {
				user_id: user.id,
			},
		},
		filter: {
			storeId: STORE_ID,
		},
		page: {
			size: 100,
		},
	})

	const checkoutUrls = {}

	for (const plan of plans) {
		const existingCheckout = check.data.data.find(
			checkout =>
				checkout.attributes.variant_id.toString() === plan.variantId.toString()
		)

		if (existingCheckout) {
			checkoutUrls[plan.variantId] = existingCheckout.attributes.url
		} else {
			const newCheckout = await createCheckout(STORE_ID, plan.variantId, {
				productOptions: {
					redirectUrl: `https://forvoyez.com/app/billing/`,
					receiptButtonText: 'Go to Dashboard',
					enabledVariants: [plan.variantId], //
				},
				checkoutData: {
					custom: {
						user_id: user.id,
					},
				},
			})
			checkoutUrls[plan.variantId] = newCheckout.data.data.attributes.url
		}
	}

	return checkoutUrls
}

je récupère tout les checkout url, et j'en crée uniquement si les liens n'existent pas déjà

je comprends pas, je ne trouve pas "getCheckouts" dans le code, et getCheckoutURL ne metais que 1-2 secondes a reagir
image

je comprends pas, je ne trouve pas "getCheckouts" dans le code, et getCheckoutURL ne metais que 1-2 secondes a reagir image

Elle est sur ma branche, et ça posait de gros problèmes dans la partie refill pour avoir tout les variants et tout les éléments liés à ça