- Home
- All APIs
- Worldpay Online Payments Guide
- Making Payments!
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, check
To make a payment, you need to have already collected the customer’s card details and received a token from Worldpay either using
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 our
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 key
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 of
curl https://api.worldpay.com/v1/orders
-H "Authorization:your-test-service-key"
-H "Content-type: application/json"
-X POST
-d '{
"token" : "your-order-token",
"orderDescription" : "your-order-description",
"amount" : 500,
"currencyCode" : "GBP" }'
The response to this call will include the following JSON object:
{
"orderCode":"worldpay-generated-order-code",
"token":"your-order-token",
"orderDescription":"your-order-description",
"amount":500,
"currencyCode":"GBP",
"paymentStatus":"SUCCESS",
"paymentResponse":
{
"type":"ObfuscatedCard",
"name":"name-of-shopper",
"expiryMonth":"7",
"expiryYear":"2018",
"cardType":"VISA",
"maskedCardNumber":"**** **** **** 1111" },
"environment":"TEST"
}
$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 = Worldpay.new('your-test-service-key')
begin
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']
else
raise response.to_s
end
rescue Exception => e
print e.to_s
end
WorldpayRestClient restClient = new WorldpayRestClient("https://api.worldpay.com/v1", "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.setToken("your-order-token");
orderRequest.setAmount(500);
orderRequest.setCurrencyCode(CurrencyCode.GBP);
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.setCity("London");
address.setCountryCode(CountryCode.GB);
address.setPostalCode("EC1 1AA");
orderRequest.setBillingAddress(address);
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, no
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 the
You have now successfully made your first payment!