paypal / PayPal-node-SDK

node.js SDK for PayPal RESTful APIs
Other
1.28k stars 451 forks source link

Fix verify function #414

Closed egorsmth closed 4 years ago

egorsmth commented 5 years ago

Issue description

There is an issue with verify function. Because of using JSON.parse on body, some values are changed. For example 1.0 become 1, that is give us failure on verification in paypal. Please fix that.

xjijies commented 4 years ago

Hi @egorsmth , can you add more context about this issue? do you have code snippet?

egorsmth commented 4 years ago

@xjijies

var foo = {a: 1.0}
var bar = JSON.parse(JSON.stringify(foo))
console.log(foo === bar)
console.log(bar)

// false
// {a: 1}

so when sdk tries to validate body it fails if body contains for example 1.0 as you see in snippet

xjijies commented 4 years ago

@egorsmth Can you tell me for which flow you are facing this issue. I mean the function and file you called under lib/resources/*

egorsmth commented 4 years ago

@xjijies Notification.js line 119 When we receive webhook we should call verify function to verify that this webhook is from paypal. We pass to verify received headers and body, which sdk transforms and sends to PayPal for validation. As you see in Notification.js on line 119, sdk either call JSON.parse to parse body or just use object we passed to make a request. But if our body contains in some field value 1.0, it parsed and the stringified to 1, so paypal can't validate it.

xjijies commented 4 years ago

@egorsmth I tried with sample in PayPal-node-SDK, webhook_payload_verify.js. In eventbody decimal values are in stringify pattern, I got verification_status as Success. For var foo = '{"a": "1.0"}' parsed value result in 1.0. Do you have any use case where you send data in decimal number format.

xjijies commented 4 years ago

@egorsmth Closing this issue. Please reopen if you are still need any help further around this.