Pass value with discount to Pagseguro

Asked

Viewed 161 times

1

I am developing a shopping cart that to the amount to reach a certain range it calculates a discount for the customer, I calculate the freight and the value of the freight is correctly added to the value with discount, but I realized that when finalizing the order and pass the values to the PagSeguro the value goes without the discounts, I pass to them what is requested to me, in 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 on the page of PagSeguro He calculates the quantity x value and then the discount does not appear, is there any way to pass the value of this discount to Pagseguro? I saw that you have an option in the documentation that makes it possible to calculate discount, this here:

$paymentRequest->setExtraAmount

But I already have the calculated amount before I pass to them, is there any hint? The service of Pagseguro did not return my questions, so this post here, I believe to be even faster.

2 answers

2


Use the method:

setExtraAmount()

passing a negative value in the parameter. Example:

$boleto->setExtraAmount(-10.00);

This way it will automatically add the discount to the total cart of the amount it sends to the pagseguro. 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);

1

See in the documentation of PAID, You can set percentages of discounts to be offered based on the payment method chosen by your customer, during checkout, in the Paypal 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'); 
  • Hello @Eduardo, thanks for the tip, I had already read the documentation, but as I said in the post, I already have the amount calculated, I would like to send it and not calculate

Browser other questions tagged

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