There is built-in functionality for this (see https://github.com/adrianmacneil/omnipay/blob/master/src/Omnipay/Common/Message/AbstractRequest.php#L117).