I use Payment Provider Framework to create a payment connector, I am modifying the default methods trying to get luck to access to an external API (my current API for the payment method) but there are some issues that I can not solve.
When I use https in the request I got this response.
Client network socket disconnected before secure TLS connection was established
I reviewed some questions and answers here in the forum and I saw that some people uses http and they add a header to force the use of https, like this.
'X-VTEX-Use-Https': true,
But making that change I got Request failed with status code 401, if I send the request directly using POSTMAN I got a successful response.
Here the curl:
curl --location 'https://emojihub.yurace.pro/api/random'
Here the code
import axios from "axios";
.
.
.
export default class MyExampleConnector extends PaymentProvider {
async cancel(cancellation: CancellationRequest): Promise<CancellationResponse> {
const options = {
headers: {
'X-VTEX-Use-Https': true
}
};
try {
const req = await axios.get('http://emojihub.yurace.pro/api/random', options);
//Dummy response
const response: CancellationResponse = {
message: req.status.toString() || '',
cancellationId: cancellation.tid,
code: 'cancel-manually',
paymentId: cancellation.paymentId
}
return response;
} catch (error) {
throw new Error(error.message || '');
}
}
}