Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
breakoutModewide
<script type="text/javascript">
	// Set orderQueryUrl string value type variable with production URL
	const orderQueryUrl = "https://live-api.checkoutchamp.com/providersApi/V1/ClubMembership/OrderQueryByOrderId";
	// Set ccClientOrderQueryIterations numeric value type variable with number of order query iteraton needed to fetch required order details, currently set to 5
	const ccClientOrderQueryIterations = 5;
	var ccClientOrderCheckInterval, ccClientOrderQueryCallCount = 1;
	// function to set order data details on form rendered by viral sweep, function accepts an object type parameter contains order details
	function ccSetClientViralSweepDetails(orderData) {
		try {
			if (orderData && window.vs_prefill_field) {
				orderData.emailAddress && vs_prefill_field("email", orderData.emailAddress);
				orderData.phoneNumber && vs_prefill_field("phone", orderData.phoneNumber);
				vs_prefill_field("order_id", orderData.vendorOrderId || orderData.orderId);
				vs_prefill_field("auto_submit", "true")
			}
		} catch(err) {err;}
	}
	async function ccClientOrderQuery(payload, orderData) {
		try {
			if (payload && orderData) {
				if (ccClientOrderQueryCallCount > ccClientOrderQueryIterations) {
					ccSetClientViralSweepDetails(orderData);
					return;
				}
				ccClientOrderQueryCallCount++;
				const data = await httpMethod(orderQueryUrl, payload);
				if (data && data.result === "SUCCESS" && data.message && data.message.vendorOrderId) {
					ccSetClientViralSweepDetails(data.message);
					return;
				}
				setTimeout(function() { ccClientOrderQuery(payload, orderData); }, 3000);
			}
		} catch (err) {
			setTimeout(function() { ccClientOrderQuery(payload, orderData); }, 3000);
		}
	}
	function ccClientInitializeOrderSearchInterval() {
		if (window.location.path !== "blank") {
			ccClientOrderCheckInterval = setInterval( function() {
			try {
					const orderDataString = sessionStorage.getItem("orderData");
					const orderData = (orderDataString && JSON.parse(orderDataString)) || {};
					if (httpMethod && orderData.orderId) {
						clearInterval(ccClientOrderCheckInterval);
						if (sessionStorage.getItem("ccShopifyProducts")) {
							const payload = JSON.stringify({ "orderId": orderData.orderId, "finalizeTransaction": 1 });
							ccClientOrderQuery(payload, orderData);
						} else {
							ccSetClientViralSweepDetails(orderData);
						}
					}
				} catch (err) {err;}
			}, 3000);
		}
	}
	function vs_widget_load_callback() {
		ccClientInitializeOrderSearchInterval();
	}
</script>
<!-- Script to render viral sweep form, update script src with script URL generated from viralsweep -->
<div id="vsscript_#####_######" data-secondsdelay=""></div>
<script async type="text/javascript" src="https://app.viralsweep.com/vsa-widget-%%%%%%-%%%%%******-*****.js?sid=#####_######"></script>