public async Task <CheckIntegrationErrorCode> CheckPaymentIntegrationAsync([FromBody] CheckPaymentIntegrationRequest request) { var integrationProperties = await _partnerIntegrationPropertiesFetcherService.FetchPropertiesAsync(request.PartnerId); if (integrationProperties.ErrorCode != IntegrationPropertiesErrorCode.None) { return(_mapper.Map <CheckIntegrationErrorCode>(integrationProperties.ErrorCode)); } var client = new PayrexxIntegrationClient( integrationProperties.ApiBaseUrl, integrationProperties.InstanceName, integrationProperties.ApiKey); try { var res = await client.Api.CheckSignatureAsync(); return(res.Status == "success" ? CheckIntegrationErrorCode.None : CheckIntegrationErrorCode.Fail); } catch (Exception e) { _log.Warning(null, exception: e); return(CheckIntegrationErrorCode.Fail); } }
public async Task <PaymentResponse> GeneratePaymentAsync([FromBody] GeneratePaymentRequest request) { var integrationProperties = await _partnerIntegrationPropertiesFetcherService.FetchPropertiesAsync(request.PartnerId); if (integrationProperties.ErrorCode != IntegrationPropertiesErrorCode.None) { return new PaymentResponse { ErrorCode = _mapper.Map <CheckIntegrationErrorCode>(integrationProperties.ErrorCode), } } ; var client = new PayrexxIntegrationClient( integrationProperties.ApiBaseUrl, integrationProperties.InstanceName, integrationProperties.ApiKey); try { var paymentGatewayRequest = new PaymentGatewayRequest { Amount = request.Amount, Currency = request.Currency, SuccessRedirectUrl = request.SuccessRedirectUrl, FailedRedirectUrl = request.FailRedirectUrl, ReferenceId = request.PaymentRequestId, SkipResultPage = 0 }; _log.Info("Call CreatePaymentGatewayAsync with data: " + paymentGatewayRequest.ToJson()); var res = await client.Api.CreatePaymentGatewayAsync(paymentGatewayRequest); var payment = res.Data[0]; return(new PaymentResponse { PaymentId = payment.Id.ToString(), PaymentPageUrl = payment.Link, }); } catch (ClientApiException e) { _log.Warning("ClientApiException with data: " + new { HttpStatusCode = $"{(int)e.HttpStatusCode}: {e.HttpStatusCode}", e }.ToJson(), exception: e); return(new PaymentResponse { ErrorCode = CheckIntegrationErrorCode.Fail, }); } catch (Exception e) { _log.Warning(null, exception: e); return(new PaymentResponse { ErrorCode = CheckIntegrationErrorCode.Fail, }); } }
public async Task <PaymentStatusResponse> CheckPaymentAsync(CheckPaymentRequest request) { var integrationProperties = await _partnerIntegrationPropertiesFetcherService.FetchPropertiesAsync(request.PartnerId); if (integrationProperties.ErrorCode != IntegrationPropertiesErrorCode.None) { return new PaymentStatusResponse { ErrorCode = _mapper.Map <CheckIntegrationErrorCode>(integrationProperties.ErrorCode), } } ; var client = new PayrexxIntegrationClient( integrationProperties.ApiBaseUrl, integrationProperties.InstanceName, integrationProperties.ApiKey); try { var paymentStatus = await client.Api.GetPaymentGatewayAsync(int.Parse(request.PaymentId)); var result = new PaymentStatusResponse { ErrorCode = CheckIntegrationErrorCode.None }; if (paymentStatus.Status != "success") { result.PaymentStatus = PaymentStatus.NotFound; return(result); } switch (paymentStatus.Data[0].Status) { case "waiting": result.PaymentStatus = PaymentStatus.Pending; break; case "confirmed": result.PaymentStatus = PaymentStatus.Success; break; case "authorized": case "reserved": result.PaymentStatus = PaymentStatus.Processing; break; default: throw new NotSupportedException($"Payment status {paymentStatus.Data[0].Status} is not supported"); } return(result); } catch (Exception e) { _log.Warning(null, exception: e); return(new PaymentStatusResponse { ErrorCode = CheckIntegrationErrorCode.Fail, }); } } }