0
이 유성 서버 코드 (주로 복사 및 다른 사람에서 붙여 넣기)이 오류 제공하는 광섬유 내에서 실행해야합니다유성 : 브레인 코드는 항상
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
는 그것은 브레인 트리 샌드 박스의 벌금 지불을 보냅니다 있지만 일단 "서버 코드의 맨 아래를보십시오"라는 메시지가 끝나면 서버에서 작업해야합니다. 어떻게 수정 될 수 있습니까?
나는 'createTransaction: Meteor.wrapAsync(function (nonceFromTheClient, Payment) {...});)
을 시도했지만 아무 소용이 없습니다. Meteor.bindEnvironment
에서
//client.account.js
Template.account.onRendered(function() { //6a
Meteor.call('getClientToken', function (error, clientToken) {
if (error) {
console.log(error);
} else {
braintree.setup(clientToken, "dropin", {
container: "payment-form",
onPaymentMethodReceived: function (response) {
var nonce = response.nonce;
Meteor.call('btCreateCustomer', function (error) {
if (error) {
throw new Meteor.Error('customer-creation-failed');
} else {
let e = document.getElementById("invoice");
let label = e.options[e.selectedIndex].text;
let Payment = {
amount: /\$(.*?) /g.exec(label)[1],
period: /(.*? .*?) /g.exec(label)[1]
};
Meteor.call('createTransaction', nonce, Payment, function (error) {
if (!error) {
//do stuff.
}
});
}
});
}
});
}
});
});
//server.main.js
Meteor.methods({
'getClientToken': function (clientId) {
let generateToken = Meteor.wrapAsync(gateway.clientToken.generate, gateway.clientToken);
let options = {};
if (clientId) {
options.clientId = clientId;
}
let response = generateToken(options);
return response.clientToken;
},
'btCreateCustomer': function() {
let user = Meteor.user();
let customerData = {
email: user.emails[0].address
};
gateway.customer.create(customerData, function (error, response) {
if (!error) {
Meteor.users.update(user._id, {
$set: {
customerId: response.customer.id
}
});
}
});
},
'createTransaction': function (nonceFromTheClient, Payment) {
let user = Meteor.user();
gateway.transaction.sale({
amount: Payment.amount,
paymentMethodNonce: nonceFromTheClient, // Generated nonce passed from client
customer: {
id: user.customerId
},
options: {
submitForSettlement: true, // Payment is submitted for settlement immediately
storeInVaultOnSuccess: true // Store customer in Braintree's Vault
}
}, function (err) {
if (!err) {
// ------------- next line fail due to Fiber issue ------------------
console.log('Paid ' + Payment.amount + " for period " + Payment.period);
}
});
}
});
<template name="account">
<div id="account">
<form role="form">
<div class="row">
<div class="col-md-6 col-xs-12">
<div id="payment-form"></div>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</template>
내가 그랬어 그 아무 소용합니다. 여전히 같은 오류. –
당신은 같은 것이 아닌'Meteor.wrapAsync'를 시도했다고하셨습니다. –
해결책을 시도했지만 작동하지 않습니다. 즉 동일한 오류가 발생했습니다. –