/// <summary>
        /// Generate SHA256 string
        /// </summary>
        /// <param name="r"></param>
        /// <returns>string</returns>
        private static string GenerateCheckInvoiceStatusSignatureAscending(PayFortCheckInvoiceRequestModel r)
        {
            try
            {
                var response = $"{r.RequestPhrase}access_code={r.AccessCode}language={r.Language}merchant_identifier={r.MerchantIdentifier}merchant_reference={r.MerchantReference}query_command={r.QueryCommand}{r.RequestPhrase}";

                return(response);
            }
            catch
            {
                return(string.Empty);
            }
        }
 public static string GenerateCheckInvoiceStatusSHA256Signature(this PayFortCheckInvoiceRequestModel request)
 {
     try
     {
         //Align Parameters names in ascending order and then
         //convert to SHA256
         return(ConvertToSHA256(GenerateCheckInvoiceStatusSignatureAscending(request)));
     }
     catch
     {
         return(string.Empty);
     }
 }
コード例 #3
0
        /// <summary>
        /// Checks the invoice status.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public PayFortCheckInvoiceRequestModel CheckInvoiceStatus(PayFortCheckInvoiceRequestModel request)
        {
            //Declarations

            //1. Generate SHA256 Signature
            request.Signature = request.GenerateCheckInvoiceStatusSHA256Signature();

            //2. Generate Json Request Parameter
            var jsonRequest = request.GenerateCheckInvoiceStatusRequestParams();

            //3. Send Request
            return(InvoiceProcessor.CheckStatus(jsonRequest, request));
        }
 /// <summary>
 /// Get Authorization Request Params
 /// </summary>
 /// <param name="request"></param>
 /// <returns>string</returns>
 public static string GenerateCheckInvoiceStatusRequestParams(this PayFortCheckInvoiceRequestModel request)
 {
     try
     {
         return(string.Format("{{\"access_code\":\"{0}\",\"language\":\"{1}\",\"merchant_identifier\":\"{2}\",\"merchant_reference\":\"{3}\",\"query_command\":\"{4}\",\"signature\":\"{5}\"}}",
                              request.AccessCode,
                              request.Language,
                              request.MerchantIdentifier,
                              request.MerchantReference,
                              request.QueryCommand,
                              request.Signature));
     }
     catch
     {
         return(string.Empty);
     }
 }
コード例 #5
0
        public static PayFortCheckInvoiceRequestModel CheckStatus(string jsonRequest, PayFortCheckInvoiceRequestModel response)
        {
            //Declarations
            var pfResponse = string.Empty;

            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

                var httpWebRequest = (HttpWebRequest)WebRequest.Create(response.Url);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(jsonRequest);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    pfResponse = streamReader.ReadToEnd();
                }

                return(GetInvoiceStatusResponse(pfResponse, response));
            }
            catch
            {
                response.IsValid = false;
                return(response);
            }
        }
コード例 #6
0
        /// <summary>
        /// Get Payfort Response Info
        /// </summary>
        /// <param name="pfResponse"></param>
        /// <returns>Payfort Error Info</returns>
        private static PayFortCheckInvoiceRequestModel GetInvoiceStatusResponse(string pfResponse, PayFortCheckInvoiceRequestModel response)
        {
            //var urlResponse = (JObject)JsonConvert.DeserializeObject(pfResponse);

            var payfortResponse = JsonConvert.DeserializeObject <PayfortCheckStatus>(pfResponse);


            response.IsValid = true;

            response.ResponseCode       = payfortResponse.response_code;
            response.AuthorizedAmount   = payfortResponse.authorized_amount.ToDecimal() / 100;
            response.CapturedAmount     = payfortResponse.captured_amount.ToDecimal() / 100;
            response.RefundedAmount     = payfortResponse.refunded_amount.ToDecimal() / 100;
            response.ResponseMessage    = payfortResponse.response_message;
            response.TransactionCode    = payfortResponse.transaction_code;
            response.TransactionMessage = payfortResponse.transaction_message;
            response.TransactionStatus  = payfortResponse.transaction_status;
            response.Status             = payfortResponse.status;
            response.FortId             = payfortResponse.fort_id;

            //if (responseCodeStatus == PayFortResponseStatusEnum.CheckStatusSuccess
            //    && responseCodeMessage == PayFortResponseMessageEnum.Success
            //    && transactionStatus == PayFortResponseStatusEnum.PurchaseSuccess)
            //{
            //    response.TransactionStatus = transactionStatus;
            //}

            response.ProfilerResponse = pfResponse;

            return(response);
        }