I was interested on which the best way to accept XMR programmatically and made this concept payment processor that credits PGP based accounts with the XMR amount deposited like an exchange would have with sub addresses assigned to each account.

When withdrawing, It is a lot more difficult to implement as transfer RPC call cannot auto-calculate the fee.

Workaround:

Estimate transfer is sent with no relay

transfer2 with no relay is sent after deducting fee manually.

Checks for proper deduction and then uses relay_tx for the final step.

If you have any suggestions on how to improve this, especially if you have a better architecture in mind for the withdraw/deposit functionalities.