PayPal IPN NodeJS production invalid, sandbox is valid

WaluigiDev
New Community Member

Our sandbox/testing environment is able to verify IPNs from paypal, they return 'VALID'. However, our production IPN validation, being the same as our sandbox validation just with the production URL to 'https://ipnpb.paypal.com/cgi-bin/webscr', always returns 'INVALID'.

The content of the IPN body is almost identical, just changing a few alphanumeric values and no new special characters. We also made sure the buttons on the front-end pointed to the right URLs/environment.

Is there something we are missing? We went through all the troubleshooting on PayPal developer's site, but we still cannot get an IPN to be valid.

Here is the code:
```

Spoiler

let postreq = 'cmd=_notify-validate'

// Iterate the original request payload object and prepend its keys and values to the post string
Object.keys(req.body).map((key) => {
postreq = `${postreq}&${key}=${req.body[key]}`
return key
})

const options = {
url: 'https://ipnpb.paypal.com/cgi-bin/webscr', // production
// url: 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr', // sandbox
method: 'POST',
headers: {
'Content-Length': postreq.length
},
encoding: 'utf-8',
body: postreq
}

// Request to paypal to verify authenticity of IPN request
request(options, (error, response, resBody) => {
if (error || response.statusCode !== 200) {
reject(new Error(error))
return
}

// Validate the response from PayPal and resolve / reject the promise.
if (resBody.substring(0, 😎 === 'VERIFIED') {
// resolve(true)
isValidIPN = true
console.log('PAYPAL IPN OBJECT: ', resBody)
} else if (resBody.substring(0, 7) === 'INVALID') {
console.log('IPN Message is invalid.')
console.log(resBody)
} else {
console.log('Unexpected response body.')
console.log('URB error: ', new Error(error))
}

// Do database actions
}

 

```

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.