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}"; } }
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; }
public Address(ScriptPubKey scriptPubKey, TxnType txnType) { byte[] pushData = Script.FromScriptPubKey(scriptPubKey, txnType); List <byte> hash; byte prefix = 0x00; switch (txnType) { case TxnType.P2SH: hash = new List <byte>(pushData); prefix = (byte)Prefix.TestnetP2SH; break; case TxnType.P2WPKH: hash = new List <byte>(pushData); break; case TxnType.P2WSH: hash = new List <byte>(pushData); break; case TxnType.P2PKH: hash = new List <byte>(pushData); prefix = (byte)Prefix.TestnetP2PKH; break; case TxnType.P2PK: hash = Crypto.DoubleHash(pushData); prefix = (byte)Prefix.TestnetP2PKH; break; default: hash = null; break; } if (hash != null) { if (txnType == TxnType.P2WPKH || txnType == TxnType.P2WSH) { address = Bech32.Encode(0, hash.ToArray(), false); } else { hash.Insert(0, prefix); Crypto.AddChecksum(ref hash); address = Base58Check.Encode(hash.ToArray()); } } }
public static string TxnColor(this HtmlHelper htmlHelper, TxnType txnType) { var output = string.Empty; switch (txnType) { case TxnType.Expenditure: output = "text-danger"; break; case TxnType.Income: output = "text-primary"; break; } return(output); }
public XElement ToQBXML(string name) { XElement xElement = new XElement(name); xElement.Add(TxnID.ToQBXML(nameof(TxnID))); xElement.Add(TxnType.ToQBXML(nameof(TxnType))); xElement.Add(TxnDate?.ToQBXML(nameof(TxnDate))); xElement.Add(RefNumber.ToQBXML(nameof(RefNumber))); xElement.Add(BalanceRemaining?.ToQBXML(nameof(BalanceRemaining))); xElement.Add(Amount?.ToQBXML(nameof(Amount))); xElement.Add(DiscountAmount?.ToQBXML(nameof(DiscountAmount))); xElement.Add(DiscountAccountRef.ToQBXML(nameof(DiscountAccountRef))); xElement.Add(DiscountClassRef.ToQBXML(nameof(DiscountClassRef))); xElement.Add(LinkedTxnList.ToQBXML(nameof(LinkedTxn))); return(xElement); }
public static byte[] FromScriptPubKey(ScriptPubKey scriptPubKey, TxnType txnType) { byte[] ret; switch (txnType) { case TxnType.P2SH: ret = new byte[scriptPubKey[1]]; Array.Copy(scriptPubKey.scriptPubKey, 2, ret, 0, scriptPubKey[1]); break; case TxnType.P2WPKH: ret = new byte[scriptPubKey[1]]; Array.Copy(scriptPubKey.scriptPubKey, 2, ret, 0, scriptPubKey[1]); break; case TxnType.P2WSH: ret = new byte[scriptPubKey[1]]; Array.Copy(scriptPubKey.scriptPubKey, 2, ret, 0, scriptPubKey[1]); break; case TxnType.P2PKH: ret = new byte[scriptPubKey[2]]; Array.Copy(scriptPubKey.scriptPubKey, 3, ret, 0, scriptPubKey[2]); break; case TxnType.P2PK: ret = new byte[scriptPubKey[0]]; Array.Copy(scriptPubKey.scriptPubKey, 1, ret, 0, scriptPubKey[0]); break; default: ret = null; break; } return(ret); }
public static Address ExtractDestination(OutputTxn output) { TxnType txnType = TxnType.Nonstandard; if (IsPayToScriptHash(output.scriptPubKey)) { txnType = TxnType.P2SH; } int witnessVersion = 0; byte[] witnessProgram = null; if (IsWitnessProgram(output.scriptPubKey, ref witnessVersion, ref witnessProgram)) { if (witnessVersion == 0 && witnessProgram.Length == (int)Witness.Ver_0_KeyHash_Size) { txnType = TxnType.P2WPKH; } else if (witnessVersion == 0 && witnessProgram.Length == (int)Witness.Ver_0_ScriptHash_Size) { txnType = TxnType.P2WSH; } else if (witnessVersion != 0) { txnType = TxnType.Nonstandard; } else { txnType = TxnType.Nonstandard; } } if (MatchPayToPubKeyHash(output.scriptPubKey)) { txnType = TxnType.P2PKH; } if (IsUnspendable(output.scriptPubKey)) { txnType = TxnType.NullPushData; } if (MatchPayToPubKey(output.scriptPubKey)) { txnType = TxnType.P2PK; } if (MatchRawMultiSig(output.scriptPubKey)) { txnType = TxnType.RawMultisig; } if (txnType == TxnType.Nonstandard || txnType == TxnType.NullPushData || txnType == TxnType.RawMultisig) { return(new Address()); } return(new Address(output.scriptPubKey, txnType)); }