我正在尝试集成付款API。我用来创建付款的方法应该返回一个对象。事实上确实如此,但仅仅是因为我无法将对象带回客户端。
我知道发生这种情况是因为API的方法是异步执行的,而服务器上的方法是同步执行的(如果我没有弄错的话)。但我仍然无法弄清楚如何做到这一点,我希望你们能帮助我。
客户端呼叫服务器:
Meteor.call('createPaymentLink',NewBooking, TotalAmount ,function(result) {
console.log(result);
});
服务器端调用API:
Meteor.methods({
'createPaymentLink': function(bookingID, amount) {
//Create Booking No.
// First two digits = First two digits of booking ID
// Last two digits = Last two digits of Customer ID
var CustomerId = Bookings.findOne({_id: bookingID}).CustomerID;
var FirstPart = CustomerId.substring(0,2);
var LastPart = bookingID.slice(-2);
var rightNow = new Date();
var OrderDate = rightNow.toISOString().slice(0,10).replace(/-/g,"");
var CustomerBookingCode = (FirstPart + OrderDate + LastPart).toUpperCase();
mollieClient.payments.create({
amount: amount,
description: "Booking code: "+bookingID,
redirectUrl: "https://webshop.example.org/order/12345/"
}, Meteor.bindEnvironment(function(payment) {
return payment;
//Bookings.update({_id: bookingID}, {$set: {payment_id : PaymentUrl}});
}));
}
});
答案 0 :(得分:0)
回调的第一个参数是错误,如果一切正常,它将是null
!试试这个:
Meteor.call('createPaymentLink',NewBooking, TotalAmount ,function(err, result) {
console.log(result);
});