Problems sending requisition to Cielo

Asked

Viewed 137 times

0

I am setting up a transparent payment method for Cielo and I use Ode on my server I have already set up my Json. But I can not send the data correctly to Cielo, someone knows some way to send the request and receive the return by Node

exports.transacaoTransparenteCielo = function(params, order, cb){ 
    //função que configura o Json e manda para a Cielo

    var valorTotal = formatNum(params.items[0].price, { minFraction: 2, maxFraction: 2 }).replace('.',''); // forma o valor total convertido para centavos
    var tipoPagamento, codigoProduto, numeroParcelas;

    switch (params.form.paymentMethodCielo) { // Verifica qual o cartão utilizado
      case 'visa_credito':
        tipoPagamento = 'Visa';
        codigoProduto = 1;
        numeroParcelas = 1;
        break;
      case 'master_credito':
        tipoPagamento = 'Master Card';
        codigoProduto = 1;
        numeroParcelas = 1;
        break;
      case 'elo_credito':
        tipoPagamento = 'Elo';
        codigoProduto = 1;
        numeroParcelas = 1;
        break;
      case 'diners_credito':
        tipoPagamento = 'Diners Club';
        codigoProduto = 1;
        numeroParcelas = 1;
        break;
      case 'jcb_credito':
        tipoPagamento = 'JCB';
        codigoProduto = 1;
        numeroParcelas = 1;
        break;
      case 'visa_debito':
        tipoPagamento = 'Visa';
        codigoProduto = 'A';
        numeroParcelas = 1;
        break;
      case 'paypal':
        return cb(true);
        break;
    }
    params.form.redecartao = (params.form.paymentMethod == 'paypal') ? 'PayPal' : 'Cielo';
    params.form.cartaotipo = (codigoProduto == 'A') ? 'D' : 'C';
    params.form.bandeira   = tipoPagamento;

    var requestJson = {  // Json que vai ser enviado para a cielo com todos os dados da compra

      "MerchantId": "bde9b106-bdea-4b81-b735-6881173ae777",
      "MerchantKey": "LBXVRFGFEVYJMEPYLTDPQESWYUIFNTSSBUXDKWTL", 
      "MerchantOrderId": params.orderNo,
      "Customer":{  
        "Name":params.form.name,
        "Email":params.form.email,
        "Address":{  
            "Street": params.form.address,
            "ZipCode": params.form.cep,
            "City": params.form.city,
            "State": params.form.uf,
            "Country": params.form.pais.name
        },
          "DeliveryAddress": {
              "Street": params.form.address,
              "ZipCode": params.form.cep,
              "City": params.form.city,
              "State": params.form.uf,
              "Country": params.form.pais.name
          }
      },
      "Payment":{  
        "Type":"CreditCard",
        "Amount": valorTotal,
        "Currency":"BRL",
        "Country":"BRA",
        "Capture":true,
        "Authenticate":false,
        "CreditCard":{  
            "CardNumber": params.form.numberCard,
            "Holder": params.form.nameCard,
            "ExpirationDate": params.form.dateMaturity,
            "SecurityCode": params.form.securityCode,
            "SaveCard":"false",
            "Brand": tipoPagamento
        }
      }
    }
    console.log(requestJson)
    cb(true) 
}
  • Post also the code you made on the Node?

  • That credit card number is a fake number, right?

  • 1

    Yes it is a fake number that Cielo itself offers to do the tests

  • 1

    Erick, take a look here https://github.com/banzeh/cielo, a colleague who has already done this and can save you some time. That’s what you’re looking for?

  • Yes this is exactly what I wanted, I had not found anything like, will help me very, thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.