swiss_blade
swiss_blade

Reputation: 541

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...

Upvotes: 0

Views: 184

Answers (1)

Dr. Mosaab Seta
Dr. Mosaab Seta

Reputation: 11

Check these points:

  1. make sure you assigned your environment to the sandbox (braintree.Environment.Sandbox);
  2. double check (merchantId, publicKey, and privateKey).

Upvotes: 0

Related Questions