"verification_status":"FAILURE" always fails - PayPal-Node-SDK - paypal

I've been trying to integrate a PAYMENT.SALE.COMPLETED notification webhook.
I searched all over the internet and its always fails with this error code: "verification_status":"FAILURE", status:
const verifyWebHook = (header, body, token, webhookId) => {
return new Promise((resolve, reject) => {
const VERIFY_URL = 'https://api.sandbox.paypal.com/v1/notifications/verify-webhook-signature';
const webhookObjJSON = '{' +
'"auth_algo": "' + header['paypal-auth-algo'] + '"' +
',"cert_url": "' + header['paypal-cert-url'] + '"' +
',"transmission_id": "' + header['paypal-transmission-id'] + '"' +
',"transmission_sig": "' + header['paypal-transmission-sig'] + '"' +
',"transmission_time": "' + header['paypal-transmission-time'] + '"' +
',"webhook_id": "' + webhookId + '"' +
',"webhook_event": ' + JSON.stringify(body) +
'}',
validationReqOptions = {
method: 'POST',
uri: VERIFY_URL,
headers: {
'Authorization': token,
'content-type': 'application/json'
},
body: webhookObjJSON,
}
rp(validationReqOptions)
.then((res) => {
return resolve(res)
})
.catch((err) => {
return reject(err);
});
})
}
rp is request-promise (tried with couple requests modules).
This is my request body (webhookObjJSON variable)
'{
"auth_algo":"SHA256withRSA",
"cert_url":"https://api.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-5edc0ebc",
"transmission_id":"9f1826f0-a941-11ea-b1e4-55afeaff811c",
"transmission_sig":"KxQVusuDV2ZtsjALJ/QXdo9L4voX3VmIWGMrAPbzi1phBIr4FEQz5nG6ANIkHKdOhgifO81UA2Y3ljHKQoe/8T8fozRwox+CSXAwxFVKZC63am0YjkzNDWB3DMxVQKnec8q2Yeha26gfssIG/x+lGnr+fmWAl+3OtxpS7rP7T7fckj53J+5aro1NNf+eHkqjZvAGponHJiPx8pZKXcF2aAXGzkcLB+V7FYjbOoW4QgksoyEMVZ9hqxseA/CWda9t43y+VER3xdtFqH+Z6Oyt5KZfRQ4rdAYqlU3iIgJl1RR/IiPi/YlglBqtY4HFBN9i7507uRF67cbh2hcgqIxZuQ==",
"transmission_time":"2020-06-08T04:36:29Z",
"webhook_id":"80021663DE681814L",
"webhook_event":{
"id":"WH-2WR32451HC0233532-67976317FL4543714",
"event_version":"1.0",
"create_time":"2014-10-23T17:23:52Z",
"resource_type":"sale",
"event_type":"PAYMENT.SALE.COMPLETED",
"summary":"A successful sale payment was made for $ 0.48 USD",
"resource":{
"id":"80021663DE681814L",
"create_time":"2014-10-23T17:22:56Z",
"update_time":"2014-10-23T17:23:04Z",
"amount":{
"total":"0.48",
"currency":"USD"
},
"payment_mode":"ECHECK",
"state":"completed",
"protection_eligibility":"ELIGIBLE",
"protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"clearing_time":"2014-10-30T07:00:00Z",
"parent_payment":"PAY-1PA12106FU478450MKRETS4A",
"links":[
{
"href":"https://api.paypal.com/v1/payments/sale/80021663DE681814L",
"rel":"self",
"method":"GET"
},
{
"href":"https://api.paypal.com/v1/payments/sale/80021663DE681814L/refund",
"rel":"refund",
"method":"POST"
},
{
"href":"https://api.paypal.com/v1/payments/payment/PAY-1PA12106FU478450MKRETS4A",
"rel":"parent_payment",
"method":"GET"
}
]
},
"links":[
{
"href":"https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714",
"rel":"self",
"method":"GET"
},
{
"href":"https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714/resend",
"rel":"resend",
"method":"POST"
}
]
}
}'
Thank you for your help!

It appears you're trying to verify a mock webhook generated by the simulator at https://developer.paypal.com/docs/api-basics/notifications/webhooks/simulator/
As that page notes, "You cannot verify the simulator-generated events."

Related

I have problems with the connection of dialogflow cx and firestore database

