ฉันกำลังพยายามผสานรวมกับเกตเวย์การชำระเงินใน Node และฉันสามารถโพสต์ข้อมูลได้สำเร็จ แต่ฉันต้องคว้ารหัสสถานะการตอบกลับ HTTP และเก็บไว้ในตัวแปรส่วนกลางเพื่อใช้สำหรับการตรวจสอบ
_doRequest(postData) {
const hostName = XXXXXXXXXXXXXXX;
const path = '/api/transact.php';
postData.security_key = this.security_key;
postData = querystring.stringify(postData);
const options = {
hostname: hostName,
path: path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
// Make request to Direct Post API
const req = https.request(options, (response) => {
console.log(`STATUS: ${response.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
response.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
response.on('end', () => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`);
});
response.statusCode คือสิ่งที่ฉันกำลังมองหาที่จะยกและเก็บไว้ในตัวแปรส่วนกลางเช่น const status = statusCode แต่ฉันไม่สามารถทราบได้ว่าจะต้องทำอย่างไรจึงจะบรรลุผลสำเร็จ ฉันอยากจะขอบคุณความช่วยเหลือใด ๆ!