stripe-node icon indicating copy to clipboard operation
stripe-node copied to clipboard

How to inspect Stripe's requests

Open andrecasal opened this issue 4 months ago • 6 comments

Describe the bug

I'm seeking visibility on Stripe's requests.

In this piece of code:

stripe.billingPortal.configurations.create({
	business_profile: {
		headline: `${appName} - Customer Portal`,
	},
	features: {
		customer_update: {
			enabled: true,
			allowed_updates: ['address', 'shipping', 'tax_id', 'email'],
		},
		invoice_history: { enabled: true },
		payment_method_update: { enabled: true },
		subscription_cancel: { enabled: true },
		subscription_update: {
			enabled: true,
			default_allowed_updates: ['price'],
			proration_behavior: 'always_invoice',
			products: filteredProducts,
		},
	},
})

One can't answer these questions:

  • What is the URL we’re hitting?
  • What method are we using? POST? GET?
  • What is the payload?
  • What format is the payload in? JSON? x-www-form-urlencoded?
  • What headers are we sending? How are we authenticating the request?

Some of these questions have obvious answers, but I'd much rather have full visibility:

const body = {
		business_profile: {
			headline: `${appName} - Customer Portal`,
		},
		features: {
			customer_update: {
				enabled: true,
				allowed_updates: ['address', 'shipping', 'tax_id', 'email'],
			},
			invoice_history: { enabled: true },
			payment_method_update: { enabled: true },
			subscription_cancel: { enabled: true },
			subscription_update: {
				enabled: true,
				default_allowed_updates: ['price'],
				proration_behavior: 'always_invoice',
				products: filteredProducts,
			},
		},
	}
	
	const encodedBody = encodeFormData(body)
	
	const response = await fetch(
		'https://api.stripe.com/v1/billing_portal/configurations',
		{
			method: 'POST',
			headers: {
				Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,
				'Content-Type': 'application/x-www-form-urlencoded',
			},
			body: encodedBody,
		},
	)

The common solution I see online is to set logLevel: 'debug':

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
  apiVersion: '2020-08-27',
  logLevel: 'debug',
})

But there is no such key on Stripe 16.12.0 or 17.0.0: Screenshot 2024-10-02 at 11 37 49

P.S.: I realize this question may have been asked a million times before, but I couldn't find anything in old issues.

To Reproduce

N.A.

Expected behavior

N.A.

Code snippets

No response

OS

macOS

Node version

Node v20.11.0

Library version

stripe-node 17.0.0

API version

2024-09-30.acacia

Additional context

I've also tried Fiddler and Charles to intercept and log the HTTP requests with no luck.

andrecasal avatar Oct 02 '24 10:10 andrecasal