Exemplo n.º 1
0
        private bool AddPaymentAuthority(PaymentResponseVm response, long paymentID)
        {
            try
            {
                var payment = _context.Payments.Find(paymentID);
                payment.StatusID          = (int)RequestStatus.UnVerified;
                payment.TerminalReference = response.data.authority;

                _context.Payments.Update(payment);
                _context.SaveChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public TerminalResponseDTO Pay(BankRequestDTO model)
        {
            TerminalResponseDTO terminalResponse = new TerminalResponseDTO()
            {
                Success = false,
                Message = "unhandled exception occurred"
            };

            try
            {
                long?id = CreateRequest(model);
                if (id.HasValue)
                {
                    PaymentRequestVm request = new PaymentRequestVm()
                    {
                        amount       = model.amount,
                        callback_url = model.callBackUrl,
                        description  = model.additionalData,
                        email        = "",
                        mobile       = "",
                        merchant_id  = model.TerminalID
                    };

                    var jsonBody        = JsonConvert.SerializeObject(request);
                    var content         = new StringContent(jsonBody, Encoding.UTF8, "application/json");
                    var response        = _client.PostAsync(Configuration.GetGatewayInfo("Request_Url"), content).Result;
                    var responseContent = response.Content.ReadAsStringAsync().Result;


                    try
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            PaymentResponseVm res = JsonConvert.DeserializeObject <PaymentResponseVm>
                                                        (responseContent);
                            if (res.data.code == 100)
                            {
                                if (AddPaymentAuthority(res, id.Value))
                                {
                                    terminalResponse.Message   = res.data.message;
                                    terminalResponse.Url       = Configuration.GetGatewayInfo("StartPayment_Url") + res.data.authority;
                                    terminalResponse.Reference = res.data.authority;
                                    terminalResponse.StatusID  = res.data.code;
                                    terminalResponse.Success   = true;
                                }
                            }
                        }
                    }
                    catch
                    {
                        PaymentErrorResponse err = JsonConvert.DeserializeObject <PaymentErrorResponse>
                                                       (responseContent);

                        terminalResponse.Success  = false;
                        terminalResponse.Message  = err.errors.message;
                        terminalResponse.Url      = response.RequestMessage.RequestUri.AbsoluteUri;
                        terminalResponse.StatusID = err.errors.code;
                    }

                    return(terminalResponse);
                }
                return(terminalResponse);
            }
            catch
            {
                return(terminalResponse);
            }
        }