-
-
Save axelgar/b7c6e489767eeca8681d396b7d1deed2 to your computer and use it in GitHub Desktop.
// Get existing payment links ✅ | |
// Get existing products ✅ | |
// Check if any existing product does not have a payment link | |
// Create new payment links | |
// Update yaml and redirect files? | |
const API_KEY = // Temporary adding api key to test locally here | |
const BASE_API_URL = "https://api.stripe.com/v1" | |
const PRODUCTS_URL = "/products" | |
const PAYMENT_LINKS_URL = "/payment_links" | |
async function generatePaymentLinks() { | |
try { | |
const paymentLinksResponse = await fetch(`${BASE_API_URL}${PAYMENT_LINKS_URL}?expand[]=data.line_items.data.price`, {headers: {Authorization: `Bearer ${API_KEY}`}}); | |
const productsResponse = await fetch(`${BASE_API_URL}${PRODUCTS_URL}`, {headers: {Authorization: `Bearer ${API_KEY}`}}); | |
if(paymentLinksResponse.ok && productsResponse.ok) { | |
const paymentLinks = await paymentLinksResponse.json(); | |
for (let paymentLink of paymentLinks.data) { | |
// To access product in payment link we go through line_items expanded object | |
console.log(paymentLink.line_items.data[0].price.product) | |
} | |
const products = await productsResponse.json(); | |
for (let product of products.data) { | |
console.log(product.id) | |
} | |
return; | |
} | |
console.error('There has been an error'); | |
} catch(e) { | |
console.error(`There has been an error: ${e}`) | |
} | |
} | |
generatePaymentLinks() |
So then in theory we also need to do something like getOrCreateProduct
for each course/start_date combo, which I've been thinking of naming cohort
. I'm also open to splitting the two, and separately keeping track of cohort
sign ups and paid status, which might allow for reusing the same product / payment link for different start dates?
Yes, one of the main things I was concerned about was how we could uniquely identify the different cohorts. I also think, combining course and startDate might be the best option... Also, I wanted to check with you again what was the mapping for course/cohort to stripe, like, is cohort each product in stripe, or is the course, and then maybe we can have payment links for the same products but different dates (I have to check if this is possible 🤔),
Duplicating this comment in the PR in case we want to keep the conversation there :)
Oh wait, I see, so it would use "Products" in the Stripe sense. Got it.