It's a little complicated... the best thing to do is probably look at the code for user upgrades and just look to see how they are handled. If it's something else you want to make "purchaseable", you have a class that defines that. As an example, the Purchasable class for user upgrade is XF\Purchaseable\UserUpgrade
.
To actually purchase it, you create a purchase request (see the xf_purchase_request
table) to setup the order (which user is buying, what they are buying, the pricing, etc.) and then you pass that (and sometimes the user, depending on the processor) to the payment processor and allow the payment to be made. Once the payment is made, you get notified via IPN (in the case of PayPal) or webhooks for some others that the payment was made. It looks up the payment request, validates things to make sure it's all valid and credits whatever needs to be credited.
I know it's a very general/abstract explanation, but maybe that at least sets you down the right path...