Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] PaymentRequestVm paymentRequest)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogDebug($"Bad Request: {JsonConvert.SerializeObject(ModelState)}");
                return(BadRequest(ModelState));
            }
            var payment = _mapper.Map <Payment>(paymentRequest);

            _logger.LogDebug($"Submitting Payment request for : {payment.MaskedCardNumber}");
            var paymentDto = await _paymentService.ProcessPayment(payment);

            var paymentSummaryVm = _mapper.Map <PaymentSummaryVm>(paymentDto);

            _logger.LogDebug($"Processed Payment for : {paymentSummaryVm.MaskedCardNumber}");
            return(base.Ok(paymentSummaryVm));
        }
Beispiel #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);
            }
        }