This is a big question to ask, definitely not a "small change" as you put it. Likely you won't get a full answer in a place like this. But what I can do is give you some resources to seek out further.
These solutions are based on native Magento invoicing functionality. I don't know much about your custom solution for invoice receipts, but starting from these should inspire you to find the answer to your scenario.
Option A: Minimum Development
Try a popular app connector service like Zapier. I put together a quick template, as shown below:
Where here you configure an available Magento trigger, like order invoice generation. Then, you bind that trigger to an action like Google Drive file upload.
- Easy setup
- No coding involved
- You have to develop the invoice template yourself
- You are limited in available data to use in the template
Option B: Custom Development
This is not an easy solution. You should know that Google's APIs use the OAuth 2 specification for authorizing connections to its services. In this case, that won't do. So instead you can look to using the service account approach:
Then, there is a PHP SDK for Google Drive:
Download and use version/tag 1.1.8. This one is old, but uses PSR-0 standards, which in short means you just to place the repo's
src/Google folder into your Magento project under
lib/Google, and all classes will autoload. With this library installed, you can start to experiment with building a Magento module to do your work.
As I see it, your task looks something like this:
- Build a new module
- Register an observer on event
- Build observer class to receive event data
- Build an API connector to upload contents to Google Drive as files
- Connect observer class event data to your API connector
- Use built-in PDF generation to create raw PDF contents
- Send PDF contents to Google Drive using your API connector
I have written an example class for step #5 above so that you can get an idea of how to bridge Magento invoice generation to a Google Drive upload interface:
const APP_NAME = '';
const CLIENT_ID = 'YOUR_SERVICE_ACCOUNT_CLIENT_ID_HERE';
const SERVICE_ID = 'account@XXXXXXXX.iam.gserviceaccount.com';
const TARGET_OWNER = 'YOUR_DRIVE_ACCOUNT_EMAIL_ADDRESS';
protected function _construct()
$this->_client = new Google_Client();
$this->_service = new Google_Service_Drive($this->_client);
protected function _getCredentials()
return new Google_Auth_AssertionCredentials(
Mage::getModuleDir('etc', 'Vbuck_DriveIntegrationTest') . DS . 'auth.p12'
protected function _getFile($name)
$file = new Google_Service_Drive_DriveFile();
protected function _getPermissions()
$permission = new Google_Service_Drive_Permission();
public function generatePdfStream(Mage_Sales_Model_Order_Invoice $invoice)
/* @var $renderer Mage_Sales_Model_Order_Pdf_Invoice */
$renderer = Mage::getSingleton('sales/order_pdf_invoice');
/* @var $document Zend_Pdf */
$document = $renderer->getPdf(array($invoice));
public function writeFile($name, $contents)
$file = $this->_getFile($name);
$result = $this->_service->files->create(
'data' => $contents,
'mimeType' => 'application/pdf',
'uploadType' => 'multipart'
public function syncInvoice(Mage_Sales_Model_Order_Invoice $invoice)
I also tested this to make sure it works by following the steps I laid out in this sample class. I was able to upload an invoice PDF to my personal Drive account in the exact same format as what Magento sends out to customers natively.
Here is the sample code I wrote to use the above class:
$model = new Vbuck_DriveIntegrationTest_Model_Upload();
$invoice = Mage::getModel('sales/order_invoice')->load(1);
$result = $model->syncInvoice($invoice);
If you use the class I wrote, you must edit the constant properties at the top of the class to match your service account credentials, which can be found here after defining a service account and enabling the Drive API:
When you setup a service account, you will be asked how you wish to download your OAuth credentials file. Choose the legacy format, P12, since we are using an older PHP SDK and that is the format required. When you download the file, save it to your module's
etc folder, as
auth.json. So using my sample code above, my auth file would be saved to:
This will allow the class method
_getCredentials I wrote above to locate it.
- Complete control over PDF upload process
- Hard to build
- Lots of integration steps
- Maintenance debt
Give either of these a try. Hopefully you can figure it out from here.