Example #1
0
        public ApiResponse <PaymentStatusResponse> GetPaymentStatus(string transId, string ComGateAPIEndpointUrl)
        {
            transId = SunamoComgateHelper.Instance.InsertDashes(transId);

            using (var httpClient = HttpClientFactory.CreateHttpClient(Core.Domain.Enums.ComGateHttpClient.HttpClient))
            {
                PaymentStatusRequest statusRequest = new PaymentStatusRequest()
                                                     .SetMerchant(this.Merchant)
                                                     .SetSecret(this.Secret)
                                                     .SetTransactionId(transId);


                var content = _serializer.Serialize <PaymentStatusRequest>(statusRequest);

                httpClient.BaseAddress = new Uri(ComGateAPIEndpointUrl);

                var response = httpClient.PostAsync("status", content).Result;

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = response.Content.ReadAsStringAsync().Result;
                    return(_serializer.Deserialize <PaymentStatusResponse>(responseContent));
                }
                else
                {
                    throw new Exception("Cannot create method list");
                }
            }
        }
Example #2
0
        public async Task <HttpStatusCode> RequestPayment(int applicationId, PaymentStatusRequest paymentStatusRequest)
        {
            var requestUri = $"application/{applicationId}/payment";

            var response = await GetStatusAndContent(CreateRequestMessage(HttpMethod.Post, requestUri, retailerApiToken, paymentStatusRequest));

            return(response.StatusCode);
        }
Example #3
0
        /// <summary>
        /// Gets the payment status of a specific transaction.
        /// It can be useful in cases where something goes wrong in the payment or
        /// reverse payment flow and your client is unsure of the outcome of the operation.
        /// </summary>
        /// <param name="request">Payment status request.</param>
        /// <returns>The payment status response.</returns>
        public async Task <PaymentStatusResponse> GetPaymentStatusAsync(PaymentStatusRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(await _client.GetAsync($"{RelativeUri.Pay}/{request.ClientReference}")
                   .ConfigureAwait(false)
                   .ThrowIfErrorResponseAsync()
                   .DeserializeAsync <PaymentStatusResponse>());
        }
        public async Task <PaymentStatusResponse> GetPaymentStatusAsync(PaymentStatusRequest request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            var definition = new RequestDefinition
            {
                Url    = $"/{request.TransactionId}/status",
                Method = HttpMethods.Get
            };

            this.logger.LogTrace($"Start send check status payment request to [{definition.Method}] {this.GetRequestUrl(definition)}");
            var rawResult = await this.ApplyAsync(definition);

            return(this.Deserialize <PaymentStatusResponse>(rawResult));
        }
