mobilestripe-payments

How to test my app with stripe test account?


So I have my app and my account in Stripe Dashboard and I can toggle test mode, but all of my accounts on the app still use live stripe key. Here is example of implementation in Strapi:

    module.exports = {
  createPaymentIntent: async (ctx, next) => {
    try {
      const {
        amount,
        currency,
        company_name,
        buyer_id,
        customer,
        selectedCard,
        company_id,
        offer_name,
        connected_account,
        is_free_trial,
        buyer_email,
        isTestUser,
        isTestCompany,
      } = ctx.request.body.productData;

      const fee = is_free_trial ? 0 : amount * 0.05;
      if (isTestUser !== isTestCompany) {
        ctx.throw(400, "Error in create payment intent");
      }
      const useTestKey = isTestUser && isTestCompany;
      const stripeKey = useTestKey
        ? process.env.STRIPE_SECRET_KEY
        : process.env.STRIPE_SECRET_KEY_LIVE;
      ...

In the app, I have a button Create an account where user on click of it is redirected to Stripe and can create its Stripe account, but that always happens with stripe live key. Do I need to hardcode isTestUser to true everywhere or can I test it in some simpler way?


Solution

  • To test in Stripe, you need to use your test API keys when doing things like creating a PaymentIntent - it looks like you are using your live mode keys here.

    Here are their docs on testing: https://docs.stripe.com/testing-use-cases#test-mode