我正在尝试集成支付 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}});
}));
}
});