question

httpsphp avatar image
httpsphp asked httpsphp commented

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'

I am having issues adding a hosted iframe onto my site. I am able to generate payments via Postman using my sites form using the clv... but I receive an error when running via Chrome

Error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Form:

<form action="process_payment.php" method="post" id="payment-form">

process_payment.php:

<?php

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
    $source = $_POST['cloverToken'];
}

?>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script type="text/javascript">
const data = JSON.stringify({
  "ecomind": "ecom",
  "amount": 176.00,
  "currency": "usd",
  "source": "<?php echo $source; ?>"
});

const xhr = new XMLHttpRequest();

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://scl-sandbox.dev.clover.com/v1/charges/");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer 4c..............................");

xhr.send(data);
</script>

What am I missing? Could anyone help? Thanks in advanced!

e-commerce api
settings.png (24.0 KiB)
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

David Marginian avatar image
David Marginian Deactivated answered httpsphp commented

You need to make the charge call from the server, not the browser - https://docs.clover.com/docs/using-the-clover-hosted-iframe#creating-a-charge

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

httpsphp avatar image httpsphp commented ·

I must've read that last sentence about a thousand times. Never really synced in until you mentioned it. Used cURL and worked like a charm. Please Close

0 Likes 0 ·

Welcome to the
Clover Developer Community