Pagseguro Notification API receiving 403 error

Asked

Viewed 773 times

0

Hello, I am doing the integration of the Pagseguro API in a transparent way and in the test environment (Sandbox), when I make a change in the status of the transaction there in the Pagseguro panel, their system send a request, but in the status http received, 403 (prohibited).

My question is, when their system accesses the respective controller of my system notification link, is it to give some kind of feedback? Follow down what I’ve done so far:

    [HttpPost]
    public ActionResult Notifications(string notificationCode, string notificationType)
    {
        HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "https://sandbox.pagseguro.uol.com.br");

        if (notificationCode.IsNullOrWhiteSpace())
            return Content("ERROR - Required code of transaction");

        try
        {
            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

            Transaction transaction = NotificationService.CheckTransaction(credentials, notificationCode);

            var dados = db.PsTransactions.FirstOrDefault(t => t.code.Equals(transaction.Code));
            if (dados != null)
            {
                if (dados.lasteventdate.Equals(transaction.LastEventDate))
                    return Content("Transaction already exists");
                dados.date = transaction.Date;
                dados.lasteventdate = transaction.LastEventDate;
                dados.status = PagSeguro.TransactionStatusToString(transaction.TransactionStatus);

                db.Entry(dados).State = EntityState.Modified;
                db.SaveChanges();
            }
            Infraestrutura.Notifications.Transactions(dados);
            TransactionsHub.NotifyCurrentTransactions();
        }
        catch (PagSeguroServiceException ex)
        {
            return Content("ERROR - " + ex.Message);
        }

        return Content("SUCCESS - Transaction update");    
    }

And follow the Sandbox notification log:

inserir a descrição da imagem aqui

  • You what (semantically) means the 403 code?

  • is an HTTP response, just like 404 (not found), 403 is access denied @jbueno

1 answer

0


I was able to identify the reason for this return. When I am in the development environment (localhost:44333) the automatic sending of when changing the status in the sandbox somehow does not work.

To work, just click on the button "Resend Local Notification" and regardless of appearing that gave error, triggered the action in Controller.

Browser other questions tagged

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