Example #1
0
 /**
  * Get the current customers saved cards
  *
  * @return array
  */
 public function getCustomerSavedPaymentMethods()
 {
     // Grab an instance of the customers session
     $customerSession = Mage::getSingleton('customer/session');
     // You can only store cards if you're logged in
     if ($customerSession->isLoggedIn() && $customerSession->getCustomer()->getBraintreeCustomerId()) {
         if (!$this->savedAccounts) {
             // Grab a new instance of the wrapper
             $wrapper = Mage::getModel('gene_braintree/wrapper_braintree');
             // Init the braintree wrapper
             $wrapper->init();
             // Try and load the customer from Braintrees side
             if ($customer = $wrapper->getCustomer($customerSession->getCustomer()->getBraintreeCustomerId())) {
                 // Assign them into our model
                 $object = new Varien_Object();
                 $object->setSavedAccounts(array_merge($customer->creditCards, $customer->paypalAccounts));
                 Mage::dispatchEvent('gene_braintree_get_saved_methods', array('object' => $object));
                 $this->savedAccounts = $object->getSavedAccounts();
             }
         }
         return $this->savedAccounts;
     }
     return false;
 }