I am trying to make a test charge and I'm getting a weird response
This is the code and I basically lifted this from the docs except for a few changes.
const Flutterwave = require("flutterwave-node-v3");
const flw = new Flutterwave(
process.env.FLW_PUBLIC_KEY,
process.env.FLW_SECRET_KEY,
process.env.FLW_ENCRYPTION_KEY
);
exports.cardCharge = async (req, res) => {
// Initiating the transaction
const data = {
card_number: "5531886652142950",
cvv: "564",
expiry_month: "09",
expiry_year: "23",
currency: "NGN",
amount: "100",
redirect_url: "https://www.google.com",
fullname: "Flutterwave Developers",
email: "[email protected]",
phone_number: "09000000000",
enckey: process.env.FLW_ENCRYPTION_KEY,
"tx_ref":"MC-3243e",
pin: "3310",
};
try {
const response = await flw.Charge.card(data);
console.log(response);
} catch (error) {
console.log(error);
}
}
and this is the response I get back.
[AxiosError: Request failed with status code 502] {
code: 'ERR_BAD_RESPONSE',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function] },
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, /',
'Content-Type': 'application/json',
'User-Agent': 'axios/0.27.2',
'Content-Length': 2
},
method: 'post',
url: 'https://moneywave.herokuapp.com/banks',
data: '{}'
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype] {
abort: [Function (anonymous)],
aborted: [Function (anonymous)],
connect: [Function (anonymous)],
error: [Function (anonymous)],
socket: [Function (anonymous)],
timeout: [Function (anonymous)],
prefinish: [Function: requestOnPrefinish]
},
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'moneywave.herokuapp.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 10,
connecting: false,
_hadError: false,
_parent: null,
_host: 'moneywave.herokuapp.com',
_readableState: [ReadableState],
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular *1],
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 26,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: true,
[Symbol(kSetKeepAliveInitialDelay)]: 60,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object],
[Symbol(RequestTimeout)]: undefined
},
_header: 'POST /banks HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'Content-Type: application/json\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Content-Length: 2\r\n' +
'Host: moneywave.herokuapp.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype],
requests: [Object: null prototype] {},
sockets: [Object: null prototype],
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'POST',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/banks',
_ended: true,
res: IncomingMessage {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
socket: [TLSSocket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: [Array],
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 502,
statusMessage: 'Bad Gateway',
client: [TLSSocket],
_consuming: true,
_dumped: false,
req: [Circular *1],
responseUrl: 'https://moneywave.herokuapp.com/banks',
redirects: [],
[Symbol(kCapture)]: false,
[Symbol(kHeaders)]: [Object],
[Symbol(kHeadersCount)]: 12,
[Symbol(kTrailers)]: null,
[Symbol(kTrailersCount)]: 0,
[Symbol(RequestTimeout)]: undefined
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'moneywave.herokuapp.com',
protocol: 'https:',
_redirectable: Writable {
_writableState: [WritableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 2,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: [Circular *1],
_currentUrl: 'https://moneywave.herokuapp.com/banks',
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
'content-type': [Array],
'user-agent': [Array],
'content-length': [Array],
host: [Array]
}
},
response: {
status: 502,
statusText: 'Bad Gateway',
headers: {
connection: 'close',
server: 'Cowboy',
date: 'Fri, 12 Aug 2022 23:16:46 GMT',
'content-length': '2476',
'content-type': 'text/html; charset=utf-8',
'cache-control': 'no-cache, no-store'
},
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object],
method: 'post',
url: 'https://moneywave.herokuapp.com/banks',
data: '{}'
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'POST /banks HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'Content-Type: application/json\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Content-Length: 2\r\n' +
'Host: moneywave.herokuapp.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'POST',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/banks',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'moneywave.herokuapp.com',
protocol: 'https:',
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
data: '\n' +
' \n' +
' \n' +
' <title>Heroku | Welcome to your new app!</title>\n' +
" <style type='text/css'>\n" +
' body {\n' +
' background-color: white;\n' +
' color: #333333;\n' +
' font-family: Arial, sans-serif;\n' +
' margin: 0;\n' +
' padding: 36px;\n' +
' line-height: 1;\n' +
' font-size: 14px; }\n' +
'\n' +
' .section {\n' +
' margin-bottom: 36px; }\n' +
' .section.friendly {\n' +
' color: #222222; }\n' +
' .section.friendly h1 {\n' +
' font-size: 26px;\n' +
' background-color: #dad8e4;\n' +
' padding: 18px 22px 15px 22px;\n' +
' margin: 0;\n' +
' overflow: hidden; }\n' +
' .section.friendly h1 strong {\n' +
' display: inline-block;\n' +
' float: left; }\n' +
' .section.friendly h1 small {\n' +
' display: inline-block;\n' +
' float: right;\n' +
' text-align: right;\n' +
' font-size: 18px;\n' +
' padding-top: 4px;\n' +
' color: #333333; }\n' +
' .section.friendly .article {\n' +
' border: 4px solid #dad8e4;\n' +
' padding: 24px 18px 18px 18px; }\n' +
' .section.friendly .article h3 {\n' +
' font-size: 20px;\n' +
' margin: 0 0 18px 0; }\n' +
' .section.friendly .article a {\n' +
' color: #6b6ceb; }\n' +
' .section.friendly .article a:visited {\n' +
' color: #1d1d3b; }\n' +
' .section.friendly .article p {\n' +
' font-size: 14px; }\n' +
' .section.friendly .article ul {\n' +
' list-style-type: square; }\n' +
' .section.original {\n' +
' background-color: #eeeeee;\n' +
' color: #444444; }\n' +
' .section.original h2 {\n' +
' background-color: #dddddd;\n' +
' margin: 0;\n' +
' padding: 18px 22px 18px 22px;\n' +
' font-size: 20px; }\n' +
' .section.original pre {\n' +
' margin: 0;\n' +
' padding: 18px 22px 18px 22px;\n' +
' overflow: auto;\n' +
' font-family: monaco, monospaced; }\n' +
' .section.original pre code {\n' +
' display: block;\n' +
' font-size: 11px;\n' +
' width: 100%; }\n' +
' </style>\n' +
' \n' +
' \n' +
"
\n" +
"
\n" +
'
Heroku | Welcome to your new app!
\n' +
"
\n" +
'
Refer to the documentation if you need help deploying.
\n' +
'
\n' +
'
\n' +
'
\n' +
' \n' +
' '
}
}