v78
v78

Reputation: 2933

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.

Upvotes: 3

Views: 1208

Answers (1)

floatingLomas
floatingLomas

Reputation: 8747

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.

Upvotes: 1

Related Questions