Menu

Getting token details

Getting token details

Example request

Copied!
curl https://api.worldpay.com/v1/tokens/[your token] 
-H "Authorization:your-service-key"
-H "Content-type: application/json" 
-X GET
try {
    $cardDetails = $worldpay->getStoredCardDetails('your-reusable-token');

    $name = $cardDetails['name'];
    $expiryMonth = $cardDetails['expiryMonth'];
    $expiryYear = $cardDetails['expiryYear'];
    $cardType = $cardDetails['cardType'];
    $maskedCardNumber = $cardDetails['maskedCardNumber'];

} catch (WorldpayException $e) {
    echo 'Error code: ' . $e->getCustomCode() . '

    HTTP status code:' . $e->getHttpStatusCode() . '

    Error description: ' . $e->getDescription()  . '

    Error message: ' . $e->getMessage();
} catch (Exception $e) {
    echo 'Error message: '. $e->getMessage();
}
WorldpayRestClient restClient = new WorldpayRestClient("your-test-service-key");

try {
    TokenResponse tokenResponse = restClient.getTokenService().get("your-reusable-token");
    CardResponse cardResponse = (CardResponse) tokenResponse.getPaymentMethod();

    System.out.println("Name: " + tokenResponse.getPaymentMethod().getName());
    System.out.println("Expiry Month: " + cardResponse.getExpiryMonth());
    System.out.println("Expiry Year: " + cardResponse.getExpiryYear());
    System.out.println("Card Type: " + cardResponse.getCardType());
    System.out.println("Masked Card Number: " + cardResponse.getMaskedCardNumber());
} catch (WorldpayException e) {
    System.out.println("Error code: " + e.getError().getCustomCode());
    System.out.println("Error description: " + e.getError().getDescription());
    System.out.println("Error message: " + e.getError().getMessage());
}
worldpay = Worldpay.new('your-test-service-key')

begin

  response = worldpay.getStoredCardDetails('your-reusable-token')

  if (response.class.to_s=="Hash")
    puts "Name: " + response['name']
    puts "Expiry Month: " + response['expiryMonth'].to_s
    puts "Expiry Year: " + response['expiryYear'].to_s
    puts "Card Type: " + response['cardType']
    puts "Masked Card Number: " + response['maskedCardNumber']
  else
    puts "There was a problem"
  end

rescue Exception => e
  raise e
end
WorldpayRestClient restClient = new WorldpayRestClient("https://api.worldpay.com/v1", "your-test-service-key");
try
{
    TokenResponse cardDetails = restClient.GetTokenService().Get("your-reusable-token");

    Console.WriteLine("Name: " + cardDetails.paymentMethod.name);
    Console.WriteLine("ExpiryMonth: " + cardDetails.paymentMethod.expiryMonth);
    Console.WriteLine("ExpiryYear: " + cardDetails.paymentMethod.expiryYear);
    Console.WriteLine("CardType: " + cardDetails.paymentMethod.cardType);
    Console.WriteLine("MaskedCardNumber: " + cardDetails.paymentMethod.maskedCardNumber);
}
catch (WorldpayException e)
{
    Console.WriteLine("Error code:" + e.apiError.customCode);
    Console.WriteLine("Error description: " + e.apiError.description);
    Console.WriteLine("Error message: " + e.apiError.message);
}

Token details can be obtained by sending a get request.