Example #1
0
		public async Task<PreauthResponse> PreauthAsync(PreauthRequest request)
		{
			var requestMessage = new PaymentRequestMessage();
			var transaction = requestMessage.Payment.PaymentList.Transaction;
			transaction.TransactionType = PaymentTransactionType.Preauthorise;
			transaction.TransactionSource = PaymentTransactionSource.Xml;
			transaction.PurchaseOrderNumber = request.PurchaseOrder;
			transaction.Amount = request.Amount;
			transaction.Currency = request.Currency;
			transaction.CreditCardInfo = new CreditCardInfo {
				CardNumber = request.CreditCard.CardNumber,
				Cvv = request.CreditCard.Cvv,
				ExpiryDate = request.CreditCard.Expires.ToSecurePayString(),
			};

			var responseMessage = await PostAsync<PaymentRequestMessage, PaymentResponseMessage>(requestMessage);
			transaction = responseMessage.Payment.PaymentList.Transaction;

			var response = new PreauthResponse {
				Approved = transaction.Approved == "Yes",
				PurchaseOrder = transaction.PurchaseOrderNumber,
				ResponseCode = transaction.ResponseCode,
				ResponseText = transaction.ReponseText,
				Amount = transaction.Amount,
				Currency = transaction.Currency,
				TransactionId = transaction.TransactionId,
				PreauthId = transaction.PreauthId,
				SettlementDate = DateUtils.ParseYyyymmdd(transaction.SettlementDate),
			};

			if (transaction.CreditCardInfo != null) {
				response.CreditCard = new CreditCardResponse {
					Expires = new YearMonth(transaction.CreditCardInfo.ExpiryDate),
					TruncatedCardNumber = transaction.CreditCardInfo.TruncatedCreditCardNumber,
					CardDescription = transaction.CreditCardInfo.CardDescription,
				};
			}

			return response;
		}
Example #2
0
		private async Task<PreauthResponse> Preauth(bool expectSuccess = true)
		{
			var request = new PreauthRequest {
				Amount = PaymentAmount,
				PurchaseOrder = PurchaseOrder,
				CreditCard = new CreditCardRequest {
					CardNumber = CardNumber,
					Expires = Expires,
					Cvv = Ccv,
				}
			};

			try {
				var response = await Client.PreauthAsync(request);
				Assert.AreEqual(expectSuccess, response.Approved);
				return response;
			}
			catch {
				LogMessages();
				throw;
			}
		}