Exemplo n.º 1
0
      public async Task<PaymentNotificationResponse> GetNotification(PaymentInfo paymentInfo)
        {
            var pnr = new PaymentNotificationRequest()
            {
                Id = Guid.NewGuid(),
                DistributorCostCenterId =_configService.Load().CostCentreId,
                ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification,
                DateCreated = DateTime.Now,
                TransactionRefId = paymentInfo.Id.ToString(),
            };

          var data = await _paymentGatewayProxy.GetPaymentNotificationAsync(pnr);
          PaymentNotificationResponse response = null; 
          if (data != null && data.StatusCode == "S1000")
          {
             _paymentNotification.Save(data);
             response = _paymentNotification.GetById(data.Id);
          }
          return response;
        }
        public Guid Save(PaymentNotificationRequest entity)
        {
             PaymentNotificationRequest existingEntity = _ctx.AsynchronousPaymentNotificationRequest.FirstOrDefault
                                                                (n => n.Id == entity.Id);

            if(existingEntity ==null)
            {
                existingEntity = new PaymentNotificationRequest();
                existingEntity.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification;
                existingEntity.DateCreated = DateTime.Now;
                existingEntity.Id = entity.Id;
               _ctx.AsynchronousPaymentNotificationRequest.Add(existingEntity);
            }

            existingEntity.DateCreated = DateTime.Now;
            existingEntity.DistributorCostCenterId = entity.DistributorCostCenterId;
            existingEntity.TransactionRefId = entity.TransactionRefId;
    
            _ctx.AsynchronousPaymentNotificationRequest.Add(existingEntity);
            _ctx.SaveChanges();
            return entity.Id;

        }
Exemplo n.º 3
0
       private async void ApiGetPaybillPaymentNotification()
       {
           using (StructureMap.IContainer c = NestedContainer)
           {
               _paymentNotificationCompleted = false;
               var pnr = new PaymentNotificationRequest()
                             {
                                 Id = Guid.NewGuid(),
                                 DistributorCostCenterId = Using<IConfigService>(c).Load().CostCentreId,
                                 ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification,
                                 DateCreated = DateTime.Now,
                                 TransactionRefId = PaymentTransactionRefId.ToString(),
                             };

               _clientRequestResponses.Add(pnr);

               var pgresponse = await Using<IPaymentGatewayProxy>(c).GetPaymentNotificationAsync(pnr);
               ProcessPaymentNotification(pgresponse);
               MMoneyIsApproved = false;
           }
       }
Exemplo n.º 4
0
        public async Task<PaymentNotificationResponse> GetPaymentNotificationAsync(PaymentNotificationRequest request)
        {
            PaymentNotificationResponse _response = new PaymentNotificationResponse();
            HttpClient httpClient = setupHttpClient();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            string url = "api/bridge/payment/getpaymentnotification";
            try
            {
                var response = await httpClient.PostAsJsonAsync(url, request);
                string data = await response.Content.ReadAsStringAsync();
                
                JObject jo =JsonConvert.DeserializeObject<JObject>(data);
                var respodata = jo["Response"];
                _response = respodata.ToObject<PaymentNotificationResponse>();
                var datelastsyncInfo = jo["Response"]["PaymentNotificationDetails"];
                var items = datelastsyncInfo.ToObject <List<PaymentNotificationListItem>>();// JsonConvert.DeserializeObject<List<PaymentNotificationListItem>>();
              
                _response.PaymentNotificationDetails = items;
            }
            catch (Exception ex)
            { 
                string error = "Failed to retrieve payment notification.\n" +
                               (ex.InnerException == null ? "" : ex.InnerException.Message);
                _log.Error(error);
                _response.StatusCode = "Error";
                _response.StatusDetail = error;
            }

            return _response;
        }
        ClientRequestResponseBase Map(tblPaymentRequest tbl)
        {
            ClientRequestResponseBase crr = null;

            ClientRequestResponseType type = (ClientRequestResponseType) tbl.ClientRequestResponseTypeId;
            switch(type)
            {
                case ClientRequestResponseType.AsynchronousPayment:
                    crr = new PaymentRequest();
                    break;
                case ClientRequestResponseType.AsynchronousPaymentNotification:
                    crr = new PaymentNotificationRequest();
                    break;
                case ClientRequestResponseType.BuyGoodsNotification:
                    crr = new BuyGoodsNotificationRequest();
                    break;
            }

            if (crr != null)
            {
                crr.Id = tbl.Id;
                crr.DistributorCostCenterId = tbl.DistributorCostCenterId;
                crr.ClientRequestResponseType = type;
                crr.DateCreated = tbl.DateCreated;

                if (crr.ClientRequestResponseType == ClientRequestResponseType.AsynchronousPayment)
                {
                    PaymentRequest apr = crr as PaymentRequest;

                    apr.AccountId                  = tbl.AccountId.Trim();
                    //apr.Amount                   = tbl.Amount.Value;
                    apr.ApplicationId              = tbl.ApplicationId.Trim();
                    apr.SubscriberId               = tbl.SubscriberId.Trim();
                    apr.Currency                   = tbl.Currency.Trim();
                    //apr.Extra                      = tbl.Extra.ToDictionary();
                    apr.InvoiceNumber              = tbl.InvoiceNumber.Trim();
                    apr.OrderNumber                = tbl.OrderNumber.Trim();
                    apr.PaymentInstrumentName      = tbl.PaymentInstrumentName.Trim();
                    apr.TransactionRefId           = tbl.TransactionRefId.Trim();
                }
                if (crr.ClientRequestResponseType == ClientRequestResponseType.AsynchronousPaymentNotification)
                {
                    PaymentNotificationRequest apn = crr as PaymentNotificationRequest;

                    apn.TransactionRefId    = tbl.TransactionRefId.Trim();
                    apn.SDPTransactionRefId = tbl.SDPTransactionRefId ?? "";
                    apn.SDPStatusCode       = tbl.StatusCode.Trim();
                    apn.SDPStatusDetail     = tbl.StatusDetail.Trim();
                    if (tbl.Amount         != null) apn.SDPPaidAmount = tbl.Amount.Value;
                    if (tbl.TotalAmount    != null) apn.SDPTotalAmount = tbl.TotalAmount.Value;
                    if (tbl.BalanceDue     != null) apn.SDPBalanceDue = tbl.BalanceDue.Value;
                    if (tbl.TimeStamp      != null) apn.SDPTimeStamp = tbl.TimeStamp.Value;
                    apn.SDPTransactionRefId = tbl.SDPTransactionRefId;
                    apn.SDPCurrency         = tbl.Currency.Trim();
                    apn.SDPReferenceId      = tbl.SDPReferenceId.Trim();
                }
                if (crr.ClientRequestResponseType == ClientRequestResponseType.BuyGoodsNotification)
                {
                    BuyGoodsNotificationRequest bgn = crr as BuyGoodsNotificationRequest;

                    bgn.Currency             = tbl.Currency.Trim();
                    bgn.Date                 = tbl.Date.Value;
                    if (tbl.MerchantBalance != null) bgn.MerchantBalance = tbl.MerchantBalance.Value;
                    if (tbl.Amount          != null) bgn.PaidAmount = tbl.Amount.Value;
                    bgn.ReceiptNumber        = tbl.ReceiptNumber.Trim();
                    bgn.SDPTransactionRefId  = tbl.SDPTransactionRefId.Trim();
                    bgn.StatusCode           = tbl.StatusCode.Trim();
                    bgn.StatusDetail         = tbl.StatusDetail.Trim();
                    bgn.SubscriberName       = tbl.SubscriberName.Trim();
                    bgn.Time                 = tbl.Time.Value;
                    bgn.TransactionRefId     = tbl.TransactionRefId.Trim();
                }

                return crr;
            }

            return null;
        }
