Example #1
0
        //Processing ABSA transactions in accordance with the API specifications
        private async Task <TransactionProcessResult> ProcessAbsa(Transaction t)
        {
            string      paymentURL = _apiUrl + "/api/ABSA/ProccessPayment";
            ABSARequest req;

            try
            {
                req = new ABSARequest()
                {
                    AmountToPay         = t.Amount.ToString(),
                    ClientID            = t.Company.CompanyId.ToString(),
                    DestinationAccount  = t.Employee.AccountNumber,
                    OriginationAccount  = t.Company.AccountNumber,
                    DestinationBankCode = t.Employee.Bank.BankId
                };
            }
            catch (Exception e)
            {
                return(new TransactionProcessResult()
                {
                    TransactionId = t.Id, FailReason = e.Message, Code = StatusCode.Other
                });
            }

            using (var client = new HttpClient())
            {
                var request     = JsonConvert.SerializeObject(req);
                var buffer      = Encoding.UTF8.GetBytes(request);
                var bytecontent = new ByteArrayContent(buffer);
                bytecontent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage res = await client.PostAsync(paymentURL, bytecontent);

                PaymentResponse result;
                if (res.IsSuccessStatusCode)
                {
                    result = JsonConvert.DeserializeObject <PaymentResponse>(await res.Content.ReadAsStringAsync());
                }
                else
                {
                    return(new TransactionProcessResult()
                    {
                        TransactionId = t.Id, FailReason = "Post request failed", Code = StatusCode.Network
                    });
                }

                if (result.SuccessCode != 1)
                {
                    return(new TransactionProcessResult()
                    {
                        TransactionId = t.Id, FailReason = result.Message, Code = StatusCode.Other
                    });
                }
            }

            return(new TransactionProcessResult()
            {
                TransactionId = t.Id, Code = StatusCode.Success
            });
        }
Example #2
0
        private static async Task <ProcessResults> ProcessAbsa(Transaction t)
        {
            string paymentURL = _apiUrl + "/api/ABSA/ProccessPayment";
            //create an object matching how the ABSA Api accepts requests
            ABSARequest req;

            try
            {
                req = new ABSARequest()
                {
                    AmountToPay         = t.Amount.ToString(),
                    ClientID            = t.Company.CompanyId.ToString(),
                    DestinationAccount  = t.Employee.AccountNumber,
                    OriginationAccount  = t.Company.AccountNumber,
                    DestinationBankCode = t.Employee.Bank.BankId
                };
            }
            catch (Exception e)
            {
                return(new ProcessResults()
                {
                    TransactionId = t.Id, FailReason = e.Message, Code = StatusCode.Other
                });
            }

            using (var client = new HttpClient())
            {
                //convert the transaction request to an applicable type
                var request     = JsonConvert.SerializeObject(req);
                var buffer      = Encoding.UTF8.GetBytes(request);
                var bytecontent = new ByteArrayContent(buffer);
                bytecontent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                //sends the transaction to the API via POSt
                HttpResponseMessage res = await client.PostAsync(paymentURL, bytecontent);

                PaymentResponse result;
                if (res.IsSuccessStatusCode)
                {
                    //converts the API response into the expected response object
                    result = JsonConvert.DeserializeObject <PaymentResponse>(await res.Content.ReadAsStringAsync());
                }
                else
                {
                    //returns that the connection to the API failed.
                    return(new ProcessResults()
                    {
                        TransactionId = t.Id, FailReason = "Post request failed", Code = StatusCode.Network
                    });
                }

                //if the result of the transaction wasn't succesfull, returns the results along with the fialure reason
                if (result.SuccessCode != 1)
                {
                    return(new ProcessResults()
                    {
                        TransactionId = t.Id, FailReason = result.Message, Code = StatusCode.Other
                    });
                }
            }

            return(new ProcessResults()
            {
                TransactionId = t.Id, Code = StatusCode.Success
            });
        }