protected function _setMerchant()
 {
     Divido::setMerchant($this->getApiKey());
     if ($this->getMethod()->getConfigData('sandbox')) {
         Divido::setSandboxMode(true);
     }
 }
 public function setFulfilled($applicationId, $shippingMethod = null, $trackingNumbers = null)
 {
     $apiKey = $this->getApiKey();
     $params = array('application' => $applicationId, 'deliveryMethod' => $shippingMethod, 'trackingNumber' => $trackingNumbers);
     Divido::setMerchant($apiKey);
     Divido_Fulfillment::fulfill($params);
 }
Beispiel #3
0
 public function getAllPlans()
 {
     if ($plans = $this->cache->get(self::CACHE_KEY_PLANS)) {
         // OpenCart 2.1 decodes json objects to associative arrays so we
         // need to make sure we're getting a list of simple objects back.
         $plans = array_map(function ($plan) {
             return (object) $plan;
         }, $plans);
         return $plans;
     }
     $api_key = $this->config->get('divido_api_key');
     if (!$api_key) {
         throw new Exception("No Divido api-key defined");
     }
     Divido::setMerchant($api_key);
     $response = Divido_Finances::all();
     if ($response->status != 'ok') {
         throw new Exception("Can't get list of finance plans from Divido!");
     }
     $plans = $response->finances;
     // OpenCart 2.1 switched to json for their file storage cache, so
     // we need to convert to a simple object.
     $plans_plain = array();
     foreach ($plans as $plan) {
         $plan_copy = new stdClass();
         $plan_copy->id = $plan->id;
         $plan_copy->text = $plan->text;
         $plan_copy->country = $plan->country;
         $plan_copy->min_amount = $plan->min_amount;
         $plan_copy->min_deposit = $plan->min_deposit;
         $plan_copy->max_deposit = $plan->max_deposit;
         $plan_copy->interest_rate = $plan->interest_rate;
         $plan_copy->deferral_period = $plan->deferral_period;
         $plan_copy->agreement_duration = $plan->agreement_duration;
         $plans_plain[] = $plan_copy;
     }
     $this->cache->set(self::CACHE_KEY_PLANS, $plans_plain);
     return $plans_plain;
 }
 /**
  * Start Standard Checkout and dispatching customer to divido
  */
 public function startAction()
 {
     $resource = Mage::getSingleton('core/resource');
     $readConnection = $resource->getConnection('core_read');
     $table = $resource->getTableName('core_config_data');
     $query = "select value from {$table} where path = 'payment/pay/api_key'";
     $api_encode = $readConnection->fetchOne($query);
     $apiKey = Mage::helper('core')->decrypt($api_encode);
     Divido::setMerchant($apiKey);
     $quote_cart = Mage::getModel('checkout/cart')->getQuote();
     $checkout_session = Mage::getSingleton('checkout/session');
     $quote_id = $checkout_session->getQuoteId();
     $quote_session = $checkout_session->getQuote();
     $quote_session_data = $quote_session->getData();
     $deposit_percentage = $this->getRequest()->getParam('divido_deposit') / 100;
     $finance = $this->getRequest()->getParam('divido_finance');
     $language = strtoupper(substr(Mage::getStoreConfig('general/locale/code', Mage::app()->getStore()->getId()), 0, 2));
     $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
     $shipAddr = $quote_session->getShippingAddress();
     $shipping = $shipAddr->getData();
     $postcode = $shipping['postcode'];
     $telephone = $shipping['telephone'];
     $firstname = $shipping['firstname'];
     $lastname = $shipping['lastname'];
     $country = $shipping['country_id'];
     $email = $quote_session_data['customer_email'];
     $middlename = $quote_session_data['customer_middlename'];
     $item_quote = Mage::getModel('checkout/cart')->getQuote();
     $items_in_cart = $item_quote->getAllItems();
     $products = array();
     foreach ($items_in_cart as $item) {
         $item_qty = $item->getQty();
         $item_value = $item->getPrice();
         $products[] = array("type" => "product", "text" => $item->getName(), "quantity" => $item_qty, "value" => $item_value);
     }
     $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
     $grand_total = $totals['grand_total']->getValue();
     foreach ($totals as $total) {
         if (in_array($total->getCode(), array('subtotal', 'grand_total'))) {
             continue;
         }
         $products[] = array('type' => 'product', 'text' => $total->getTitle(), 'quantity' => 1, 'value' => $total->getValue());
     }
     $deposit = round($deposit_percentage * $grand_total, 2);
     $salt = uniqid('', true);
     $quote_hash = Mage::helper('pay')->hashQuote($salt, $quote_id);
     $customer = array('title' => '', 'first_name' => $firstname, 'middle_name' => $middlename, 'last_name' => $lastname, 'country' => $country, 'postcode' => $postcode, 'email' => $email, 'mobile_number' => '', 'phone_number' => $telephone);
     $metadata = array('quote_id' => $quote_id, 'quote_hash' => $quote_hash);
     $request_data = array('merchant' => $apiKey, 'deposit' => $deposit, 'finance' => $finance, 'country' => $country, 'language' => $language, 'currency' => $currency, 'metadata' => $metadata, 'customer' => $customer, 'products' => $products, 'response_url' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . 'divido_callback.php', 'checkout_url' => Mage::helper('checkout/url')->getCheckoutUrl(), 'redirect_url' => Mage::getUrl('pay/payment/return', array('quote_id' => $quote_id)));
     if (Mage::getStoreConfig('payment/pay/debug')) {
         Mage::log('Request: ' . json_encode($request_data), Zend_Log::DEBUG, 'divido.log', true);
     }
     $response = Divido_CreditRequest::create($request_data);
     if (Mage::getStoreConfig('payment/pay/debug')) {
         Mage::log('Response: ' . $response->__toJSON(), Zend_Log::DEBUG, 'divido.log', true);
     }
     if ($response->status == 'ok') {
         $lookup = Mage::getModel('callback/lookup');
         $lookup->setQuoteId($quote_id);
         $lookup->setSalt($salt);
         $lookup->setCreditRequestId($response->id);
         $lookup->setDepositAmount($deposit);
         $existing_lookup = Mage::getModel('callback/lookup')->load($quote_id, 'quote_id');
         if ($existing_lookup->getId()) {
             $lookup->setId($existing_lookup->getId());
         }
         if (Mage::getStoreConfig('payment/pay/debug')) {
             Mage::log('Lookup: ' . json_encode($lookup->getData()), Zend_Log::DEBUG, 'divido.log', true);
         }
         $lookup->save();
         $this->getResponse()->setRedirect($response->url);
         return;
     } else {
         if ($response->status === 'error') {
             Mage::getSingleton('checkout/session')->addError($response->error);
             $this->_redirect('checkout/cart');
         }
     }
 }
 /**
  * @param boolean $verify
  */
 public static function setVerifySslCerts($verify)
 {
     self::$verifySslCerts = $verify;
 }