示例#1
0
        /// <summary>
        /// Send a cancel transaction after an authorize transaction to cancel it.
        /// </summary>
        /// <param name="transactionNumber">The transactionNumber of the transaction you wish to cancel.</param>
        public async Task <CancelResult> Cancel(int transactionNumber)
        {
            // Validation
            if (transactionNumber <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(transactionNumber), "transactionNumber is required");
            }

            // Build string for md5 including all fields except empty strings
            var hashInput = new StringBuilder();

            hashInput.Append(Account.AccountNumber);
            hashInput.Append(transactionNumber);
            // Add encryption key at the end of string to be hashed
            hashInput.Append(Account.EncryptionKey);
            // Create a hash string from the parameters
            string hash;

            MD5Hash.Hash(hashInput.ToString(), out hash);

            // Invoke Initialize method on external PayEx PxOrder web service
            var payexOrder = GetPxOrderClient();
            var xmlReturn  = await payexOrder.Cancel2Async(Account.AccountNumber, transactionNumber, hash);

            // Parse the result and retrieve code-node to figure out if the service method was invoked successfully.
            var result = ResultParser.ParseCancelResult(xmlReturn);

            return(result);
        }