1

Hola muy buenas tardes usuarios, el día de hoy estaba programando una aplicación con algo de braintree, pero me percate que al intentar realizar una compra me sale un error en el paso final, me encantaría que alguno de ustedes me pudiera ayudar en esta situación.

He intentando solucionarlo por más de 10 días, pero no conseguí solucionarlo si me ayudarme o como se podría solucionarlo me ayudaría mucho, En android studio no me sale ningún error, solo me sale en un cmd que estoy iniciando el "servidor", y les dejo mi código para que lo puedan observar gracias. Js:

const {Router } = require('express');
const { Transaction } = require('braintree');
const logger = require('debug');
const gateway = require('../lib/gateway');

const router = Router(); // eslint-disable-line new-cap
const debug = logger('braintree_example:router');
const TRANSACTION_SUCCESS_STATUSES = [
  Transaction.Status.Authorizing,
  Transaction.Status.Authorized,
  Transaction.Status.Settled,
  Transaction.Status.Settling,
  Transaction.Status.SettlementConfirmed,
  Transaction.Status.SettlementPending,
  Transaction.Status.SubmittedForSettlement,
];

function formatErrors(errors) {
  let formattedErrors = '';

  for (let [, { code, message }] of Object.entries(errors)) {
    formattedErrors += `Error: ${code}: ${message}
`;
  }

  return formattedErrors;
}

function createResultObject({ status }) {
  let result;

  if (TRANSACTION_SUCCESS_STATUSES.indexOf(status) !== -1) {
    result = {
      header: 'Sweet Success!',
      icon: 'success',
      message:
        'Your test transaction has been successfully processed. See the Braintree API response and try again.',
    };
  } else {
    result = {
      header: 'Transaction Failed',
      icon: 'fail',
      message: `Your test transaction has a status of ${status}. See the Braintree API response and try again.`,
    };
  }

  return result;
}

router.get('/', (req, res) => {
  res.redirect('/checkouts/new');
});

router.get('/checkouts/new',function (req, res) {
    gateway.clientToken.generate({}, function (err,response){
        res.send(JSON.stringify(response));
    });

});

router.get('/checkouts/:id', (req, res) => {
  var result;
  var transactionId = req.params.id;

  gateway.transaction.find(transactionId).then((transaction) => {
    result = createResultObject(transaction);
    res.render('checkouts/show', { transaction, result });
  });
});

router.post('/checkouts',function (req, res) {
  // In production you should not take amounts directly from clients
  var amount=req.body.amount;
  var nonce=req.body.payment_method_nonce;
  var transactionErrors; 

  gateway.transaction
    .sale({
      amount: amount,
      paymentMethodNonce: nonce,
      options:{ SubmittedForSettlement: true

  }
},function (err,result){
    if (result.transaction != result) {
        res.send(result);

    }else{
        transactionErrors = result.errors.deepErrors();
        res.send(formatErrors(transactionErrors));
    }

});

});
module.exports = router; 

Error:

Error in callback function
TypeError: Cannot read property 'transaction' of undefined
    at C:\xampp\htdocs\braintree\routes\index.js:85:13
    at Timeout._onTimeout (C:\xampp\htdocs\braintree\node_modules\@braintree\wrap-promise\dist\lib\deferred.js:11:20)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
 

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.