Link to home
Start Free TrialLog in
Avatar of Dattu
DattuFlag for United States of America

asked on

calling extension methods and calling them in data contracts

Hi,
I have using a 3 party payment cart provided by chase.
below is a extension method. Irequest is the object provided by chase for sending them a request.
String ordernumber is anything string.

Suppose , i want to call this SetMerchantOrderNumber(this IRequest request, string orderNumber)  in another class, how do i call it. i know i have to using this class using using in class file.

also, how do i mport this into datacontracts for sending the request to chase using wcf.
using System;
using System.Collections.Generic;
using System.Linq;
using ChasePaymentech.Spectrum;
using Vertrue.Core.String;
using Vertrue.Core.PaymenTech.Exceptions;
using Vertrue.Core.PaymenTech.Extensions.CreditCardVendors;
using Vertrue.Core.PaymenTech.Interfaces;

namespace Vertrue.Core.PaymenTech.Extensions.Request
{
    public static class IRequestExtensions
    {
        /// <summary>
        /// Validates the value passed in does not contain invalid characters and sets the MerchantOrderNumber property on the request.
        /// </summary>
        /// <param name="request">Any Paymentech request.</param>
        /// <param name="orderNumber">A string value must not contaion |,^,%,\,/,[,],`,~ characters and must be less than 23 characters.</param>
        public static void SetMerchantOrderNumber(this IRequest request, string orderNumber)
        {
            if (!string.IsNullOrWhiteSpace(orderNumber))
            {
                var invalidCharacters = new HashSet<char> { '|', '^', '%', '\\', '/', '[', ']', '~', '`' };
                const int merchantOrderNumbermaxLength = 22;

                //check for invalid characters
                if (orderNumber.ToCharArray().Any(invalidCharacters.Contains))
                    throw new ArgumentContainsInvalidCharacterException("value", invalidCharacters);

                //check for invalid length
                if (!orderNumber.IsValidLength(merchantOrderNumbermaxLength))
                    throw new ArgumentToLongException("value", merchantOrderNumbermaxLength);

                //should be left aligned and padded with spaces.
                orderNumber = orderNumber.Trim().Length == 0 ? null : orderNumber.PadRight(22, ' ');
            }
            else
                orderNumber = null;

            const string merchantOrderNumberKey = "MerchantOrderNumber";
            request[merchantOrderNumberKey] = orderNumber;
        }
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dattu

ASKER

hi,
i am looking for the exact syntax, pleasee....
Irequest is an interface.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>   i am looking for the exact syntax, pleasee....


I gave you the syntax in line 3 of my post. You asked for the syntax to call an extension method, not how to declare an interface. And I stated in my post that the variable declaration was not proper.

To make the declaration proper, set it equal to a new instance of any class which implements IRequest.
Avatar of Dattu

ASKER

Sorry, it tok me so long to close this questiona and had to give points to both of you. I wish I give each of you 250 points. Sorry again for the delay.