Access to XMLHttpRequest at 'https://loggworks-c15c9e56f169.herokuapp.com/mangopay/cardregistration' from origin 'https://profesional-loggworks.netlify.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Closed this issue · 1 comments
Deleted user commented
Hello, I need help with this. I started getting this error when I shifted from sandbox to production. how do I fix this cors issue?
below is my code
`app.use(cors());
app.post('/mangopay/cardregistration', async (req, res) => {
try {
const authToken = await getAuthToken();
// Step 1: Create a card registration request
const cardRegistrationData = {
UserId: req.body.userId, // Replace with the actual user's MangoPay ID
Currency: 'GBP', // Replace with the desired currency
};
const cardRegistrationResponse = await axios.post(
`https://api.mangopay.com/v2.01/${clientId}/cardregistrations`,
cardRegistrationData,
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`,
},
}
);
// Step 2: Save the AccessKey and PreregistrationData
const accessKey = cardRegistrationResponse.data.AccessKey;
const preregistrationData = cardRegistrationResponse.data.PreregistrationData;
const cardRegistrationURL = cardRegistrationResponse.data.CardRegistrationURL;
// Step 3: Make a request to the CardRegistrationURL
const tokenizationResponse = await axios.post(cardRegistrationURL, {
accessKeyRef: accessKey,
data: preregistrationData,
cardNumber: req.body.cardNumber,
cardExpirationDate: req.body.expiryDatef,
cardCvx: req.body.cvv,
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded', // Set the correct Content-Type
},
});
// Step 4: Update the card registration with the RegistrationData from the tokenization server
const registrationData = tokenizationResponse.data;
const updateResponse = await axios.put(
`https://api.mangopay.com/v2.01/${clientId}/cardregistrations/${cardRegistrationResponse.data.Id}`,
{ RegistrationData: registrationData },
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`,
},
}
);
// Handle the MangoPay API response or perform any additional actions
const cardId = updateResponse.data.CardId;
res.json({ cardId });
} catch (error) {
}
});`
fredericdelordm commented
Hello @loggworks,
It's not related to the SDK