Return getInstallments Pagseguro

1

The% of PagSeguro is used to return the number of parcels and the value of each parcel, when informing a card and the value of the sale.

The feedback I get is this:

Inthisreturneachitemrepresentsanumberofparcelsanditsvalue,whatIamnotgettingistousegetInstallmentsinsomewayinthisreturnandfillaforeach.

IwouldliketofilltheSelectoptionswiththeamountofparcelandthevalue.

ToreturnthevaluesI'musing:

PagSeguroDirectPayment.getInstallments({amount:<?phpecho$total_compra?>,brand:$("#bandeira").val(),
    maxInstallmentNoInterest: 2,
    success: function(response) {
        //console.log(response);

        bandeira = $("#bandeira").val();
        $("#parcelas_div").show(200);


        var options = "";
        var retorno_bandeira = response.installments.visa;

        for (var i = 0; i < retorno_bandeira.length; i++) {
            var quantidade = retorno_bandeira[i].quantity;
            var parcela = retorno_bandeira[i].installmentAmount;
            var valorTotal = retorno_bandeira[i].totalAmount;

            options += '<option value="' + quantidade + '" data-valor="' + parcela + '">' + quantidade + 'x de ' + parcela + ' = R$ ' + valorTotal + '</option>';
        }

        $("#parcelas").html(options);


    },
    error: function(response) {
        console.log(response);
    },
    complete: function(response) {
        console.log(response);
    }
});

The problem that is occurring is as follows:

If I put in the line select return of all data comes var retorno_bandeira = response.installments+"."+bandeira; , but if I add the name of the flag directly on the line so Undefined comes everything normal, I believe the problem is in the form of concatenating the name from the flag to the return.

    
asked by anonymous 29.10.2016 / 05:49

2 answers

1
  

If I put it in the line var retorno_bandeira = response.installments + "." + bandeira , return of all data comes Undefined , but if I add the name of the flag   directly on the line so response.installments.visa comes everything   normal, I believe the problem is in the form of concatenating the name   from the flag to the return.

Another way to access object property is with bracket notation :

bandeira = $("#bandeira").val();
var retorno_bandeira = response.installments[bandeira];
// ...
    
30.10.2016 / 16:34
1

You only need to iterate over the array inside the visa:

var parcelas = getInstallments(),
    visa     = parcelas.installments.visa;

for( var i = 0; i < visa.length; i++ ) {
  var quantidade = visa[i].quantity,
      parcela    = visa[i].installmentAmount,
      valorTotal = visa[i].totalAmount;
  
      // aqui você usa os valores definidos pra montar o select
}
    
29.10.2016 / 15:53