Пример #1
0
		public PaymentResult Pay(CreditCardInfo info, int orderId)
		{
			Func<IGateway> openGateway = () => new Gateway(_authorizeSettings.AuthorizationApiLogin, _authorizeSettings.AuthorizationTransactionKey, _authorizeSettings.IsAuthorizationTestMode);
			var gateway = openGateway();
			var apiRequest = new AuthorizationRequest(info.CreditCardNumber, info.ExpirationDate.ToString(ExpirationDateFormat), info.Amount, "Direct Valuation Solutions, Inc.");

			apiRequest.FirstName = info.FirstName;
			apiRequest.LastName = info.LastName;
			apiRequest.Address = info.StreetAddress;
			apiRequest.City = info.City;
			apiRequest.State = info.State;
			apiRequest.Zip = info.ZIP;
			apiRequest.CardCode = info.CVVCSCCode;

			Logger.WriteInfo(String.Format("Payment started. OrderId [{0}], UserId [{1}]", orderId, _securityContext.CurrentUser.Id));

			var response = gateway.Send(apiRequest);

			Logger.WriteInfo(String.Format("Payment completed. OrderId [{0}], UserId [{1}], amount [{2}], transactionId [{3}], ResponseCode [{4}], Approved [{5}]",
				orderId, _securityContext.CurrentUser.Id, response.Amount, response.TransactionID, response.ResponseCode, response.Approved));

			const int defaultResponseCode = 1;
			var responseCode = SafeConvert.ToInt(response.ResponseCode, defaultResponseCode);
			const int responseReasonIndex = 2;
			const int defaultResponseReasonCode = 1;
			var responseReasonCode = SafeConvert.ToInt(((ResponseBase)response).RawResponse[responseReasonIndex], defaultResponseReasonCode);

			return new PaymentResult
			{
				Message = _referenceManagement.GetAuthorizeDotNetResponseMessage(responseCode, responseReasonCode),
				IsApproved = response.Approved,
				TransactionId = response.TransactionID
			};
		}
Пример #2
0
		public PaymentResult Pay(CreditCardInfo info, int orderId)
		{
			Logger.WriteInfo(String.Format("Payment started. OrderId [{0}], UserId [{1}]", orderId, _securityContext.CurrentUser.Id));


			UserInfo user = new UserInfo(_configurationHelper.PayPalUser, _configurationHelper.PayPalVender, "PayPal", _configurationHelper.PayPalUserPassword);
			PayflowConnectionData connection = new PayflowConnectionData(_configurationHelper.PayPalUrl);

			Invoice invoice = new Invoice()
			{
				Amt = new Currency(info.Amount),
				BillTo = new BillTo()
				{
					BillToCity = info.City,
					BillToFirstName = info.FirstName,
					BillToStreet = info.StreetAddress,
					BillToZip = info.ZIP,
					BillToLastName = info.LastName,
					BillToState = info.State
				}
			};

			CreditCard creditCard = new CreditCard(info.CreditCardNumber, info.ExpirationDate.ToString("MMyy"));
			creditCard.Cvv2 = info.CVVCSCCode;
			CardTender cardTender = new CardTender(creditCard);

			SaleTransaction trans = new SaleTransaction(user, connection, invoice, cardTender, PayflowUtility.RequestId);

			// Set the transaction verbosity to HIGH to display most details.
			trans.Verbosity = "HIGH";

			// Try to submit the transaction up to 3 times with 5 second delay.  This can be used
			// in case of network issues.  The idea here is since you are posting via HTTPS behind the scenes there
			// could be general network issues, so try a few times before you tell customer there is an issue.
			int trxCount = 1;
			bool respRecd = false;
			while (trxCount <= 3 && !respRecd)
			{
				// Notice we set the request id earlier in the application and outside our loop.  This way if a response was not received
				// but PayPal processed the original request, you'll receive the original response with DUPLICATE set.

				Response resp = trans.SubmitTransaction();

				if (resp != null)
				{
					Logger.WriteInfo(String.Format("Payment completed. OrderId [{0}], UserId [{1}], requestId [{2}], Request [{3}], Response [{4}]",
							orderId, _securityContext.CurrentUser.Id, resp.RequestId, resp.RequestString, resp.ResponseString));

					respRecd = true; // Got a response.
					TransactionResponse trxnResponse = resp.TransactionResponse;

					if (trxnResponse != null)
					{
						if (trxnResponse.Result == 0)
						{
							return new PaymentResult() { IsApproved = true, TransactionId = trxnResponse.Pnref };
						}
						else
						{
							return new PaymentResult() { IsApproved = false, TransactionId = trxnResponse.Pnref, Message = trxnResponse.RespMsg };
						}
					}
				}


				Thread.Sleep(5000); // let's wait 5 seconds to see if this is a temporary network issue.
				trxCount++;
			}

			return new PaymentResult() { IsApproved = false, TransactionId = null, Message = "Time out" };
		}