Exemplo n.º 1
0
        /// <summary>
        /// Cancel a transaction that has not yet been approved by client transaction id
        /// </summary>
        public static void CancelByClientId(string clientId)
        {
            try
            {
                //Prepare the objet to send for the annulment
                var cancellation = new CancellationByClientRequestModel
                {
                    ClientId = clientId
                };
                //Send request for cancel transaction using transaction id
                var response = connection.PostCall <bool>("/api/Cancel/client", cancellation, Configurations.Lang);
                Console.WriteLine(response ? "Transaccion cancelada" : "La transaccion no pudo ser cancelada");
            }
            catch (PayPhoneWebException e)
            {
                //All call make to PayPhone need to be inside a try catch
                //Verify if error returned was Unhautorized and get new token
                if (RefreshToken(e))
                {
                    //Make the same call again after restore the invalid token for new one
                    CancelByClientId(clientId);
                }

                PrintErrors(e);
            }
            catch (Exception e)
            {
                //Always is recomended have generic exception for possibles errors generate from your code
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Exception " + e.Message);
                Console.ResetColor();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send request for reimbursement by client transaction id
        /// </summary>
        public static void ReimbursemetByClientTransactionId(string clientId)
        {
            try
            {
                var cancellation = new CancellationByClientRequestModel
                {
                    ClientId = clientId
                };
                //Send reimbursement by client transaction id request
                var response = connection.PostCall <bool>("/api/Reverse/Client", cancellation, Configurations.Lang);
                //save the reimbursement id returned
                if (response)
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine($"El reverso ha sido realizado satisfactoriamente");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"La transaccion no pudo ser reversada");
                }
                Console.ResetColor();
            }
            catch (PayPhoneWebException e)
            {
                //All call make to PayPhone need to be inside a try catch
                //Verify if error returned was Unhautorized and get new token
                if (RefreshToken(e))
                {
                    //Make the same call again after restore the invalid token for new one
                    ReimbursemetByClientTransactionId(clientId);
                }

                PrintErrors(e);
            }
            catch (Exception e)
            {
                //Always is recomended have generic exception for possibles errors generate from your code
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Exception " + e.Message);
                Console.ResetColor();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Annull transaction by client transction id
        /// </summary>
        /// <param name="txId">Transction id get from PayPHone</param>
        public static void AnnulmentByClientId(string clientId)
        {
            //Prepare the objet to send for the annulment
            var cancellation = new CancellationByClientRequestModel
            {
                ClientId = clientId
            };

            try
            {
                //Send annulment request with object created above
                var response = connection.PostCall <AnnulResponseModel>("/api/Annul/client", cancellation, Configurations.Lang);
                //Save the annulment id for get status later
                AnnulmentId = response.Id;
                Console.WriteLine($"Identificador de la anulación: {AnnulmentId}");
            }
            catch (PayPhoneWebException e)
            {
                //All call make to PayPhone need to be inside a try catch
                //Verify if error returned was Unhautorized and get new token
                if (RefreshToken(e))
                {
                    //Make the same call again after restore the invalid token for new one
                    AnnulmentByClientId(clientId);
                }

                PrintErrors(e);
            }
            catch (Exception e)
            {
                //Always is recomended have generic exception for possibles errors generate from your code
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Exception " + e.Message);
                Console.ResetColor();
            }
        }