private static void AssertResponse(PaymentResponseMessage <StandardPaymentResponseTxn> message) { AssertResponse((ResponseMessage)message); Assert.IsTrue(message.Payment.TxnList.Txn.IsApproved); Assert.AreEqual("00", message.Payment.TxnList.Txn.ResponseCode); Assert.AreEqual("Approved", message.Payment.TxnList.Txn.ResponseText); Assert.AreEqual(Pan, message.Payment.TxnList.Txn.CreditCardInfo.Pan); Assert.AreEqual(CreditCardType.Visa, message.Payment.TxnList.Txn.CreditCardInfo.CardType); Assert.AreEqual(CreditCardType.Visa.ToString(), message.Payment.TxnList.Txn.CreditCardInfo.CardDescription); }
private static void AssertRequestResponse(PaymentRequestMessage <StandardPaymentRequestTxn> paymentRequestMessage, PaymentResponseMessage <StandardPaymentResponseTxn> paymentResponseMessage, PaymentRequestMessage <RefundRequestTxn> requestMessage, PaymentResponseMessage <RefundResponseTxn> responseMessage) { AssertRequestResponse(requestMessage, responseMessage); Assert.AreEqual(requestMessage.MerchantInfo.MerchantId, responseMessage.MerchantInfo.MerchantId); Assert.AreEqual(requestMessage.Payment.TxnList.Txn.Amount, responseMessage.Payment.TxnList.Txn.Amount); Assert.AreEqual(paymentRequestMessage.Payment.TxnList.Txn.Currency, responseMessage.Payment.TxnList.Txn.Currency); Assert.AreEqual(paymentResponseMessage.Payment.TxnList.Txn.ExternalTransactionId, responseMessage.Payment.TxnList.Txn.PaymentExternalTransactionId); Assert.AreEqual(paymentResponseMessage.Payment.TxnList.Txn.CreditCardInfo.Pan, responseMessage.Payment.TxnList.Txn.CreditCardInfo.Pan); Assert.AreEqual(paymentResponseMessage.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate, responseMessage.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate); Assert.AreEqual(paymentResponseMessage.Payment.TxnList.Txn.CreditCardInfo.CardType, responseMessage.Payment.TxnList.Txn.CreditCardInfo.CardType); Assert.AreEqual(paymentResponseMessage.Payment.TxnList.Txn.CreditCardInfo.CardDescription, responseMessage.Payment.TxnList.Txn.CreditCardInfo.CardDescription); }
private static void AssertRequestResponse(PaymentRequestMessage <StandardPaymentRequestTxn> requestMessage, PaymentResponseMessage <StandardPaymentResponseTxn> responseMessage) { AssertRequestResponse((RequestMessage)requestMessage, responseMessage); Assert.AreEqual(requestMessage.MerchantInfo.MerchantId, responseMessage.MerchantInfo.MerchantId); Assert.AreEqual(requestMessage.Payment.TxnList.Txn.Amount, responseMessage.Payment.TxnList.Txn.Amount); Assert.AreEqual(requestMessage.Payment.TxnList.Txn.Currency, responseMessage.Payment.TxnList.Txn.Currency); Assert.AreEqual(requestMessage.Payment.TxnList.Txn.PurchaseId, responseMessage.Payment.TxnList.Txn.PurchaseId); Assert.AreEqual(requestMessage.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate, responseMessage.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate); }
private static PaymentResponseMessage <TResponseTxn> GetResponseMessage <TRequestTxn, TResponseTxn>(PaymentRequestMessage <TRequestTxn> requestMessage, PaymentResponseMessage <TResponseTxn> responseMessage) where TRequestTxn : PaymentRequestTxn, new() where TResponseTxn : PaymentResponseTxn, new() { if (typeof(TRequestTxn) == typeof(StandardPaymentRequestTxn)) { return(GetStandardResponseMessage(requestMessage as PaymentRequestMessage <StandardPaymentRequestTxn>, responseMessage as PaymentResponseMessage <StandardPaymentResponseTxn>) as PaymentResponseMessage <TResponseTxn>); } if (typeof(TRequestTxn) == typeof(AntiFraudPaymentRequestTxn)) { return(GetAntiFraudResponseMessage(requestMessage as PaymentRequestMessage <AntiFraudPaymentRequestTxn>, responseMessage as PaymentResponseMessage <AntiFraudPaymentResponseTxn>) as PaymentResponseMessage <TResponseTxn>); } return(null); }
private static PaymentResponseMessage <AntiFraudPaymentResponseTxn> GetAntiFraudResponseMessage(PaymentRequestMessage <AntiFraudPaymentRequestTxn> requestMessage, PaymentResponseMessage <AntiFraudPaymentResponseTxn> responseMessage) { responseMessage.Payment.TxnList.Txn.Amount = requestMessage.Payment.TxnList.Txn.Amount; responseMessage.Payment.TxnList.Txn.Currency = requestMessage.Payment.TxnList.Txn.Currency; responseMessage.Payment.TxnList.Txn.PurchaseId = requestMessage.Payment.TxnList.Txn.PurchaseId; responseMessage.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate = requestMessage.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate; return(responseMessage); }
public async Task <IActionResult> Index(PaymentModel paymentModel) { if (!this.ModelState.IsValid || paymentModel == null) { return(this.View()); } var token = ""; using (var httpClient = new HttpClient()) { var tokenRequest = new APIModeModel() { apiKey = paymentModel.APIKey }; StringContent content = new StringContent(JsonConvert.SerializeObject(tokenRequest), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/Token", content)) { token = await response.Content.ReadAsStringAsync(); } } var request = new PaymentRequest() { amount = new Amount() { currency = paymentModel.Currency, value = paymentModel.Amount.ToString() }, description = paymentModel.Description, locale = "DE", redirectUrl = $"{_httpContextAccessor.HttpContext.Request.Scheme}://{_httpContextAccessor.HttpContext.Request.Host.Value}/home/Success", sequenceType = 1, webhookUrl = $"{_httpContextAccessor.HttpContext.Request.Scheme}://{_httpContextAccessor.HttpContext.Request.Host.Value}/home/Success", method = 1 }; PaymentResponseMessage paymentResponseMessage = null; using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); StringContent content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync($"{_configuration.GetSection("appSettings")["PaymentAPI"]}/CreatePaymentAPI", content)) { string apiResponse = await response.Content.ReadAsStringAsync(); paymentResponseMessage = JsonConvert.DeserializeObject <PaymentResponseMessage>(apiResponse); } } if (paymentResponseMessage != null) { if (paymentResponseMessage.ErrorCode == string.Empty) { return(this.Redirect(paymentResponseMessage.PaymentResponse.CheckoutUrl)); } else { _logger.LogError(paymentResponseMessage.ErrorMessage); // Show Error return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } } return(View()); }
private static void AssertResponseMessage(MessageId messageId, MessageTimestamp messageTimestamp, int amount, Guid purchaseId, string externalTransactionId, PaymentResponseMessage <StandardPaymentResponseTxn> message) { Assert.AreEqual(messageId, message.MessageInfo.MessageId); Assert.AreEqual(messageTimestamp, message.MessageInfo.MessageTimestamp); Assert.AreEqual(ApiVersion, message.MessageInfo.ApiVersion); Assert.AreEqual(MerchantId, message.MerchantInfo.MerchantId); Assert.AreEqual(RequestType.Payment, message.RequestType); Assert.AreEqual(int.Parse(StatusCode), message.Status.StatusCode); Assert.AreEqual(StatusDescription, message.Status.StatusDescription); Assert.AreEqual(amount, message.Payment.TxnList.Txn.Amount); Assert.AreEqual(Currency.AUD, message.Payment.TxnList.Txn.Currency); Assert.AreEqual(purchaseId, message.Payment.TxnList.Txn.PurchaseId); Assert.AreEqual(true, message.Payment.TxnList.Txn.IsApproved); Assert.AreEqual(ResponseCode, message.Payment.TxnList.Txn.ResponseCode); Assert.AreEqual(ResponseText, message.Payment.TxnList.Txn.ResponseText); Assert.AreEqual(SettlementDate, message.Payment.TxnList.Txn.SettlementDate); Assert.AreEqual(externalTransactionId, message.Payment.TxnList.Txn.ExternalTransactionId); Assert.AreEqual(Pan, message.Payment.TxnList.Txn.CreditCardInfo.Pan); Assert.AreEqual(ExpiryDate, message.Payment.TxnList.Txn.CreditCardInfo.ExpiryDate); Assert.AreEqual(CreditCardType.Visa, message.Payment.TxnList.Txn.CreditCardInfo.CardType); Assert.AreEqual(CreditCardType.Visa.ToString(), message.Payment.TxnList.Txn.CreditCardInfo.CardDescription); }