Beispiel #1
0
 private async void ApiGetBuyGoodsNotification(string paymentRef)
 {
     using (var c = NestedContainer)
     {
         PaymentTransactionRefId = Guid.NewGuid();
         var bgr = new BuyGoodsNotificationRequest()
         {
             ClientRequestResponseType = ClientRequestResponseType.BuyGoodsNotification,
             DateCreated = DateTime.Now,
             DistributorCostCenterId = Using<IConfigService>(c).Load().CostCentreId,
             Id = Guid.NewGuid(),
             TransactionRefId = paymentRef
         };
         _clientRequestResponses.Add(bgr);
         var pgresponse = await Using<IPaymentGatewayProxy>(c).GetBuyGoodsNotificationAsync(bgr);
         ProcessPaymentNotification(pgresponse);
         MMoneyIsApproved = false;
     }
 }
        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;
        }
        public async Task<BuyGoodsNotificationResponse> GetBuyGoodsNotificationAsync(BuyGoodsNotificationRequest request)
        {
            BuyGoodsNotificationResponse _response = new BuyGoodsNotificationResponse();
            HttpClient httpClient = setupHttpClient();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            string url = "api/bridge/payment/getbuygoodsnotification";
            try
            {
                var response = await httpClient.PostAsJsonAsync(url, request);
                _response = await response.Content.ReadAsAsync<BuyGoodsNotificationResponse>();
            }
            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;
        }
        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;
            }
        }