I direct you to the authorize.net module for an example

/includes/modules/payment/authorizenet_aim.php