Exemplo n.º 1
0
        private void Process_IPN_Request(TransactionResult result, CheckoutDetails details)
        {
            result.RawResponse = "";

            // build raw response
            foreach (string keyName in details.GetAllKeys())
            {
                if (String.IsNullOrEmpty(keyName))
                {
                    continue;
                }

                // check for separator
                if (!String.IsNullOrEmpty(result.RawResponse) &&
                    !result.RawResponse.EndsWith("&"))
                {
                    result.RawResponse += "&";
                }

                result.RawResponse += keyName + "=" + details[keyName];
            }
            // compare business account against email addres in response
            if (!String.Equals(details["receiver_email"], Business, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception(BUSINESS_NOT_MATCH_MSG);
            }

            // validate whether response still genuine
            if (!IsResponseGenuine(result.RawResponse))
            {
                throw new Exception(INVALID_RESPONSE_MSG);
            }
            // build tran id
            string transactionId = details["txn_id"];

            // check payment status
            switch (details["payment_status"])
            {
            case "Completed":
            case "Processed":
                result.Succeed = true;
                // store order details
                result.TransactionId     = transactionId;
                result.TransactionStatus = TransactionStatus.Approved;
                break;

            case "Pending":
                result.Succeed = true;
                // store order details
                result.TransactionId     = transactionId;
                result.TransactionStatus = TransactionStatus.Pending;
                break;

            default:
                result.Succeed           = false;
                result.TransactionStatus = TransactionStatus.Declined;
                break;
            }
        }
Exemplo n.º 2
0
        public TransactionResult SubmitPaymentTransaction(CheckoutDetails details)
        {
            TransactionResult result = new TransactionResult();

            // build raw response for 2CO
            string[]      keys  = details.GetAllKeys();
            List <string> bunch = new List <string>();

            // copy checkout details
            foreach (string key in keys)
            {
                bunch.Add(String.Concat(key, "=", details[key]));
            }
            // build raw 2CO response
            result.RawResponse = String.Join("|", bunch.ToArray());
            // recognize credit card status
            switch (details[CREDIT_CARD_PROCESSED])
            {
            case "Y":
                result.TransactionStatus = TransactionStatus.Approved;
                break;

            case "K":
                result.TransactionStatus = TransactionStatus.Pending;
                break;

            default:
                throw new Exception(CC_PROCESSED_ERROR_MSG);
            }
            // read order number
            string order_number = details["order_number"];
            // check demo mode: set order number to 1
            // according to 2Checkout documentation for demo transactions

            bool valid = false;

            // validate TCO key
            if (LiveMode)             // do live validation
            {
                valid = ValidateKey(SecretWord, AccountSID, order_number, details[CheckoutKeys.Amount], details[KEY]);
            }
            else             // do demo validation
            {
                valid = ValidateKey(SecretWord, AccountSID, "1", details[CheckoutKeys.Amount], details[KEY]);
            }

            // key validation failed
            if (!valid)
            {
                throw new ArgumentException(KEY_VALIDATION_FAILED_MSG);
            }
            // we are succeed copy order number
            result.TransactionId = order_number;
            //
            result.Succeed = true;
            // return result
            return(result);
        }
Exemplo n.º 3
0
        internal static void SerializeProfile(ref string propertyNames, ref string propertyValues,
                                              bool encrypt, CheckoutDetails profile)
        {
            // names
            StringBuilder namesBuilder = new StringBuilder();
            // string values
            StringBuilder valsBuilder = new StringBuilder();

            //
            string[] allKeys = profile.GetAllKeys();
            //
            foreach (string keyName in allKeys)
            {
                //
                int length = 0, position = 0;
                // get serialized property value
                string keyValue = profile[keyName];
                //
                if (String.IsNullOrEmpty(keyValue))
                {
                    length = -1;
                }
                else
                {
                    //
                    length = keyValue.Length;
                    //
                    position = valsBuilder.Length;
                    //
                    valsBuilder.Append(keyValue);
                }
                //
                namesBuilder.Append(keyName + ":S:" + position.ToString(CultureInfo.InvariantCulture) + ":" + length.ToString(CultureInfo.InvariantCulture) + ":");
            }
            //
            propertyNames = (encrypt) ? CryptoUtils.Encrypt(namesBuilder.ToString()) : namesBuilder.ToString();
            //
            propertyValues = (encrypt) ? CryptoUtils.Encrypt(valsBuilder.ToString()) : valsBuilder.ToString();
        }
		private void Process_IPN_Request(TransactionResult result, CheckoutDetails details)
		{
			result.RawResponse = "";

			// build raw response
			foreach (string keyName in details.GetAllKeys())
			{
				if (String.IsNullOrEmpty(keyName))
					continue;

				// check for separator
				if (!String.IsNullOrEmpty(result.RawResponse) && 
					!result.RawResponse.EndsWith("&"))
					result.RawResponse += "&";

				result.RawResponse += keyName + "=" + details[keyName];
			}
			// compare business account against email addres in response
			if (!String.Equals(details["receiver_email"], Business, StringComparison.InvariantCultureIgnoreCase))
				throw new Exception(BUSINESS_NOT_MATCH_MSG);

			// validate whether response still genuine
			if(!IsResponseGenuine(result.RawResponse))
				throw new Exception(INVALID_RESPONSE_MSG);
			// build tran id
			string transactionId = details["txn_id"];
			// check payment status
			switch(details["payment_status"])
			{
				case "Completed":
				case "Processed":
					result.Succeed = true;
					// store order details
					result.TransactionId = transactionId;
					result.TransactionStatus = TransactionStatus.Approved;
					break;
				case "Pending":
					result.Succeed = true;
					// store order details
					result.TransactionId = transactionId;
					result.TransactionStatus = TransactionStatus.Pending;
					break;
				default:
					result.Succeed = false;
					result.TransactionStatus = TransactionStatus.Declined;
					break;
			}
		}
Exemplo n.º 5
0
		public TransactionResult SubmitPaymentTransaction(CheckoutDetails details)
		{
			TransactionResult result = new TransactionResult();
			// build raw response for 2CO
			string[] keys = details.GetAllKeys();
			List<string> bunch = new List<string>();
			// copy checkout details
			foreach (string key in keys)
			{
				bunch.Add(String.Concat(key, "=", details[key]));
			}
			// build raw 2CO response
			result.RawResponse = String.Join("|", bunch.ToArray());
			// recognize credit card status
            switch(details[CREDIT_CARD_PROCESSED])
            {
                case "Y":
                    result.TransactionStatus = TransactionStatus.Approved;
                    break;
                case "K":
                    result.TransactionStatus = TransactionStatus.Pending;
                    break;
                default:
                    throw new Exception(CC_PROCESSED_ERROR_MSG);
            }
			// read order number
			string order_number = details["order_number"];
			// check demo mode: set order number to 1
			// according to 2Checkout documentation for demo transactions
			
			bool valid = false;
			// validate TCO key
			if (LiveMode) // do live validation
				valid = ValidateKey(SecretWord, AccountSID, order_number, details[CheckoutKeys.Amount], details[KEY]);
			else // do demo validation
				valid = ValidateKey(SecretWord, AccountSID, "1", details[CheckoutKeys.Amount], details[KEY]);

			// key validation failed
			if (!valid)
				throw new ArgumentException(KEY_VALIDATION_FAILED_MSG);
			// we are succeed copy order number
			result.TransactionId = order_number;
			//
			result.Succeed = true;
			// return result
			return result;
		}