#stevez4081_api

1 messages ¡ Page 1 of 1 (latest)

terse haloBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1270201087747555341

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

ocean scroll
#

Question #2: what's the difference between a preview invoice and an upcoming one? Is there a way to simply create a subscription from the preview invoice? I know I can just create a subscription with the same items but in theory a customer's credit could change and the amount charged would change, I'm not sure how to validate the new subscription matches the upcoming / preview one.

silk umbra
#

For subscription with trial, the subscription will be active with trialing status even the card is not collected. If you wish to collect the card details before the subscription with trial, I'd recommend using Setup Intent to collect the payment method first (https://docs.stripe.com/payments/save-and-reuse), then create the subscription with the saved payment method

ocean scroll
#

Questions #3 is there a bullet proof way to convert a price in a currency into the "unitAmount" I copied the docs here: https://docs.stripe.com/currencies and made this function, but I'm unsure a good way to test that it's working correctly. Is there an api I could call that would then give me the "conversion"? Here's the config and function:

const selectCurrencyConfig = (currency: string): CurrencyConfig => {
  const config = (currenciesConfig as CurrenciesConfig)[currency];
  if (!config) {
    throw new Error(`Currency config not found for ${currency}`);
  }
  return config;
};

const getStripeUnitAmount = (amount: number, currency: string): number => {
  const currencyConfig = selectCurrencyConfig(currency);
  const { decimals = 2, significantDigit = 1 } = currencyConfig;
  return Math.round((amount * 10 ** decimals) / 10 ** significantDigit) * 10 ** significantDigit;
};
...
  "bhd": { "decimals": 3, "significantDigit": 2 },
  "isk": { "decimals": 2, "significantDigit": 2 },
  "jod": { "decimals": 3, "significantDigit": 2 },
  "jpy": { "decimals": 0, "minUnitAmount": 50 },
 ...
}

See what currencies you can use for making charges and for paying out to your bank account.

silk umbra
#

Question #2: what's the difference between a preview invoice and an upcoming one?
Upcoming invoices are computed in-memory and not persisted whereas preview invoices are.

Is there a way to simply create a subscription from the preview invoice? I know I can just create a subscription with the same items but in theory a customer's credit could change and the amount charged would change, I'm not sure how to validate the new subscription matches the upcoming / preview one.
Creating a subscription from preview is not supported. The subscription will be re-computed again at the time of creation since the credit might change as you mentioned