Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding using mock stripe for e2e tests

I came across stripe mock(https://github.com/stripe/stripe-mock) recently, for local testing,

public PaymentMethod createPaymentMethod(Card card) {
      var paymentMethodParams =
          PaymentMethodCreateParams.builder()
              .setType(Type.CARD)
              .setCard(
                  CardDetails.builder()
                      .setNumber(card.getNumber())
                      .setExpMonth((long) card.getExpiryMonth())
                      .setExpYear((long) card.getExpiryYear())
                      .setCvc(card.getCvv())
                      .build())
              .build();
      var response = testMode? "Make API call to mock stripe with params" : PaymentMethod.create(paymentMethodParams);
      return response;
  }

Now I do not want to manually make http call to stripe mock server with http client and request body, Is there a way to change something in RequestOptions or use a different dependency to make the call?

Basically, I dont want to do, something like

String url = String.format("%s%s", Stripe.getApiBase(), String.format("/v1/payment_methods/%s", ApiResource.urlEncodeId(paymentMethod)));

just somehow override the stripe base API URL.

Stripe.overrideApiBase(); is something useful, but its static to stripe java library, I want normal stripe calls to go through, when my e2e tests are running.

like image 880
v78 Avatar asked Jun 16 '26 06:06

v78


1 Answers

Stripe.overrideApiBase() is likely what you want; you'd just want to configure your app to only override it when running end to end tests.

like image 136
floatingLomas Avatar answered Jun 18 '26 19:06

floatingLomas