Tom Christian Posted January 18, 2015 Posted January 18, 2015 I'm trying to build a plugin so that whenever an invoice is generated or updated some data is sent to a 3rd-party service.Extending the \IPS\nexus\Invoice class and save() method seems to be what I need.My question - The 3rd-party service I'm integrating has a nice PHP wrapper to help structure their XML requests from a php array structure. The wrapper is split into three .php files. What is the best way of integrating this into a plugin? Where can I store these files and how do I load them? I'm aware of the autoloader but I'm not confident of how exactly it works.Thanks
Ryan H. Posted January 18, 2015 Posted January 18, 2015 There's a brief section on libraries at the bottom of the autoloader doc: http://community.invisionpower.com/4docs/advanced-usage/development/the-autoloader-r75/
Tom Christian Posted January 18, 2015 Author Posted January 18, 2015 There's a brief section on libraries at the bottom of the autoloader doc: http://community.invisionpower.com/4docs/advanced-usage/development/the-autoloader-r75/Thanks.And if the library doesn't follow the PSR-0 standard and we have to manually load it, does that mean literally pasting the source files into a hook?
Farcaster II Posted January 18, 2015 Posted January 18, 2015 or use the good old "require_once" function
Tom Christian Posted January 18, 2015 Author Posted January 18, 2015 or use the good old "require_once" functionOf course, will try that.
Tom Christian Posted January 18, 2015 Author Posted January 18, 2015 or use the good old "require_once" functionAnd using the psr0 method: eg:\IPS\IPS::$PSR0Namespaces['FreshBooksApi'] = \IPS\ROOT_PATH . '/plugins/commerceTests/Freshbooks/FreshBooksApi';How would I then call that inside a hook? Everything I try returns a class not found error.
Mark Posted January 19, 2015 Posted January 19, 2015 And using the psr0 method: eg:\IPS\IPS::$PSR0Namespaces['FreshBooksApi'] = \IPS\ROOT_PATH . '/plugins/commerceTests/Freshbooks/FreshBooksApi';How would I then call that inside a hook? Everything I try returns a class not found error. Are the classnames \FreshBooksApi\Class? If so, that should work fine.Though you can't distribute files in the plugins directory (since they're created dynamically), you'd need to put them somewhere else. /system/3rd_party/ is probably a good place.
Tom Christian Posted January 19, 2015 Author Posted January 19, 2015 Are the classnames \FreshBooksApi\Class? If so, that should work fine.Though you can't distribute files in the plugins directory (since they're created dynamically), you'd need to put them somewhere else. /system/3rd_party/ is probably a good place.This is the library I'm using. Should that work alright?
Mark Posted January 20, 2015 Posted January 20, 2015 \IPS\IPS::$PSR0Namespaces['Freshbooks'] = \IPS\ROOT_PATH . '/plugins/commerceTests/Freshbooks';
Tom Christian Posted January 21, 2015 Author Posted January 21, 2015 \IPS\IPS::$PSR0Namespaces['Freshbooks'] = \IPS\ROOT_PATH . '/plugins/commerceTests/Freshbooks';Mark, when creating an invoice, is it possible for me to store some additional data? Before creating the invoice, my plugin sends the invoice data to Freshbooks which responds with an invoice_id. I need to store that ID so that any future invoice updates within Commerce can also be applied over to freshbooks.
Mark Posted January 22, 2015 Posted January 22, 2015 Sure, you could add a column to the invoices table in the database, or create your own map table.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.