public function processPayment(Payment $payment)
    {
        $response = $this->postRequest('/api-payment/create', $payment->toJson());

        if ( ! in_array('application/json', $response->getHeader('Content-Type'))) {
            throw new PaymentFailed('Server returned a non-JSON result.');
        }

        $body = json_decode((string)$response->getBody());

        if ($response->getStatusCode() !== 201) {
            throw new PaymentFailed(
                sprintf('Paytrail request failed: %s (%d)', $body->errorMessage, $body->errorCode)
            );
        }

        $result = new Result;
        $result->configure(
            array(
                'orderNumber' => $body->orderNumber,
                'token'       => $body->token,
                'url'         => $body->url,
            )
        );

        return $result;
    }