Exemplo n.º 1
0
        public static string CreateRefundData(ParsianGatewayAccount account, InvoiceContext context, Money amount)
        {
            var transaction = context.Transactions.SingleOrDefault(item => item.Type == TransactionType.Verify);

            if (transaction == null)
            {
                throw new InvalidOperationException($"No transaction record found in database for payment with tracking number {context.Payment.TrackingNumber}.");
            }

            if (!AdditionalDataConverter.ToDictionary(transaction).TryGetValue("token", out var token))
            {
                throw new InvalidOperationException($"No token found in database for payment with tracking number {context.Payment.TrackingNumber}.");
            }

            return
                ("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:rev=\"https://pec.Shaparak.ir/NewIPGServices/Reversal/ReversalService\">" +
                 "<soap:Header/>" +
                 "<soap:Body>" +
                 "<rev:ReversalRequest>" +
                 "<!--Optional:-->" +
                 "<rev:requestData>" +
                 "<!--Optional:-->" +
                 $"<rev:LoginAccount>{XmlHelper.EncodeXmlValue(account.LoginAccount)}</rev:LoginAccount>" +
                 $"<rev:Token>{XmlHelper.EncodeXmlValue(token)}</rev:Token>" +
                 "</rev:requestData>" +
                 "</rev:ReversalRequest>" +
                 "</soap:Body>" +
                 "</soap:Envelope>");
        }
Exemplo n.º 2
0
        public static string GetVerificationUrl(InvoiceContext invoiceContext, SamanGatewayOptions gatewayOptions)
        {
            var record = invoiceContext
                         .Transactions
                         .SingleOrDefault(transaction => transaction.Type == TransactionType.Request);

            if (record == null || record.AdditionalData.IsNullOrEmpty())
            {
                return(gatewayOptions.WebApiUrl);
            }

            if (AdditionalDataConverter.ToDictionary(record).TryGetValue(MobileGatewayKey, out var isMobileGatewayEnabled) && bool.Parse(isMobileGatewayEnabled))
            {
                return(gatewayOptions.MobileApiVerificationUrl);
            }

            return(gatewayOptions.WebApiUrl);
        }
Exemplo n.º 3
0
        public static IEnumerable <KeyValuePair <string, string> > CreateRefundData(
            InvoiceContext context,
            Money amount,
            IPasargadCrypto crypto,
            PasargadGatewayAccount account)
        {
            var transactionRecord = context.Transactions.FirstOrDefault(transaction => transaction.Type == TransactionType.Request);

            if (transactionRecord == null)
            {
                throw new Exception($"Cannot find transaction record for Payment-{context.Payment.TrackingNumber}");
            }

            if (!AdditionalDataConverter.ToDictionary(transactionRecord).TryGetValue("invoiceDate", out var invoiceDate))
            {
                throw new Exception("Cannot get the invoiceDate from database.");
            }

            var timeStamp = GetTimeStamp(DateTime.Now);

            var dataToSign = string.Format("#{0}#{1}#{2}#{3}#{4}#{5}#{6}#",
                                           account.MerchantCode,
                                           account.TerminalCode,
                                           context.Payment.TrackingNumber,
                                           invoiceDate,
                                           (long)amount,
                                           RefundNumber,
                                           timeStamp);

            var signedData = crypto.Encrypt(account.PrivateKey, dataToSign);

            return(new[]
            {
                new KeyValuePair <string, string>("InvoiceNumber", context.Payment.TrackingNumber.ToString()),
                new KeyValuePair <string, string>("InvoiceDate", invoiceDate),
                new KeyValuePair <string, string>("MerchantCode", account.MerchantCode),
                new KeyValuePair <string, string>("TerminalCode", account.TerminalCode),
                new KeyValuePair <string, string>("Amount", amount.ToLongString()),
                new KeyValuePair <string, string>("action", RefundNumber),
                new KeyValuePair <string, string>("TimeStamp", timeStamp),
                new KeyValuePair <string, string>("Sign", signedData)
            });
        }