can someone help me with dialogflow cx webhooks and add data to Firestore, this is my index.js code but it does not store in the database. Thanks
Hello, can someone help me with dialogflow cx webhooks and add data to Firestore, this is my index.js code but it does not store in the database. Thanks
const Firestore = require('#google-cloud/firestore');
const PROJECTID = 'ia-proyecto';
const firestore = new Firestore({
projectId: PROJECTID,
timestampsInSnapshots: true,
});
exports.db_datos_personales = (req, res) => {
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}
console.log('Dialogflow Request body: ' + JSON.stringify(req.body));
let tag = req.body.fulfillmentInfo.tag;
console.log('Tag: ' + tag);
console.log('Session Info Parameters: ' + JSON.stringify(req.body.sessionInfo.parameters));
//
if (tag === 'nombre') {
const COLLECTION_NAME = 'Datos_Personales';
let Nombre_Usuario = replaceAll(JSON.stringify(req.body.sessionInfo.parameters['nombre_usuario']), '"', '');
let Ciudad_Usuario = replaceAll(JSON.stringify(req.body.sessionInfo.parameters['ciudad_usuario']), '"', '');
console.log('Nombre usuario: ' + Nombre_Usuario);
console.log('Ciudad usuario: ' + Ciudad_Usuario);
const data = {
Nombre_Usuario: Nombre_Usuario,
Ciudad_Usuario: Ciudad_Usuario,
};
console.log(JSON.stringify(data));
var answer = 'Welcome to the Cloud Audio family, '+ Nombre_Usuario +'! Enjoy our services.';
return firestore.collection(COLLECTION_NAME)
.set(data)
.then(doc => {
return res.status(200).send({
fulfillmentResponse: {
messages: [{
text: {
text: [answer]
}
}]
}
});
}).catch(err => {
console.error(err);
return res.status(404).send({ error: 'unable to store', err });
});
//
} else if (tag === 'pregunta') {
const COLLECTION_NAME = 'Pregunta_Usuario';
let pregunta_usuario = replaceAll(JSON.stringify(req.body.sessionInfo.parameters['pregunta_usuario']), '"', '');
console.log('Pregunta Usuario: ' + pregunta_usuario);
const data = {
pregunta_usuario: pregunta_usuario
};
console.log(JSON.stringify(data));
var answer = 'Your plan has been changed to the '+ pregunta_usuario + ' service.';
return firestore.collection(COLLECTION_NAME)
.doc(phone_number)
.update(data)
.then(doc => {
return res.status(200).send({
fulfillmentResponse: {
messages: [{
text: {
text: [answer]
}
}]
}
});
}).catch(err => {
console.error(err);
return res.status(404).send({ error: 'unable to update field', err });
});
}
};
I hope to have a solution, since I was more than a week and I can't find anything.

expo Facebook.useAuthRequest validation error

I am using "expo-auth-session" package for login to Facebook
SDK Version: 45
Platforms(Android/iOS/web/all): expo go and iOS
Code I got from the manual https://docs.expo.dev/guides/authentication/#facebook
import * as React from 'react';
import * as WebBrowser from 'expo-web-browser';
import * as Facebook from 'expo-auth-session/providers/facebook';
import { ResponseType } from 'expo-auth-session';
import { Button } from 'react-native';
WebBrowser.maybeCompleteAuthSession();
export default function App() {
const [request, response, promptAsync] = Facebook.useAuthRequest({
clientId: '<YOUR FBID>',
responseType: ResponseType.Code,
});
React.useEffect(() => {
if (response?.type === 'success') {
const { code } = response.params;
const fetchData = async () => {
const requestOptions = {
method: 'GET',
headers: {
"Content-Type": "application/json"
}
};
const link = "https://graph.facebook.com/v7.0/oauth/access_token" +
"?client_id=*******************" +
"&redirect_uri=https://auth.expo.io/#********/**********" +
"&client_secret=*******************" +
"&code=" + code;
const response = await fetch(link, requestOptions);
const body = await response.json();
console.log("fetchData response: => ", body);
}
fetchData().catch(console.error);
}
}, [response]);
return (
<Button
disabled={!request}
title="Login"
onPress={() => {
promptAsync();
}}
/>
);
}
So I am getting “Code” param from the api and then I should change it to “access token” with request like that
const link = "https://graph.facebook.com/v7.0/oauth/access_token" +
"?client_id=*******************" +
"&redirect_uri=https://auth.expo.io/#********/**********" +
"&client_secret=*******************" +
"&code=" + code;
Response:
{
"error": Object {
"code": 1,
"fbtrace_id": "A2avpevCrHdiCPhfadWl-S3",
"message": "Invalid code verifier. Code verifier should be a cryptographically random string using the characters A-Z, a-z, 0-9, and the punctuation characters -._~ (hyphen, period, underscore, and tilde), between 43 and 128 characters long.",
"type": "OAuthException",
},
}
How come it asking some verifier? Where should I get that param? I do not see anything like that in the manual.
I found the solution to this. In object request, you can find that "validator" param which was generated automatically. All you need resend it when getting token.
const link = "https://graph.facebook.com/oauth/access_token" +
"?client_id=*************" +
"&redirect_uri=*********************" +
"&client_secret=***********************" +
"&grant_type=authorization_code" +
"&code_verifier=" + request?.codeVerifier +
"&code=" + code;

Malformed stream when uploading file to Box