Example #5
0
        private async Task <PaymentStatusResponse> GetPaymentStatus(string token)
        {
            var paymentStatusRequest = new PaymentStatusRequest(_setting.Value.MerchantId, _setting.Value.MerchantPassword, token);
            var httpClient           = _httpClientFactory.CreateClient();
            var nganLuongUrl         = _setting.Value.IsSandbox ? "https://sandbox.nganluong.vn:8088/nl35/service/order/check" : "https://www.nganluong.vn/service/order/check";
            var requestMesage        = new HttpRequestMessage(HttpMethod.Post, nganLuongUrl)
            {
                Content = paymentStatusRequest.MakePostContent()
            };
            var response = await httpClient.SendAsync(requestMesage);

            response.EnsureSuccessStatusCode();
            var contentString = await response.Content.ReadAsStringAsync();

            var paymentStatusResponse = JsonConvert.DeserializeObject <PaymentStatusResponse>(contentString);

            return(paymentStatusResponse);
        }
        /// <summary>
        /// Get data FromMySQL where Payment Pending
        /// </summary>
        /// <param name="ConString"></param>
        public static void GetdataFromMySQL(string ConString)
        {
            int    ID              = 0;
            int    TenantId        = 0;
            string InvoiceNo       = string.Empty;
            string Date            = string.Empty;
            string CustomerName    = string.Empty;
            string MobileNumber    = string.Empty;
            string TokenId         = string.Empty;
            string Alias           = string.Empty;
            string StoreCode       = string.Empty;
            string CompanayName    = string.Empty;
            string apiResponse     = string.Empty;
            string apitokenRes     = string.Empty;
            string ShippingAddress = string.Empty;
            string PinCode         = string.Empty;
            string City            = string.Empty;
            string State           = string.Empty;
            string Country         = string.Empty;
            string DeliveryType    = string.Empty;

            PaymentStatusResponse paymentapiResponse = new PaymentStatusResponse();

            MySqlConnection con = null;

            try
            {
                DataTable dt = new DataTable();

                IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json", true, true).Build();

                string ClientAPIURL = config.GetSection("MySettings").GetSection("ClientAPIURL").Value;
                string clientAPIUrlForGenerateToken = config.GetSection("MySettings").GetSection("clientAPIUrlForGenerateToken").Value;
                string TerminalId    = config.GetSection("MySettings").GetSection("TerminalId").Value;
                string Client_Id     = config.GetSection("MySettings").GetSection("Client_Id").Value;
                string Client_Secret = config.GetSection("MySettings").GetSection("Client_Secret").Value;
                string Grant_Type    = config.GetSection("MySettings").GetSection("Grant_Type").Value;
                string Scope         = config.GetSection("MySettings").GetSection("Scope").Value;

                con = new MySqlConnection(ConString);
                MySqlCommand cmd = new MySqlCommand("SP_PHYGetPaymentDetails", con)
                {
                    CommandType = System.Data.CommandType.StoredProcedure
                };
                cmd.Connection.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                da.Fill(dt);
                cmd.Connection.Close();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        ID              = Convert.ToInt32(dr["ID"]);
                        TenantId        = Convert.ToInt32(dr["TenantId"]);
                        InvoiceNo       = Convert.ToString(dr["InvoiceNo"]);
                        Date            = Convert.ToDateTime(dr["Date"]).ToString("yyyy-MM-dd HH:mm:ss");
                        CustomerName    = Convert.ToString(dr["CustomerName"]);
                        MobileNumber    = Convert.ToString(dr["MobileNumber"]);
                        TokenId         = Convert.ToString(dr["TokenId"]);
                        Alias           = Convert.ToString(dr["Alias"]);
                        StoreCode       = Convert.ToString(dr["StoreCode"]);
                        CompanayName    = Convert.ToString(dr["ProgramCode"]);
                        ShippingAddress = Convert.ToString(dr["ShippingAddress"]);
                        PinCode         = Convert.ToString(dr["PinCode"]);
                        City            = Convert.ToString(dr["City"]);
                        State           = Convert.ToString(dr["State"]);
                        Country         = Convert.ToString(dr["Country"]);
                        DeliveryType    = Convert.ToString(dr["DeliveryType"]);

                        var dtOffset = DateTimeOffset.Parse(Date, CultureInfo.InvariantCulture);

                        string apiReq = "Client_Id=" + Client_Id + "&Client_Secret=" + Client_Secret + "&Grant_Type=" + Grant_Type + "&Scope=" + Scope;

                        apitokenRes = CommonService.SendApiRequestToken(clientAPIUrlForGenerateToken + "connect/token", apiReq);
                        HSResponseGenerateToken hSResponseGenerateToken = new HSResponseGenerateToken();
                        hSResponseGenerateToken = JsonConvert.DeserializeObject <HSResponseGenerateToken>(apitokenRes);

                        PaymentStatusRequest paymentStatus = new PaymentStatusRequest
                        {
                            tokenId     = TokenId,
                            programCode = CompanayName,
                            storeCode   = StoreCode,
                            //billDateTime = dtOffset.ToString("yyyy-MM-dd'T'HH:mm:ss.249'Z'"),
                            billDateTime  = dtOffset.ToString("dd-MMM-yyyy hh:mm:ss"),
                            terminalId    = TerminalId,
                            merchantTxnID = InvoiceNo,
                            mobile        = MobileNumber.TrimStart('0')
                        };
                        string apiReqpayment = JsonConvert.SerializeObject(paymentStatus);

                        if (!string.IsNullOrEmpty(hSResponseGenerateToken.access_token))
                        {
                            apiResponse        = CommonService.SendApiRequest(ClientAPIURL + "/api/GetPaymentStatus", apiReqpayment, hSResponseGenerateToken.access_token);
                            paymentapiResponse = JsonConvert.DeserializeObject <PaymentStatusResponse>(apiResponse);
                        }
                        if (paymentapiResponse.returnCode == "0" && paymentapiResponse.tokenStatus.Contains("Success"))
                        {
                            if (ShippingAddress != "" && PinCode != "" && City != "" && State != "" && Country != "" && DeliveryType != "Pickup")
                            {
                                UpdateResponse(ID, /*paymentapiResponse.status*/ "PaymentDetails", ConString);
                            }
                            else
                            {
                                UpdatePaymentResponse(ID, /*paymentapiResponse.status*/ "PaymentDetails", DeliveryType, ConString);
                            }

                            //CommonService.SmsWhatsUpDataSend(TenantId, 0, CompanayName, ID, ClientAPIURL, "PaymentStatus", ConString, hSResponseGenerateToken.access_token);
                        }
                        else
                        {
                            ExLogger(ID, InvoiceNo, Date, StoreCode, paymentapiResponse.returnMessage, paymentapiResponse.tokenStatus, ConString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExLogger(ID, InvoiceNo, Date, StoreCode, ex.Message, ex.StackTrace, ConString);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
                GC.Collect();
            }
        }
Example #7
0
        private IEnumerable <KeyValuePair <string, string> > CreateStatusMandatoryParams(PaymentStatusRequest request)
        {
            List <KeyValuePair <string, string> > mandatoryParameters = new List <KeyValuePair <string, string> >();

            mandatoryParameters.Add(new KeyValuePair <string, string>("merchant", request.Merchant));
            mandatoryParameters.Add(new KeyValuePair <string, string>("secret", request.Secret));
            mandatoryParameters.Add(new KeyValuePair <string, string>("transId", request.TransactionID));

            return(mandatoryParameters);
        }