JSFiddle - React, Tailwind, and code Playground
JavaScript
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
myHeaders.append("Authorization", "Bearer <api key>");
var lineItems = ["<Search for Product's Price>"];
var simCardCount = "<search for sim card count>"
var isRush = "<yes/no>"
var urlencoded = new URLSearchParams();
let i = 0
if (isRush == "yes") {
urlencoded.append("line_items["+i+"][price]", "price_1JT9yxDVJA2loejy1g1TEhAU")
urlencoded.append("line_items["+i+"][quantity]", "1");
i += 1
}
for (var [n,v] of lineItems.entries()){
if (v == "price_1JSm6kDVJA2loejy1ru3Vn38") {
urlencoded.append("line_items[" + i + "][price]", v)
urlencoded.append("line_items[" + i + "][quantity]", simCardCount);
i += 1
} else {
urlencoded.append("line_items[" + i + "][price]", v)
urlencoded.append("line_items[" + i + "][quantity]", "1");
i += 1
}
}
urlencoded.append("cancel_url", "https://gpx-control.bubbleapps.io/version-test/ai_shoppage");
urlencoded.append("success_url", "https://gpx-control.bubbleapps.io/version-test/ai_shoppage?session_id={CHECKOUT_SESSION_ID}");
urlencoded.append("mode", "subscription");
urlencoded.append("payment_method_types[0]", "card");
urlencoded.append("allow_promotion_codes", "true");
urlencoded.append("automatic_tax[enabled]", "true");
urlencoded.append("billing_address_collection", "required");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};
var ids
fetch("https://api.stripe.com//v1/checkout/sessions", requestOptions)
.then(response => response.json())
.then(data => ids = data.id)
.then(bubble_fn_stripeSessionID)
.catch(error => console.log('error', error));