internal static RefundRequest refundRequest(string paymentScenario, string currency, string amount,
                                              string token, string cardNumber, string expiryDateMMYY,
                                              string cardVerificationCode, string customerReference, string paymentGuid)
        {
            RefundRequest refundRequest = new RefundRequest();
            refundRequest.PaymentGuid = paymentGuid;
            refundRequest.PaymentScenario = paymentScenario;
            refundRequest.Currency = currency;
            refundRequest.Amount = amount;
            refundRequest.Token = token;
            refundRequest.CardNumber = cardNumber;
            refundRequest.ExpiryDateMMYY = expiryDateMMYY;
            refundRequest.CustomerReference = customerReference;
            string validationErrors = validateRefundRequest(refundRequest);
            if (validationErrors != null)
            {
                throw new HpECommerceException("Message failed validation \n" + validationErrors);
            }

            return refundRequest;
        }
Ejemplo n.º 2
0
 internal HpEcommerce.messages.Refund sendRefundRequest(RefundRequest request)
 {
     HttpWebResponse response = client.sendPostRequest(UrlGenerator.getRefundUrl(CardAcceptor, Environment), HpXmlSerializer.getMessage(typeof(RefundRequest), request), SharedSecret);
     if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Forbidden)
     {
         return HpXmlSerializer.convertRefund(getResponsestring(response));
     }
     else
     {
         throw new HpServerError("Refund declined.", HpXmlSerializer.convertErrorMessage(getResponsestring(response)));
     }
 }
        private static string validateRefundRequest(RefundRequest request)
        {
            StringBuilder validationErrors = new StringBuilder();
            ValidateCommonFields(request, validationErrors);
            if (!isValidRefundRequest(request))
            {
                validationErrors.Append("Request has invalid card data. It must have either Card Number and Expiry date or Token");
            }

            if (validationErrors.Length == 0)
            {
                return null;
            }
            else
            {
                return validationErrors.ToString();
            }
        }
 private static bool isValidRefundRequest(RefundRequest message)
 {
     return (message.CardNumber != null && message.ExpiryDateMMYY != null) || message.Token != null || message.PaymentGuid != null;
 }