简体   繁体   中英

Braintree Node.js cannot get transaction.sale to work

I am building a reactjs app that among others will include Braintree Dropin UI integration. So far, I have managed to make the UI show up and send a payload to the back end. However, I cannot get the gateway.transaction.sale() part to work. Here is my code's relevant parts:

When the user clicks the pay button, this is fired:

instance.requestPaymentMethod().then(function (payload) {
    console.log(payload);
    completePayment(amount, payload.nonce, userId, sessionId).then((result) => {
        console.log( result );
    });
}).catch(function (err) {
    alert(err.message);
});

And this is the code that should handle the transaction:

return gateway.transaction.sale({
    amount: amount,
    paymentMethodNonce: nonce,
    customFields: {
        session_id: sessionId,
        user_id: userId
    },
    options: {
        submitForSettlement: true
    }
}).then(function (result) {
    if (result.success) {
        console.log('Transaction ID: ' + result.transaction.id);
    } else {
        console.error(result.message);
    }
}).catch(( error ) => {
    alert(error);
});

Every time this function is fired, I get this error from catch:

TypeError: can't assign to property "success" on :not an object

Can anyone point me in the right direction?

Please note that I am not very familiar with react, node etc so my code may not be the best thing around...

1- 确保您将环境分配给沙箱(braintree.Environment.Sandbox) 2- 仔细检查(merchantId、publicKey 和 privateKey)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM