public PaymentAuthorizationResponse(bool responseOk, PaymentAuthorizationResult response, decimal amount, string description, string receiptNumber) { ResponseOk = responseOk; AuthorizationResult = response; AmountAuthorized = amount; Description = description ?? string.Empty; ReceiptNumber = receiptNumber ?? string.Empty; }
/// <summary> /// Process payment /// </summary> /// <param name="payment"></param> /// <param name="orderGroup"></param> /// <param name="transactionId"></param> /// <returns></returns> public PaymentAuthorizationResult Process(IPayment payment, IOrderGroup orderGroup, string transactionId) { var result = new PaymentAuthorizationResult(); if (payment.TransactionType == "Authorization" && !string.IsNullOrEmpty(transactionId)) { PaymentResult paymentResult = null; try { paymentResult = this.Client.Query(transactionId); } catch (Exception ex) { Logger.Error(ex.Message); AddNoteAndSaveChanges(orderGroup, "Payment Query - Error", "Payment Query - Error: " + ex.Message); return(result); } if (paymentResult.Cancelled) { payment.Status = "Failed"; result.Result = PaymentResponseCode.Cancelled; return(result); } if (paymentResult.ErrorOccurred) { payment.Status = "Failed"; result.Result = PaymentResponseCode.ErrorOccurred; result.ErrorMessage = paymentResult.ErrorMessage; AddNoteAndSaveChanges(orderGroup, "Payment - Failed", "Payment - Error: " + result.ErrorMessage); return(result); } try { var responseResult = this.Client.Authorize(transactionId); if (responseResult.ErrorOccurred) { payment.Status = "Failed"; result.Result = PaymentResponseCode.ErrorOccurred; AddNoteAndSaveChanges(orderGroup, "Payment Auth - Error", "Payment Auth - Error: " + responseResult.ErrorMessage); return(result); } } catch (Exception ex) { payment.Status = "Failed"; result.Result = PaymentResponseCode.ErrorOccurred; result.ErrorMessage = ex.Message; Logger.Error(ex.Message); AddNoteAndSaveChanges(orderGroup, "Payment Auth - Error", "Payment Auth - Error: " + result.ErrorMessage); return(result); } payment.TransactionID = transactionId; payment.ProviderTransactionID = transactionId; payment.Properties[NetaxeptConstants.CardInformationPaymentMethodField] = paymentResult.CardInformationPaymentMethod; payment.Properties[NetaxeptConstants.CardInformationExpiryDateField] = paymentResult.CardInformationExpiryDate; payment.Properties[NetaxeptConstants.CardInformationIssuerCountryField] = paymentResult.CardInformationIssuerCountry; payment.Properties[NetaxeptConstants.CardInformationIssuerField] = paymentResult.CardInformationIssuer; payment.Properties[NetaxeptConstants.CardInformationIssuerIdField] = paymentResult.CardInformationIssuerId; payment.Properties[NetaxeptConstants.CardInformationMaskedPanField] = paymentResult.CardInformationMaskedPan; // Save the PanHash(if not empty) on the customer contact, so we can use EasyPayment for next payment if (!string.IsNullOrEmpty(paymentResult.CardInformationPanHash) && orderGroup.CustomerId != Guid.Empty) { var customerContact = CustomerContext.Current.GetContactById(orderGroup.CustomerId); if (customerContact != null) { customerContact[NetaxeptConstants.CustomerPanHashFieldName] = paymentResult.CardInformationPanHash; customerContact[NetaxeptConstants.CustomerCardMaskedFieldName] = paymentResult.CardInformationMaskedPan; customerContact[NetaxeptConstants.CustomerCardExpirationDateFieldName] = paymentResult.CardInformationExpiryDate; customerContact[NetaxeptConstants.CustomerCardPaymentMethodFieldName] = paymentResult.CardInformationPaymentMethod; customerContact[NetaxeptConstants.CustomerCardIssuerCountryFieldName] = paymentResult.CardInformationIssuerCountry; customerContact[NetaxeptConstants.CustomerCardIssuerIdFieldName] = paymentResult.CardInformationIssuerId; customerContact[NetaxeptConstants.CustomerCardIssuerFieldName] = paymentResult.CardInformationIssuer; customerContact.SaveChanges(); } } result.Result = PaymentResponseCode.Success; AddNoteAndSaveChanges(orderGroup, "Payment - Auth", "Payment - Auth"); } return(result); }
public Task <PaymentAuthorizationGuiResponse> ProcessResponse( PaymentProviderConfiguration configuration, NameValueCollection paramsCollection, ResponseParameters additionalParameters) { string timestamp = paramsCollection[RealexFields.RealexFieldTimestamp]; string merchantid = paramsCollection[RealexFields.RealexFieldMerchantId]; string orderid = paramsCollection[RealexFields.RealexFieldOrderId]; string authcode = paramsCollection[RealexFields.RealexFieldAuthCode]; string resultCode = paramsCollection[RealexFields.RealexFieldResult]; string textmsg = paramsCollection[RealexFields.RealexFieldResponseTextMessage]; string receiptNumber = paramsCollection[RealexFields.RealexFieldPasRef]; string responseSignature = paramsCollection[RealexFields.RealexFieldHashSignature]; string amountString = paramsCollection[RealexFields.RealexFieldAmount]; string[] fieldsForResponseSignature = new string[] { timestamp, merchantid, orderid, resultCode, textmsg, receiptNumber, // PASREF authcode }; string expectedResponseHash = CalculateRealexSignature(fieldsForResponseSignature, configuration.SharedSecret); decimal amount; if (decimal.TryParse(amountString, out amount)) { amount = amount / 100m; } else { amount = 0; } if (expectedResponseHash != responseSignature) { PaymentAuthorizationResponse dummyBackendResponse = new PaymentAuthorizationResponse(false, PaymentAuthorizationResult.Unknown, amount, "incorrect SHA1HASH.", receiptNumber) { ResponseCode = resultCode, TransactionId = orderid }; return(Task.FromResult(new PaymentAuthorizationGuiResponse(dummyBackendResponse, null))); } PaymentAuthorizationResult isAuthorized = IsResponseCodeSuccess(resultCode) ? PaymentAuthorizationResult.Authorized : PaymentAuthorizationResult.Declined; var savedCardResponse = new SavedCardResponse(); if (!string.IsNullOrEmpty(paramsCollection[RealVaultFields.ResponsePayerSetupResultCode]) && paramsCollection[RealVaultFields.ResponsePayerSetupResultCode] == "00") { savedCardResponse.NewCardholderSaved = true; } if (!string.IsNullOrEmpty(paramsCollection[RealVaultFields.ResponseSavedPayerRef])) { savedCardResponse.CardholderReference = paramsCollection[RealVaultFields.ResponseSavedPayerRef]; } if (!string.IsNullOrEmpty(paramsCollection[RealVaultFields.ResponseSavedCardResultCode])) { if (IsResponseCodeSuccess(paramsCollection[RealVaultFields.ResponseSavedCardResultCode])) { savedCardResponse.CardSaved = true; savedCardResponse.CardReference = paramsCollection[RealVaultFields.ResponseSavedCardRef]; savedCardResponse.CardDigits = paramsCollection[RealVaultFields.ResponseMaskedCardDigits]; savedCardResponse.ExpiryDate = Utility.ParseExpiryDate(paramsCollection[RealVaultFields.ResponseSavedCardExpiryDate]); } else { savedCardResponse.CardSaved = false; savedCardResponse.CardSaveStatus = paramsCollection[RealVaultFields.ResponseSavedCardResultMessage]; } } PaymentAuthorizationResponse response = new PaymentAuthorizationResponse( IsResponseCodeSuccess(resultCode), isAuthorized, amount, textmsg, receiptNumber) { ResponseCode = resultCode, TransactionId = orderid, SavedCard = savedCardResponse }; var realExResponse = new RealExServerResponse(); StringBuilder displayText = new StringBuilder(); if (!response.ResponseOk) { realExResponse.ImagePath = additionalParameters.FailureImageUrl; realExResponse.ConfigDescription = "Payment failed"; displayText.Append("There was an error while processing your payment.<br />Please contact <a href=\"mailto:[email protected]\">My Play Service Support</a><br />"); displayText.AppendFormat($"ERROR DETAILS : {textmsg}"); } else { // TODO: show AUTHCODE to user (a legal requirement?) and an absolute hyperlink back in to the ebooking application realExResponse.ConfigDescription = "Payment Success"; displayText.AppendFormat($"Payment Reference Number = {response.ReceiptNumber}<br />"); displayText.AppendFormat($"Amount Paid = {response.AmountAuthorized:c}<br />"); displayText.AppendFormat("Booking Reference Number {0}<br />", additionalParameters.Reference); displayText.AppendFormat("A confirmation email will be sent shortly with all details and invoice"); realExResponse.ImagePath = additionalParameters.SuccessImageUrl; realExResponse.AdditionalSuccessMessage = additionalParameters.AdditionalSuccessMessage; } realExResponse.MainResult = displayText.ToString(); realExResponse.NextUrl = additionalParameters.NextUrl; PartialViewResult serverReply = PaymentFrameworkUtility.CreatePartialView("~/Views/Payment/ReplyToRealEx.cshtml", realExResponse); PaymentAuthorizationGuiResponse guiResponse = new PaymentAuthorizationGuiResponse(response, serverReply); return(Task.FromResult <PaymentAuthorizationGuiResponse>(guiResponse)); }