I have to write a payment module for a new gateway. I am trying to find an already existing module which works more or less through the same kind of mechanism (see below). If someone can point me in the right direction, I'd be very happy.

So here is how it works:
1. When the client clicks to proceed to the payment, an XML file has to be generated with informations regarding the order (price, order_id), plus some merchant's specific data (id, customization...).
2. The XML file is processed by a small executable (provided with the gateway's SDK) that connects to the gateway to do some pre-check and obtain a token for the transaction.
3. If this is OK (i.e. the transaction can continue), another XML file is created containing an external address (including the token) that I have to read to redirect the client's browser to the Gateway's Secure Site
--- At this point, we can simplify the above by: for payment, redirect the user to a specific page while passing on some parameters ---
4. On the Gateway Site, the user proceeds to payment via credit card.
5. Upon payment success, the user is redirected by the gateway to my site to a payment_succes page that I have to create (?), passing along informations about the transaction. In case of error, he is redirected to a payment_error page (payment_success and payment_error are pages that I define in the XML file created at point 1).

So, does anybody know something close to this, that is redirection of the client to an external payment then comeback to the site upon success? I have already checked the code of some payment modules, but they most have the user input its CC details into the site, then ship it to the gateway. Paypal module seems to work this way but looks kind of complicated...