Jump to content

addInvoicePayment() create the transation, but invoice still marked as unpaid


linkhost

Recommended Posts

Hi!

 

I've developed my own callback module. Everything is working fine: it receives the informations from my payment gateway and create the transation. How ever, the invoice still marked as unpaid. Any ideia about this bug?

I've double checked the invoices values and they are allright. Here is my code:

 

<?php

# Required File Includes
include("../../../dbconnect.php");
include("../../../includes/functions.php");
include("../../../includes/gatewayfunctions.php");
include("../../../includes/invoicefunctions.php");

$gatewaymodule = "pagseguro"; # Enter your gateway module name here replacing template

$GATEWAY = getGatewayVariables($gatewaymodule);
if (!$GATEWAY["type"]) die("Module Not Activated"); # Checks gateway module is active before accepting callback

# Get Returned Variables - Adjust for Post Variable Names from your Gateway's Documentation
$notificationCode = $_POST["notificationCode"];
$notificationType = $_POST["notificationType"];
$emailPagseguro = $GATEWAY["email"];
$apiKey = $GATEWAY["callbacktoken"];


$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL,"https://ws.pagseguro.uol.com.br/v3/transactions/notifications/$notificationCode?email=$emailPagseguro&token=$apiKey"); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 


curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
$ret = curl_exec($curl);
$retorno = new SimpleXMLElement($ret);
$err = curl_error($curl); 
curl_close($curl);

$idTransacao = $retorno->code; 
$idFatura = $retorno->reference; 
$statusPagamento = $retorno->status; 
$valorBruto = $retorno->grossAmount; 
$valorTaxas1 = $retorno->creditorFees->intermediationRateAmount; 
$valorTaxas2 = $retorno->creditorFees->intermediationFeeAmount;
$valorLiquido = $retorno->netAmount; 
$totalTaxa=(float)$valorTaxas1+(float)$valorTaxas2;

$invoiceid = checkCbInvoiceID($idFatura,$GATEWAY["name"]); # Checks invoice ID is a valid invoice number or ends processing

checkCbTransID($idTransacao); # Checks transaction number isn't already in the database and ends processing if it does

if ($statusPagamento=="3") {
   # Successful
   addInvoicePayment($idFatura,$idTransacao,$valorBruto,$totalTaxa,$gatewaymodule); # Apply Payment to Invoice: invoiceid, transactionid, amount paid, fees, modulename
logTransaction($GATEWAY["name"],$_POST,"Successful"); # Save to Gateway Log: name, data array, status
} else {
# Unsuccessful
   logTransaction($GATEWAY["name"],$_POST,"Unsuccessful"); # Save to Gateway Log: name, data array, status
}

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated