示例#1
0
 public static object CreateRequestData(Invoice invoice, SepehrGatewayAccount account)
 {
     return(new TokenRequestModel
     {
         InvoiceId = invoice.TrackingNumber.ToString(),
         Amount = invoice.Amount,
         CallbackUrl = invoice.CallbackUrl,
         TerminalId = account.TerminalId
     });
 }
示例#2
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            SepehrGatewayAccount account,
            MessagesOptions messages)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                return(PaymentRequestResult.Failed($"Operation failed. Http Status: {responseMessage.StatusCode}", account.Name));
            }

            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            var result = JsonConvert.DeserializeObject <TokenResponseModel>(response);

            if (result == null)
            {
                return(PaymentRequestResult.Failed(messages.InvalidDataReceivedFromGateway, account.Name));
            }

            if (result.Status != 0)
            {
                var message = SepehrGatewayResultTranslator.Translate(result.Status.ToString(), messages);

                return(PaymentRequestResult.Failed(message, account.Name));
            }

            if (result.AccessToken.IsNullOrWhiteSpace())
            {
                return(PaymentRequestResult.Failed(messages.InvalidDataReceivedFromGateway, account.Name));
            }

            var transporterDescriptor = GatewayTransporterDescriptor.CreatePost(
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "TerminalID", account.TerminalId.ToString() },
                { "token", result.AccessToken }
            });

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }
示例#3
0
        public static async Task <CallbackResultModel> CreateCallbackResultAsync(
            InvoiceContext context,
            HttpRequest httpRequest,
            SepehrGatewayAccount account,
            MessagesOptions messages,
            CancellationToken cancellationToken)
        {
            var respCodeParam = await httpRequest.TryGetParamAsync("respcode", cancellationToken).ConfigureAwaitFalse();

            var respMsgParam = await httpRequest.TryGetParamAsync("respmsg", cancellationToken).ConfigureAwaitFalse();

            var invoiceIdParam = await httpRequest.TryGetParamAsync("invoiceid", cancellationToken).ConfigureAwaitFalse();

            var terminalIdParam = await httpRequest.TryGetParamAsync("terminalid", cancellationToken).ConfigureAwaitFalse();

            var amountParam = await httpRequest.TryGetParamAsync("amount", cancellationToken).ConfigureAwaitFalse();

            var traceNumberParam = await httpRequest.TryGetParamAsync("tracenumber", cancellationToken).ConfigureAwaitFalse();

            var rrnParam = await httpRequest.TryGetParamAsync("rrn", cancellationToken).ConfigureAwaitFalse();

            var digitalReceiptParam = await httpRequest.TryGetParamAsync("digitalreceipt", cancellationToken).ConfigureAwaitFalse();

            var cardNumberParam = await httpRequest.TryGetParamAsync("cardnumber", cancellationToken).ConfigureAwaitFalse();

            bool isSucceed;
            IPaymentVerifyResult verifyResult = null;
            long traceNumber = 0;
            long rrn         = 0;

            if (!respCodeParam.Exists)
            {
                verifyResult = PaymentVerifyResult.Failed(messages.InvalidDataReceivedFromGateway);
                isSucceed    = false;
            }
            else
            {
                if (!int.TryParse(respCodeParam.Value, out var responseCode))
                {
                    verifyResult = PaymentVerifyResult.Failed(messages.InvalidDataReceivedFromGateway);
                    isSucceed    = false;
                }
                else if (responseCode != 0)
                {
                    var message = respMsgParam.Exists ? (string)respMsgParam.Value : messages.PaymentFailed;
                    verifyResult = PaymentVerifyResult.Failed(message);
                    isSucceed    = false;
                }
                else
                {
                    var isValid = true;
                    var message = messages.InvalidDataReceivedFromGateway;

                    if (!invoiceIdParam.Exists || !string.Equals(invoiceIdParam.Value, context.Payment.TrackingNumber.ToString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        isValid  = false;
                        message += " InvoiceID is not valid.";
                    }

                    if (!terminalIdParam.Exists || !string.Equals(terminalIdParam.Value, account.TerminalId.ToString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        isValid  = false;
                        message += " TerminalID is not valid.";
                    }

                    if (!amountParam.Exists || !string.Equals(amountParam.Value, ((long)context.Payment.Amount).ToString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        isValid  = false;
                        message += " Amount is not valid.";
                    }

                    if (!traceNumberParam.Exists)
                    {
                        isValid  = false;
                        message += " TraceNumber doesn't exist.";
                    }
                    else
                    {
                        traceNumber = long.Parse(traceNumberParam.Value);
                    }

                    if (!rrnParam.Exists)
                    {
                        isValid  = false;
                        message += " RRN doesn't exist.";
                    }
                    else
                    {
                        rrn = long.Parse(rrnParam.Value);
                    }

                    if (!digitalReceiptParam.Exists)
                    {
                        isValid  = false;
                        message += " DigitalReceipt doesn't exist.";
                    }

                    if (!isValid)
                    {
                        verifyResult = PaymentVerifyResult.Failed(message);
                    }

                    isSucceed = isValid;
                }
            }

            return(new CallbackResultModel
            {
                IsSucceed = isSucceed,
                Result = verifyResult,
                TraceNumber = traceNumber,
                Rrn = rrn,
                DigitalReceipt = digitalReceiptParam.Value,
                CardNumber = cardNumberParam.Value
            });
        }
示例#4
0
        public static VerificationRollbackRequestModel CreateRefundData(InvoiceContext context, SepehrGatewayAccount account)
        {
            var verificationRecord = context.Transactions.SingleOrDefault(transaction => transaction.Type == TransactionType.Verify);

            if (verificationRecord == null)
            {
                throw new Exception("No verification record found in transactions.");
            }

            var additionalData = JsonConvert.DeserializeObject <IDictionary <string, string> >(verificationRecord.AdditionalData);

            if (additionalData == null || !additionalData.ContainsKey(VerificationAdditionalDataKey))
            {
                throw new Exception("No Additional Data found in transactions record.");
            }

            var verificationAdditionalData = JsonConvert.DeserializeObject <SepehrGatewayVerificationAdditionalData>(additionalData[VerificationAdditionalDataKey]);

            if (verificationAdditionalData == null)
            {
                throw new Exception("No Additional Data found in transactions record.");
            }

            return(new VerificationRollbackRequestModel
            {
                Tid = account.TerminalId,
                DigitalReceipt = verificationAdditionalData.DigitalReceipt
            });
        }
示例#5
0
 public static VerificationRollbackRequestModel CreateVerifyData(CallbackResultModel callbackResult, SepehrGatewayAccount account)
 {
     return(new VerificationRollbackRequestModel
     {
         DigitalReceipt = callbackResult.DigitalReceipt,
         Tid = account.TerminalId
     });
 }