Pass discount value to PagSeguro

0

I'm developing a shopping cart that at a certain price reaches a range, it calculates a discount for the customer, I calculate the freight and the freight value is correctly added to the discount value, but I realized that when I finished the order and passed the values for the PagSeguro the value goes without the discounts, step for them what I am asked, this way:

if ($TPFrete == 3){
    $peso = 0;
    $paymentRequest->addItem($cod_prod, $nome_prod, $quantidade_prod, $vlr, $peso);
} else {
    $paymentRequest->addItem($cod_prod, $nome_prod, $quantidade_prod, $vlr, $peso, $VLRFrete);
}

I believe that on the page of PagSeguro it calculates the quantity x value and there the discount does not appear, is there any way to pass the value of this discount to PagSeguro? I saw that there is an option in the documentation that makes it possible to calculate discount, here:

$paymentRequest->setExtraAmount

But I already have the calculated value before moving on to them, is there any tip? The service of PagSeguro did not return my questions, so this post here, I believe to be even faster.

    
asked by anonymous 11.10.2018 / 14:11

2 answers

1

Use the method:

setExtraAmount()

by passing a negative value on the parameter. Example:

$boleto->setExtraAmount(-10.00);

In this way he will automatically add the discount to the cart total of the amount he sends for the payout. If you already have the calculated value, just multiply by (-1) before passing it in the parameter.

$desconto = 10.00;
$desconto_n = $desconto*(-1);
$boleto->setExtraAmount($desconto_n);
    
26.10.2018 / 21:39
1

See the documentation for the PAGSEGURO , You can set discount percentages to be offered based on the payment method chosen by your customer during the checkout in the PagSeguro environment.

$paymentRequest->addPaymentMethodConfig('CREDIT_CARD', 1.00, 'DISCOUNT_PERCENT');  
$paymentRequest->addPaymentMethodConfig('EFT', 2.90, 'DISCOUNT_PERCENT');  
$paymentRequest->addPaymentMethodConfig('BOLETO', 10.00, 'DISCOUNT_PERCENT');  
$paymentRequest->addPaymentMethodConfig('DEPOSIT', 3.45, 'DISCOUNT_PERCENT');  
$paymentRequest->addPaymentMethodConfig('BALANCE', 0.01, 'DISCOUNT_PERCENT'); 
    
11.10.2018 / 15:46