public GenerateRequestMessage(string pxPayUserId,
            string pxPayKey,
            string urlSuccess,
            string urlFail,
            Currency currencyInput,
            TxnType txnType,
            decimal amount = 0,
            ClientType clientType = DpsPayfit.Client.ClientType.Internet,
            DateTimeOffset? timeout = null)
        {
            if (string.IsNullOrWhiteSpace(pxPayUserId)) throw new ArgumentNullException(nameof(pxPayUserId));
            if (string.IsNullOrWhiteSpace(pxPayKey)) throw new ArgumentNullException(nameof(pxPayKey));
            if (string.IsNullOrWhiteSpace(urlSuccess)) throw new ArgumentNullException(nameof(urlSuccess));
            if (string.IsNullOrWhiteSpace(urlFail)) throw new ArgumentNullException(nameof(urlFail));

            PxPayUserId = pxPayUserId;
            PxPayKey = pxPayKey;
            UrlSuccess = urlSuccess;
            UrlFail = urlFail;
            Amount = amount;
            CurrencyInput = currencyInput;
            TxnType = txnType.ToString();
            ClientType = clientType.ToString();
            if (timeout.HasValue)
            {
                Timeout = $"{timeout:yyMMddHHmm}";
            }
        }
Beispiel #2
0
        public async Task<string> GenerateRequest(TxnType txnType, string txnId, decimal amountInput, 
            string merchantReference, bool enableAddBillCard, string dpsBillingId)
        {
            var data = new Dictionary<string, string>
            {
                {"TxnType", txnType.ToString()},
                {"AmountInput", amountInput.ToString()},
                {"TxnId", txnId},
                {"DpsBillingId", dpsBillingId},
                {"EnableAddBillCard", enableAddBillCard ? "1" : "0"},
                {"MerchantReference", HttpUtility.HtmlEncode(merchantReference)},
                {"CurrencyInput", CurrencyInput},
                {"UrlSuccess", UrlSuccess}, 
                {"UrlFail", UrlFail}
            };

            var xml = await SendRequest("GenerateRequest", data);

            if (xml.Element("URI") == null)
            {
                Trace.TraceError($"GenerateRequest Error. Response: {xml}");
                throw new PxPayException("GenerateRequest Error", xml.Element("Reco").Value, xml.Element("ResponseText").Value);
            } else if (xml.Attribute("valid").Value != "1")
            {
                Trace.TraceError($"GenerateRequest Invalid. Response: {xml}");
                throw new PxPayException("GenerateRequest Invalid", "", xml.Element("URI").Value);
            }

            return xml.Element("URI").Value;
        }