question

sguv avatar image
sguv asked parquet76 edited

CORS error with iframe integration

I am trying to implement the iframe integration and receiving this error when I call clover.createToken().

Access to fetch at 'https://token-sandbox.dev.clover.com/v1/tokens' from origin 'https://checkout.sandbox.dev.clover.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

e-commerce api
10 |2000

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

parquet76 avatar image
parquet76 answered parquet76 edited

Why are you calling the tokens endpoint? The point of using the iframe is that tokenization happens on the Clover side to reduce your PCI exposure.

4 comments
10 |2000

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

sguv avatar image sguv commented ·

It is the script loaded from https://checkout.sandbox.dev.clover.com/sdk.js which is doing the calling, when clover.createToken() is invoked.

0 Likes 0 ·
parquet76 avatar image parquet76 sguv commented ·
You are probably passing an invalid key, you should be using the merchant's public key (also, make sure your environment matches the environment the key exists in).
0 Likes 0 ·
sguv avatar image sguv parquet76 commented ·
I am using the apiAccessKey to initialize Clover, which was returned from the /pakms/apikey endpoint as described in the docs, on the sandbox environment, which is the same where my merchant is. When looking at the imported script which is doing the calling, the same key is used as well so there's no mistake.
0 Likes 0 ·
Show more comments
parquet76 avatar image
parquet76 answered parquet76 edited

You are going down the wrong path and not making much sense. The token call is made from within the iframe on a page Clover controls, so you worrying about or trying to do something with CORs headers makes no sense. I am guessing you are using the wrong token when you are initializing the SDK. You should be using the PAKMS or public key. Here is a working example which basically proves there is no CORs issue on Clover's end. However, I am not sure if the token comes from a developer app making a call to retrieve the PAKMS or an e-commerce merchant token.

https://codepen.io/davidmarginian/pen/JjXLRwM

Note, you cannot make the charge request from the front-end or you will get a CORs error. That call MUST be made from the server.

10 |2000

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

parquet76 avatar image
parquet76 answered parquet76 commented

FYI, I just logged into my developer account, create a merchant ecommerce token, plugged the public key into the working example I posted above (https://codepen.io/davidmarginian/pen/JjXLRwM) and it worked. So, everything is working fine, not sure what you are doing wrong.

10 |2000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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

Welcome to the
Clover Developer Community