/**
* An endpoint that accepts XML in request body.
*
* Description of the endpoint.
*
* @request-body string
* @request-header Content-Type {type: 'application/xml'}
*/
public function process(): array
{
$xml = simplexml_load_string(file_get_contents('php://input'));
if (! $xml) {
return ['error' => 'Invalid XML'];
}
return array_map(function ($order) {
$amount = (float) $order->amount;
return [
'customer' => $order->customer,
'amount' => $amount,
'points' => $amount > 1000 ? 10 : 1,
];
}, (array) $xml->order);
}