meteor - Paypal muestra "No token passed" al hacer clic en el botón de PayPal
paypal-express (0)
Por alguna razón, el pago exprés de PayPal no funciona conmigo y me muestra una página vacía que dice:
Sin token pasado
Debajo está mi código para obtener la respuesta del servidor desde la URL, ya que el archivo que contiene el código es global, cualquier página puede usarse para procesar la respuesta correcta.
setTimeout(function () {
var paypalToken = Router.current().params.query.token;
var paypalPayerId = Router.current().params.query.PayerID;
var price = '''';
var itemId = '''';
if (paypalToken != undefined && paypalPayerId != undefined) {
check(paypalToken, String);
check(paypalPayerId, String);
check(price, String);
check(itemId, String);
Meteor.call(''fetchItemId'', paypalToken, function (err, data) {
if (err) {
alert(err);
}
else {
itemId = data;
Meteor.call(''fetchPriceById'', itemId, function (err, data) {
if (err) {
alert(err);
}
else {
price = data.toString();
Meteor.call(''processPayment'', paypalToken, paypalPayerId, price, function (error, result) {
Meteor.call(''fetchLatestToken'', function (err, data) {
if (err) {
alert(err);
}
else {
//console.log(data.itemId);
pathPaypal = "https://domain/item/" + data.itemId;
window.location = pathPaypal;
}
});
});
}
});
}
});
}
}
Métodos del lado del servidor
fetchItemId: function(paypalToken){
check(paypalToken, String);
purchasesData = Purchases.findOne( { paypalToken: paypalToken });
return purchasesData.itemId;
},
fetchPriceById: function(itemId){
check(itemId, String);
itemData = Products.findOne( { _id: itemId });
return itemData.price;
},
checkOut:function(itemId,price){
check(itemId, String);
check(price, String);
Future = Npm.require(''fibers/future'');
var accessToken = new Future();
Meteor.http.call("POST", "https://api-3t.paypal.com/nvp", {
headers: {
"Accept": "application/json",
"Accept-Language": "en_US",
"Content-Type": "application/x-www-form-urlencoded"
},
params: {
"USER": "user"
"PWD": "pass"
"SIGNATURE": "signature",
"METHOD": "SetExpressCheckout",
"VERSION": "93",
"PAYMENTREQUEST_0_AMT": price,
"PAYMENTREQUEST_0_PAYMENTACTION": "SALE",
"PAYMENTREQUEST_0_CURRENCYCODE": "USD",
"RETURNURL": "http://domain/item/"+itemId,
"CANCELURL": "http://domain/item/"+itemId,
}
},function(error,result){
if (result.statusCode === 200) {
paypalToken = decodeURIComponent(result.content.split("&")[0].split("=")[1]);
/* database operations */
try {
Purchases.insert({
itemId: itemId,
clientId: Meteor.userId(),
paypalToken: paypalToken,
status: ''0'',
createdAt: new Date()
});
}
catch(e){
console.log(''transaction in progress'');
}
data = Purchases.find( { itemId: itemId }).fetch();
//console.log(data);
accessToken.return('''');
return '''';
}
});
accessToken.wait();
},
processPayment:function(token, PayerID, price){
var accessToken = new Future();
check(token, String);
check(PayerID, String);
check(price, String);
Meteor.http.call("POST", "https://api-3t.paypal.com/nvp", {
headers: {
"Accept": "application/json",
"Accept-Language": "en_US",
"Content-Type": "application/x-www-form-urlencoded"
},
params: {
"USER": "user",
"PWD": "pwd",
"SIGNATURE": "signature",
"METHOD": "DoExpressCheckoutPayment",
"VERSION": "93",
"TOKEN": token,
"PAYERID": PayerID,
"PAYMENTREQUEST_0_PAYMENTACTION": "SALE",
"PAYMENTREQUEST_0_AMT": price,
"PAYMENTREQUEST_0_CURRENCYCODE": "USD",
}
},function(error,result){
if (result.statusCode === 200) {
try {
var purchase;
var purchase2;
purchase = Purchases.findOne( { paypalToken: token }, {sort:{$natural:-1}});
Purchases.update(purchase._id, {$set: {status: ''1''}});
}
catch(e){
console.log(''transaction in progress'');
}
accessToken.return(result);
}
});
accessToken.wait();
}