/// <summary> /// Gets a dictionary of form key / values that should be submitted to the payment provider. /// </summary> /// <param name="variables">The transaction variables.</param> /// <returns>A dictionary of form key / values that should be submitted to the payment provider.</returns> public override Dictionary<string, string> GetTransactionRequest(TransactionVariables variables) { this.FormData["EPS_AMOUNT"] = variables.TransactionAmount.ToString("F2"); this.FormData["EPS_REFERENCEID"] = variables.TransactionReference; this.FormData["EPS_TIMESTAMP"] = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss"); this.FormData["EPS_FINGERPRINT"] = string.Format( "{0}|{1}|{2}|{3}|{4}|{5}", this.FormData["EPS_MERCHANT"], variables.MerchantPassword, this.FormData["EPS_TXNTYPE"], this.FormData["EPS_REFERENCEID"], this.FormData["EPS_AMOUNT"], this.FormData["EPS_TIMESTAMP"]).ToSha1Hash(); return this.FormData; }
/// <summary> /// Sets the properties of a <see cref="SecurePayTransactionResponse"/> object /// based on the parameters of a <see cref="HttpRequest"/> object. /// </summary> /// <param name="httpRequest">A <see cref="HttpRequest"/> object to read from.</param> /// <param name="securePayResponse">A <see cref="SecurePayTransactionResponse"/> object to write to.</param> /// <param name="variables">The transaction variables.</param> /// <exception cref="SecurityException"> /// The returned fingerprint value does not match the expected value. /// </exception> public void Convert(HttpRequest httpRequest, SecurePayTransactionResponse securePayResponse, TransactionVariables variables) { string merchantId = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.MERCHANT_ID); string referenceId = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.REFERENCE_ID); string timestamp = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.TIMESTAMP); string summaryCode = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.SUMMARY_CODE); string fingerprint = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.FINGERPRINT); string localFingerprint = string.Format( "{0}|{1}|{2}|{3}|{4}|{5}", merchantId, variables.MerchantPassword, referenceId, variables.TransactionAmount.ToString("F2"), timestamp, summaryCode).ToSha1Hash(); if (!localFingerprint.Equals(fingerprint)) { throw new SecurityException("Invalid fingerprint."); } securePayResponse.TransactionResult = !string.IsNullOrEmpty(summaryCode) ? (SecurePayTransactionResult)Enum.Parse(typeof(SecurePayTransactionResult), summaryCode) : SecurePayTransactionResult.Unknown; securePayResponse.SummaryCode = summaryCode; securePayResponse.ResponseCode = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.RESPONSE_CODE); securePayResponse.ResponseText = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.RESPONSE_TEXT); securePayResponse.ReferenceId = referenceId; securePayResponse.TransactionId = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.TRANSACTION_ID); securePayResponse.Amount = variables.TransactionAmount; string settlementDatestamp = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.SETTLEMENT_DATE); if (!string.IsNullOrEmpty(settlementDatestamp)) { securePayResponse.SettlementDate = new DateTime( System.Convert.ToInt32(settlementDatestamp.Substring(0, 4)), System.Convert.ToInt32(settlementDatestamp.Substring(4, 2)), System.Convert.ToInt32(settlementDatestamp.Substring(6, 2))); } securePayResponse.PreAuthorisationId = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.PREAUTHORISATION_ID); securePayResponse.ExpiryDate = this.RequestParamNullGuard(httpRequest, SecurePayConstants.Result.EXPIRY_DATE); securePayResponse.MerchantId = merchantId; securePayResponse.Timestamp = timestamp; }