XF 2.2 Integrating into Payment Providers

stromb0li

Well-known member
A bit of a broad ask, but are there any development docs or references that I can use for leveraging the payment providers system built into XenForo for development?

Thank you!

Edit: To clarify, I don't want to edit the payment providers, rather leverage them for processing / making a payment.
 
Last edited:
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...
 
Sorry to bubble up this thread again, but a bit lost on actually starting the purchase. I have created a new controller called Purchase and setup a route to get to it. I have the form setup in the template and see my request hit the actionIndex method of the controller, but I don't quite understand what is going on here:

PHP:
/** @var \XF\Purchasable\AbstractPurchasable $purchasableHandler */
        $purchasableHandler = $purchasable->handler;
        $purchase = $purchasableHandler->getPurchaseFromRequest($this->request, \XF::visitor(), $error);
        if (!$purchase)
        {
            throw $this->exception($this->error($error));
        }

How exactly do I create the request? I'm essentially building a mini-shopping cart, so the request would have multiple items in it, not 1:1 with a user upgrade.
 
Sorry to bubble up again, but I was able to successfully complete a purchase now for a single item, however my goal is to have multiple "line items" to the payment provider to define what is in the purchase request.

In other words, is there a way to define multiple purchasables as an array and have them aggregated as a single request to the provider?

Thank you!
 
The purchase request table has an extra_data column that allows you to store arbitrary data for whatever you need/want for your purchase request. For example it could have an array of line items and whatever info you need for those line items (amount, quantity, item id, etc.)
 
The purchase request table has an extra_data column that allows you to store arbitrary data for whatever you need/want for your purchase request. For example it could have an array of line items and whatever info you need for those line items (amount, quantity, item id, etc.)
I see the key/value pairs get stored in the purchase_request extra_data column, but it doesn't look like those are sent as-is. I'm guessing I'd have to override how the data is sent for each provider to take an array?
 
Back
Top Bottom