Exemplo n.º 6
0
        public void ProcessSDPRequest(ServerRequestBase sdpRequest, out ClientRequestResponseBase crrRequest, out string subcriberid, out Guid sip)
        {
            subcriberid = "";
            sip = Guid.Empty;
            ClientRequestResponseBase paymentRequest = null;
            Guid serviceProviderId = Guid.Empty;
            crrRequest = new ClientRequestResponseBase();
            if (sdpRequest is SDPPaymentNotificationRequest)
            {
                paymentRequest = _paymentResponseRepository.GetByTransRefId(
                    new Guid(((SDPPaymentNotificationRequest)sdpRequest)
                        .externalTrxId))
                        .OfType<PaymentResponse>().FirstOrDefault();

                if (paymentRequest != null)
                {
                    serviceProviderId = paymentRequest.DistributorCostCenterId;
                   
                }
                if (paymentRequest  is PaymentResponse)
                {
                    var respo = ((PaymentResponse) paymentRequest);
                    subcriberid = respo.SubscriberId;
                    sip = respo.DistributorCostCenterId;
                }

                SDPPaymentNotificationRequest sdpapn =
                    sdpRequest as SDPPaymentNotificationRequest;

                PaymentNotificationRequest apn = new PaymentNotificationRequest();

                apn.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification;
                apn.DateCreated               = sdpapn.timestamp;
                apn.Id                        = Guid.NewGuid();
                apn.TransactionRefId          =ConstructMyGuid(sdpapn.externalTrxId).ToString();
                apn.SDPStatusCode             = sdpapn.statusCode;
                apn.SDPStatusDetail           = sdpapn.statusDetail;
                apn.SDPTimeStamp              = sdpapn.timestamp;
                apn.SDPTransactionRefId       = sdpapn.internalTrxId;
                apn.SDPPaidAmount             = Convert.ToDouble(sdpapn.paidAmount);
                apn.SDPTotalAmount            = Convert.ToDouble(sdpapn.totalAmount);
                apn.SDPBalanceDue             = Convert.ToDouble(sdpapn.balanceDue);
                apn.SDPCurrency               = sdpapn.currency;
                apn.SDPReferenceId            = sdpapn.referenceId;
                apn.DistributorCostCenterId   = serviceProviderId;
               
                crrRequest = apn;
            }
            else if (sdpRequest is SDPBuyGoodsNotificationRequest)
            {
                throw new Exception("Buy goods not in use");
                SDPBuyGoodsNotificationRequest sdpBg = sdpRequest as SDPBuyGoodsNotificationRequest;
                BuyGoodsNotificationRequest bgNotif = new BuyGoodsNotificationRequest();

                bgNotif.ClientRequestResponseType = ClientRequestResponseType.AsynchronousPaymentNotification;
                bgNotif.Currency = sdpBg.currency;
                bgNotif.Date = sdpBg.date;
                bgNotif.DateCreated = DateTime.Now;
                bgNotif.Id = Guid.NewGuid();
                bgNotif.MerchantBalance = Convert.ToDouble(sdpBg.merchantBalance);
                bgNotif.PaidAmount = Convert.ToDouble(sdpBg.paidAmount);
                bgNotif.ReceiptNumber = sdpBg.receiptNumber;
                bgNotif.SDPTransactionRefId = sdpBg.internalTrxId;
                bgNotif.StatusCode = sdpBg.statusCode;
                bgNotif.StatusDetail = sdpBg.statusDetail;
                bgNotif.SubscriberName = sdpBg.subscriberName;
                bgNotif.Time = sdpBg.time;

                crrRequest = bgNotif;
            }
        }