Esempio n. 1
0
        static readonly string _baseUrl = "http://localhost:7000/";// ConfigurationManager.AppSettings["baseUrl"];

        /// <summary>
        /// This service charges a specific amount from a subscriber’s account.
        /// </summary>
        /// <param name="applicationId">Used to identify the application. </param>
        /// <param name="password">Used to authenticate the application originated message against the service providers credentials.Encoded, single value</param>
        /// <param name="subscriberId">This can be the MSISDN the subscriber to be charged. This is a unique identifier.</param>
        /// <returns></returns>
        public async Task <DirectDebitResponseDto> Charge(string applicationId, string password, string subscriberId)
        {
            Log.TraceStart();
            DirectDebitResponseDto response = null;

            try
            {
                DirectDebitRequestDto ddRequestDto = new DirectDebitRequestDto();
                ddRequestDto.applicationId = applicationId;
                ddRequestDto.password      = password;
                ddRequestDto.subscriberId  = subscriberId;
                ddRequestDto.externalTrxId = Guid.NewGuid().ToString();
                //ddRequestDto.paymentInstrumentName = "MobileAccount";
                ddRequestDto.amount = "2";

                var ddResponse = await DirectDebit(ddRequestDto);

                if (ddResponse.IsSuccessStatusCode)
                {
                    var result = ddResponse.Content.ReadAsAsync <dynamic>().Result;

                    //response = new IdeaMartStatusResponse();
                    //response.requestId = result.requestId;
                    //response.statusCode = result.statusCode;
                    //response.statusDetail = result.statusDetail;
                    //response.timeStamp = DateTime.UtcNow.ToString();
                    //response.version = result.version;

                    // response = new DirectDebitResponseDto();
                    response = MapToDirectDebitResponseDto(result);

                    if (ddRequestDto.externalTrxId != response.externalTrxId)
                    {
                        Log.Error("External Transaction Id mimatch");
                    }
                    //    return WebApiHelper.GetErrorResponce<DirectDebitResponseDto>(StatusCode.CaasServiceFailed, Resources.Caas_ExternalTransactionIdMismatch);

                    //response = new Response<DirectDebitResponseDto>(StatusCode.Success, Resources.Success, ddResponseDto);
                }
                else
                {
                    Log.Error(Resources.Caas_CassServiceFailed);
                }
                Log.TraceEnd();
                return(response);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                throw;
                //return WebApiHelper.GetErrorResponce<DirectDebitResponseDto>(StatusCode.Error, Resources.Error_ServiceAccessFailed);
            }
        }
Esempio n. 2
0
        private DirectDebitResponseDto MapToDirectDebitResponseDto(dynamic response)
        {
            Log.TraceStart();

            DirectDebitResponseDto ddResponseDto = new DirectDebitResponseDto();

            ddResponseDto.statusCode       = response.statusCode;
            ddResponseDto.timeStamp        = response.timeStamp;
            ddResponseDto.shortDescription = response.shortDescription;
            ddResponseDto.statusDetail     = response.statusDetail;
            ddResponseDto.externalTrxId    = response.externalTrxId;
            ddResponseDto.longDescription  = response.longDescription;
            ddResponseDto.internalTrxId    = response.internalTrxId;

            Log.TraceEnd();
            return(ddResponseDto);
        }
Esempio n. 3
0
        /// <summary>
        /// This service charges a specific amount from a subscriber’s account.
        /// </summary>
        /// <param name="applicationId">Used to identify the application. </param>
        /// <param name="password">Used to authenticate the application originated message against the service providers credentials.Encoded, single value</param>
        /// <param name="subscriberId">This can be the MSISDN the subscriber to be charged. This is a unique identifier.</param>
        /// <returns></returns>
        public async Task <DirectDebitResponseDto> Charge(string applicationId, string password, string subscriberId)
        {
            //Log.TraceStart();
            DirectDebitResponseDto response = null;

            try
            {
                DirectDebitRequestDto ddRequestDto = new DirectDebitRequestDto();
                ddRequestDto.applicationId         = applicationId;
                ddRequestDto.password              = password;
                ddRequestDto.subscriberId          = subscriberId;
                ddRequestDto.externalTrxId         = Guid.NewGuid().ToString();
                ddRequestDto.paymentInstrumentName = "MobileAccount";
                ddRequestDto.amount   = _amount;
                ddRequestDto.currency = "LKR";

                var ddResponse = await DirectDebit(ddRequestDto);

                if (ddResponse.IsSuccessStatusCode)
                {
                    var result = ddResponse.Content.ReadAsAsync <dynamic>().Result;

                    response = MapToDirectDebitResponseDto(result);

                    if (ddRequestDto.externalTrxId != response.externalTrxId)
                    {
                        Log.Error("External Transaction Id mimatch");
                    }
                }
                else
                {
                    Log.Error(Resources.Caas_CassServiceFailed);
                }
                //Log.TraceEnd();
                return(response);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                throw;
            }
        }