Making Payments!

This guide explains how to charge your customer by making a payment from your server.

For information about which payment types can be combined, checkhere.

To make a payment, you need to have already collected the customer’s card details and received a token from Worldpay either usingyour own formor thetemplate form.

At this stage all you need to do is to send Worldpay the token, plus details of the amount and currency, and a description of the order. The code examples below show you how to do this using ourCode Libraries.

A key part of this process involves re-identifying yourself to the Worldpay servers, this time using the service key. In order to maximise security, this is a different key from the client key (which is used when taking card details). You can find your service keyhere.

We recommend that, when creating an order, you also send us the billingAddress and deliveryAddress. This information is not mandatory but it will limit the effectiveness ofAddress Verificationwhen it is switched on in yourrisk settings, and for other important functions in our fraud detection service. How to send these fields is explained in theAPI Reference.

-H "Authorization:your-test-service-key" 
-H "Content-type: application/json" 
-d '{ 
    "token" : "your-order-token", 
    "orderDescription" : "your-order-description", 
    "amount" : 500, 
    "currencyCode" : "GBP" }' 

The response to this call will include the following JSON object:

        "maskedCardNumber":"**** **** **** 1111" }, 
$worldpay = new Worldpay('your-test-service-key');

$billing_address = array(
    "address1"=>'123 House Road',
    "address2"=> 'A village',
    "address3"=> '',
    "postalCode"=> 'EC1 1AA',
    "city"=> 'London',
    "state"=> '',
    "countryCode"=> 'GB',

try {
    $response = $worldpay->createOrder(array(
        'token' => 'your-order-token',
        'amount' => 500,
        'currencyCode' => 'GBP',
        'name' => 'test name',
        'billingAddress' => $billing_address,
        'orderDescription' => 'Order description',
        'customerOrderCode' => 'Order code'
    if ($response['paymentStatus'] === 'SUCCESS') {
        $worldpayOrderCode = $response['orderCode'];
    } else {
        throw new WorldpayException(print_r($response, true));
} 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();
worldpay ='your-test-service-key')


    billingAddress = {
        "address1"=>'123 House Road',
        "address2"=> 'A village',
        "address3"=> '',
        "postalCode"=> 'EC1 1AA',
        "city"=> 'London',
        "state"=> '',
        "countryCode"=> 'GB'

    response = worldpay.createOrder({
        'token' => 'your-order-token',
        'amount' => 500,
        'currencyCode' => 'GBP',
        'name' => 'test name',
        'billingAddress' => billingAddress,
        'orderDescription' => 'Order description',
        'customerOrderCode' => 'Order code'

    if (response['body']['paymentStatus'] === 'SUCCESS')
        @_worldpayOrderCode = response['body']['orderCode']
        raise response.to_s
rescue Exception => e
    print e.to_s
WorldpayRestClient restClient = new WorldpayRestClient("", "YOUR_SERVICE_KEY");

var orderRequest = new OrderRequest()
    token = "your-order-token",
    amount = 500,
    currencyCode = CurrencyCode.GBP,
    name = "test name",
    orderDescription = "Order description",
    customerOrderCode = "Order code"

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

orderRequest.billingAddress = address;

try {
    OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);
    Console.WriteLine("Order code: " + orderResponse.orderCode);
} catch (WorldpayException e) {
    Console.WriteLine("Error code:" + e.apiError.customCode);
    Console.WriteLine("Error description: " + e.apiError.description);
    Console.WriteLine("Error message: " + e.apiError.message);
WorldpayRestClient restClient = new WorldpayRestClient("your-test-service-key");

OrderRequest orderRequest = new OrderRequest();
orderRequest.setName("test name");
orderRequest.setOrderDescription("Order description");
orderRequest.setCustomerOrderCode("Order code");

Address address = new Address();
address.setAddress1("123 House Road");
address.setAddress2("A village");
address.setPostalCode("EC1 1AA");

try {
    OrderResponse orderResponse = restClient.getOrderService().create(orderRequest);
    System.out.println("Order code: " + orderResponse.getOrderCode());
} catch (WorldpayException e) {
    System.out.println("Error code: " + e.getApiError().getCustomCode());
    System.out.println("Error description: " + e.getApiError().getDescription());
    System.out.println("Error message: " + e.getApiError().getMessage());

In this example, nosettlement currencyis specified. Specifying a settlement currency is only required if you have enabled multiple settlement currencies in yourcurrency settings(this setting is only available when you have activated your account). How to specify the settlement currency when making the payment is explained in ourAPI reference.

When the payment has been successfully completed, you will see in the response that the paymentStatus shows as SUCCESS. A full list of payment states is described in theAPI Reference.

You have now successfully made your first payment!

Suggested next steps: