私はこれが何度か議論されていることを知っています - すべてのスレッドを調査しましたが、動かすことはできません。これをあきらめる前に、最後に試してみたいです:nodejs paypal ipnは無効になります
私の環境は急行とボディタイプの最新のnodejです。私は自分のアプリを開発し、簡単なペイパルエクスプレスチェックアウトを実装しようとしました。私はpaypal-ipnを使用しましたが、Paypalから有効な応答を得ることができませんでした。私は問題であると信じられていたものを使って遊んでいました(ペイパルコールバックのための生のボディパーサーを実装し、エンコーディングとヘッダーオプションを使って、Windowsからutf8エンコーディングへのpaypalアカウントの設定を切り替えました) 。だから私は、私のアプリを離れて、プレーンでシンプルな新しい設定で一から行くことに決めました。私はネット上で見つかった別のアプローチを使用し、再び同じエラーで終わった。私は、サンドボックスが常に無効を返すと報告されることがあるので、「ライブ」に進むことに決めました。その試みは私に50セントの取引手数料を負担しました...そして無効なままでした:-)
何とか私を混乱させるものは、私が発見した議論のほとんどが数年前です。私が2つの異なるコードを使用していたので(どちらもまだありますが)、有効であると報告されました。プログラミングロジックの一般的な間違いではないと思うのは公正だと思います。 Paypal APIが変更されたか、更新されたnodejsパッケージが何かを壊した可能性があります。あなたの誰かが正しい方向に私を指すことができる場合は、してください。
私の現在のコードです。私はそれを議論に投げ込むために、いくつかのボディータイプの選択肢を残しました。そして再び、私は借りたプルームで自分自身を飾ることを望んでいません。ほとんどのコードは、ネットからのスニペットです。
var express = require('express');
var querystring = require('querystring');
var request = require('request');
var colors = require('colors');
var bodyParser = require('body-parser');
var StringDecoder = require('string_decoder').StringDecoder;
colors.setTheme({
silly: 'rainbow',
input: 'grey',
verbose: 'cyan',
prompt: 'grey',
info: 'green',
data: 'grey',
help: 'cyan',
warn: 'yellow',
debug: 'blue',
error: 'red'
});
var app = express();
var bpJSON = bodyParser.json();
var bpUrl = bodyParser.urlencoded({
extended: false
});
var parseRaw = function (req, res, next) {
req.body = '';
var helper = '';
req.setEncoding('utf8');
var decoder = new StringDecoder('utf8');
req.on('data', function (chunk) {
req.body += decoder.write(chunk);
console.log(req.body);
});
req.on('end', function() {
next();
});
};
app.use(function (req, res, next) {
if (!~req.url.indexOf('/notipal')) bpJSON(req, res, next)
else return next();
});
app.use(function (req, res, next) {
if (!~req.url.indexOf('/notipal')) bpUrl(req, res, next)
else return next();
});
app.use(function (req, res, next) {
if (~req.url.indexOf('/notipal')) parseRaw(req, res, next)
else return next();
});
app.get('/', function (req, res) {
res.end('Response will be available on console, nothing to look here!');
});
app.post('/notipal', function (req, res) {
console.log('Received POST /'.bold);
console.log(req.body);
logger.log(req.body);
console.log('\n\n');
// STEP 1: read POST data
req.body = req.body || {};
res.send('200');
res.end();
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
var postreq = 'cmd=_notify-validate';
for (var key in req.body) {
if (req.body.hasOwnProperty(key)) {
var value = querystring.escape(req.body[key]);
postreq = postreq + "&" + key + "=" + value;
console.log('key: ' + key + ' value: ' + value);
}
}
// Step 2: POST IPN data back to PayPal to validate
console.log('Posting back to paypal'.bold);
console.log(postreq);
console.log('\n\n');
var options = {
url: 'https://www.sandbox.paypal.com/cgi-bin/webscr',
method: 'POST',
headers: {
'Connection': 'close'
},
body: postreq,
strictSSL: true,
rejectUnauthorized: false,
requestCert: true,
agent: false
};
request(options, function callback(error, response, body) {
if (!error && response.statusCode === 200) {
// inspect IPN validation result and act accordingly
if (body.substring(0, 8) === 'VERIFIED') {
// The IPN is verified, process it
console.log('Verified IPN!'.green);
console.log('\n\n');
// assign posted variables to local variables
var item_name = req.body['item_name'];
var item_number = req.body['item_number'];
var payment_status = req.body['payment_status'];
var payment_amount = req.body['mc_gross'];
var payment_currency = req.body['mc_currency'];
var txn_id = req.body['txn_id'];
var receiver_email = req.body['receiver_email'];
var payer_email = req.body['payer_email'];
//Lets check a variable
console.log("Checking variable".bold);
console.log("payment_status:", payment_status)
console.log('\n\n');
// IPN message values depend upon the type of notification sent.
// To loop through the &_POST array and print the NV pairs to the screen:
console.log('Printing all key-value pairs...'.bold)
for (var key in req.body) {
if (req.body.hasOwnProperty(key)) {
var value = req.body[key];
console.log(key + "=" + value);
}
}
} else if (body.substring(0, 7) === 'INVALID') {
// IPN invalid, log for manual investigation
console.log('Invalid IPN!'.error);
console.log('\n\n');
console.log(body);
}
}
});
});
var port = 80;
app.listen(port);
var msg = 'Listening at http://localhost:' + port;
console.log(msg.green.bold);
コンソールログには、受信して送信するための2つの同一のボディが表示されます。
アイデア?
ありがとうございます。
1日後編集: 状況がさらに好奇心を増しています。さらに調査するために、私はGithubに掲載されているPaypalsのPHPの例を使ってWamp環境をセットアップしました。私は何を言いますか:無効です。これは私を夢中にさせる...
私は現在、正確に同じ問題を抱えています。次のいずれかの答えを得ることができませんでした。あなたはこれを最後に解決したのですか? – Fizzix