cancel
Showing results for 
Search instead for 
Did you mean: 

Post request with fetch() fails. Possible CORS error.

cristian_sp
Explorer
0 Kudos

Hi.

I'm trying to do an advanced integration with PapPal, and I use a fetch() with a POST request. This request returns a '405 Method Not Allowed' error.

If I use the same request with Ajax, it works fine, but I have to do it with fetch() because Ajax is asynchronous and it doesn't work properly.

I've done all the CROS origin configurations, but I'm still in the same situation.
This is the configuration:

corsfilter.default.allowedMethods=GET POST HEAD PUT PATCH DELETE OPTIONS FETCH
corsfilter.default.allowedOrigins=*
corsfilter.default.allowedHeaders=*
xss.filter.header.X-Frame-Options=*
xss.filter.header.Access-Control-Allow-Origin=*

This is the request from js, in storefront:

// Render the button component
paypal
	.Buttons({
		// Sets up the transaction when a payment button is clicked
		createOrder: function (data) {
			return fetch(ACC.config.encodedContextPath', {
				method: "POST",
				body: {
					"paymentSource": data.paymentSource,
				}
			})
				.then((response) => response.json())
				.then((order) => order.id);
		}
	})
	.render("#paypal-button-container");

With all this setup, this is the message error I get always

cristian_sp_0-1715254796024.png

Any idea what I'm missing? I'm using the 1808.2 hybris version.

Thanx a lot.

 

Accepted Solutions (0)

Answers (0)