Remove/Delete reusable token from world pay payment integration

260 views Asked by At

I have created order in world pay using API which return my reusable token. I am using this reusable token to do any next payment for the same order in future. I would like to delete the token now so that user can no longer use it. I have written below C# code to create order and capture the reusable token. can someone know how do i delete reusable token?

       WorldpayRestClient restClient = new WorldpayRestClient("https://api.worldpay.com/v1", "Key");

        var orderRequest = new OrderRequest()
        {
            token = token,
            amount = 200,
            //authorizedAmount=20,
            currencyCode = CurrencyCode.GBP.ToString(),
            name = "Laptop",
            orderDescription = "Laptop description",
            customerOrderCode = "ordercode_01",
        };

        var address = new Address()
        {
            address1 = "123 House Road",
            address2 = "A village",
            city = "London",
            countryCode = CountryCode.GB.ToString(),
            postalCode = "EC1 1AA"
        };

        orderRequest.billingAddress = address;

        try
        {
            OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);

            string token = orderResponse.token;

            Console.WriteLine("Order code: " + orderResponse.orderCode);
        }
        catch (WorldpayException error)
        {
            Console.WriteLine("Error code:" + error.apiError.customCode);
            Console.WriteLine("Error description: " + error.apiError.description);
            Console.WriteLine("Error message: " + error.apiError.message);
        }

any help would be appreciated.

1

There are 1 answers

2
Karan On

It seems that delete token method is not implemented by WorldpayRestClient which is third party extension. Create your own delete-token request like below. I have taken xxxx just for example. Please set your actual token there. Also verify url.

You need to add headers as shown below. Please add appropriate value in it. Check this for more detail about values

This is an example how you can make DELETE web request.

string token = "xxxxx";
string sURL = "https://api.worldpay.com/v1/tokens/" + token;

WebRequest request = WebRequest.Create(sURL);
request.Method = "DELETE";
request.Headers.Add("Authorization", "your_credentials");
request.Headers.Add("Accept", "application/vnd.worldpay.tokens-v1.hal+json");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();