I am trying to upload a file to Box drive using its upload API, but I get Malformed Stream error response. I cannot figure out why?
var axios = require('axios');
var data = '\n--------------------------foo_bar_baz\ncontent-disposition: form-data; name="attributes"\n\n{"name":"ENC-mob.key.lock", "parent":{"id":"115921805292"}}\n--------------------------foo_bar_baz\ncontent-disposition: form-data; name="file"; filename="ENC-mob.key.lock"\ncontent-type: text/plain\n\n1\n\n--------------------------foo_bar_baz--';
var config = {
method: 'post',
url: 'https://upload.box.com/api/2.0/files/content',
headers: {
'Content-Type': 'multipart/form-data; boundary=------------------------foo_bar_baz',
'Authorization': 'Bearer ' + this.credentials.access_token,
},
data : data
};
console.log("Data: " + _params);
try {
let response: any = await axios(config)
console.log(JSON.stringify(response));
return response;
} catch(error) {
console.log(error + "\nError Message: " + error.message + "\nError response: " + JSON.stringify(error.response));
return error;
};

[TypeError: undefined is not an object (evaluating 'this.setState')]

I get a problem with ReactNative and axios. I would like save the response URL in a state variable but I have this problem :
[TypeError: undefined is not an object (evaluating 'this.setState')]
The function :
githubGetUrl = () => {
axios({
method: 'get',
url: 'http://' + global.IP_ADDRESS + ':8080/github/link'
}).then(function(response) {
this.setState({githuburl: response.data.LINK})
console.log('Résultat [' + this.state.githuburl + ']')
}).catch(function(error) {
console.log(error)
});
}
}
The constructor :
constructor (props) {
super(props)
this.state = {
clicked: '',
githuburl: ''
}
}
I already search on web but I don't find the origin of the problem...
If someone can help me, I will appreciate it.
Thanks
You can try to use arrow function in then
githubGetUrl = () => {
axios({
method: 'get',
url: 'http://' + global.IP_ADDRESS + ':8080/github/link'
}).then((response) => {
this.setState({githuburl: response.data.LINK})
console.log('Résultat [' + this.state.githuburl + ']')
}).catch(function(error) {
console.log(error)
});
}
}

Amazon ses.sendEmail - how to attach pdf file?

I am trying to attach pdf in email using Amazon ses.sendEmail. But i don't know the param key to do it. Without attachment it is working perfectly. Here is what I have tried.
` var ses = new AWS.SES()
var params = {
Destination: {
ToAddresses: [
'xxx',
]
},
Message: {
Body: {
Html: {
Data: msg,
Charset: 'UTF-8'
}
},
Subject: { /* required */
Data: 'Test Mail',
Charset: 'UTF-8'
}
},
Attachment:{
},
Source: 'yyy'
};
ses.sendEmail(params, function(err, data) {
if (err) {// an error occurred}
oDialog.close();
MessageToast.show("Email not sent. Some problem occurred!");
}
else {
oDialog.close();
MessageToast.show("Email sent successfully!");
}
});`
For anyone else that want to add attachments to an SES email, here is what I did for a lambda in NodeJS: use Nodemailer with the SES transport.
npm install --save nodemailer
and in the code:
// create Nodemailer SES transporter
const transporter = nodemailer.createTransport({
SES: new AWS.SES({
apiVersion: '2010-12-01',
region: "eu-west-1", // SES is not available in eu-central-1
})
});
const emailTransportAttachments = [];
if (attachments && attachments.length !== 0) {
emailTransportAttachments = attachments.map(attachment => ({
filename: attachment.fileName,
content: attachment.data,
contentType: attachment.contentType,
}));
}
const emailParams = {
from,
to,
bcc,
subject,
html,
attachments: emailTransportAttachments,
};
return new Promise((resolve, reject) => {
transporter.sendMail(emailParams, (error, info) => {
if (error) {
console.error(error);
return reject(error);
}
console.log('transporter.sendMail result', info);
resolve(info);
});
});
Currently, you can only send attachments if you use the raw email API, e.g.:
var ses_mail = "From: 'Your friendly UI5 developer' <" + email + ">\n"
+ "To: " + email + "\n"
+ "Subject: AWS SES Attachment Example\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n"
+ "--NextPart\n"
+ "Content-Type: text/html; charset=us-ascii\n\n"
+ "This is the body of the email.\n\n"
+ "--NextPart\n"
+ "Content-Type: text/plain;\n"
+ "Content-Disposition: attachment; filename=\"attachment.txt\"\n\n"
+ "Awesome attachment" + "\n\n"
+ "--NextPart";
var params = {
RawMessage: { Data: new Buffer(ses_mail) },
Destinations: [ email ],
Source: "'Your friendly UI5 developer' <" + email + ">'"
};
var ses = new AWS.SES();
ses.sendRawEmail(params, function(err, data) {
if(err) {
oDialog.close();
MessageToast.show("Email sent successfully!");
}
else {
oDialog.close();
MessageToast.show("Email sent successfully!");
}
});