Ejemplo n.º 1
0
 /**
  * Show details for specified transaction
  */
 private function showTransactionDetails()
 {
     $manager = ShopTransactionsManager::getInstance();
     $buyer_manager = ShopBuyersManager::getInstance();
     $address_manager = ShopDeliveryAddressManager::getInstance();
     $id = fix_id($_REQUEST['id']);
     $transaction = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id));
     $buyer = $buyer_manager->getSingleItem($buyer_manager->getFieldNames(), array('id' => $transaction->buyer));
     $address = $address_manager->getSingleItem($address_manager->getFieldNames(), array('id' => $transaction->address));
     $full_address = "{$address->name}\n\n{$address->street}\n";
     $full_address .= "{$address->zip} {$address->city}\n";
     if (empty($address->state)) {
         $full_address .= $address->country;
     } else {
         $full_address .= "{$address->state}, {$address->country}";
     }
     $params = array('id' => $transaction->id, 'uid' => $transaction->uid, 'type' => $transaction->type, 'type_string' => '', 'status' => $transaction->status, 'currency' => $transaction->currency, 'handling' => $transaction->handling, 'shipping' => $transaction->shipping, 'timestamp' => $transaction->timestamp, 'delivery_method' => $transaction->delivery_method, 'remark' => $transaction->remark, 'total' => $transaction->total, 'first_name' => $buyer->first_name, 'last_name' => $buyer->last_name, 'email' => $buyer->email, 'address_name' => $address->name, 'address_street' => $address->street, 'address_city' => $address->city, 'address_zip' => $address->zip, 'address_state' => $address->state, 'address_country' => $address->country, 'full_address' => $full_address);
     $template = new TemplateHandler('transaction_details.xml', $this->path . 'templates/');
     // register tag handler
     $template->registerTagHandler('_item_list', $this, 'tag_TransactionItemList');
     $template->registerTagHandler('_transaction_status', $this, 'tag_TransactionStatus');
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Ejemplo n.º 3
0
 /**
  * Handle transaction status change.
  *
  * @param object transaction
  */
 public function on_transaction_completed($transaction)
 {
     global $language;
     // get managers
     $buyer_manager = ShopBuyersManager::getInstance();
     $address_manager = ShopDeliveryAddressManager::getInstance();
     $transaction_items_manager = ShopTransactionItemsManager::getInstance();
     $item_manager = ShopItemManager::getInstance();
     // get transaction data
     $buyer = Transaction::get_buyer($transaction);
     $address = Transaction::get_address($transaction);
     $transaction_items = $transaction_items_manager->getItems($transaction_items_manager->getFieldNames(), array('transaction' => $transaction->id));
     $date_time = date('Y-m-d', strtotime($transaction->delivery_type));
     // prepare data
     $title = $buyer->first_name . ' ' . $buyer->last_name . ' - ' . $transaction->uid;
     if ($transaction->delivery_type == 'pickup') {
         $location = '';
         $color = 9;
     } else {
         $location = $address->street . ' ' . $address->street2 . ', ' . $address->zip . ' ' . $address->city . ', ' . $address->country;
         $color = 10;
     }
     $id_list = array();
     $name_by_id = array();
     $description = '';
     if (count($transaction_items) > 0) {
         foreach ($transaction_items as $item) {
             $id_list[] = $item->item;
         }
         $items = $item_manager->getItems(array('id', 'name'), array('id' => $id_list));
         foreach ($items as $item) {
             $name_by_id[$item->id] = $item->name;
         }
         foreach ($transaction_items as $item) {
             $description .= $name_by_id[$item->item][$language] . ' - ' . $item->amount . "\n";
         }
     }
     $post_data = array('start' => $date_time, 'end' => $date_time, 'title' => $title, 'location' => $location, 'description' => $description, 'color' => $color);
     $post_data = json_encode($post_data);
     $url = 'https://zapier.com/hooks/catch/133542/uti08e';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HTTPGET, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($ch);
 }
Ejemplo n.º 4
0
 /**
  * Handle drawing checkout form
  *
  * @param array $tag_params
  * @param array $children
  */
 public function tag_CheckoutForm($tag_params, $children)
 {
     $account_information = array();
     $shipping_information = array();
     $billing_information = array();
     $payment_method = null;
     $stage = isset($_REQUEST['stage']) ? fix_chars($_REQUEST['stage']) : null;
     $recurring = isset($_SESSION['recurring_plan']) && !empty($_SESSION['recurring_plan']);
     // decide whether to include shipping and account information
     if (isset($tag_params['include_shipping'])) {
         $include_shipping = fix_id($tag_params['include_shipping']) == 1;
     } else {
         $include_shipping = true;
     }
     $bad_fields = array();
     $info_available = false;
     // grab user information
     if (!is_null($stage)) {
         // get payment method
         $payment_method = $this->getPaymentMethod($tag_params);
         if (is_null($payment_method)) {
             throw new PaymentMethodError('No payment method selected!');
         }
         // get billing information
         $billing_information = $this->getBillingInformation($payment_method);
         $billing_required = array('billing_full_name', 'billing_card_type', 'billing_credit_card', 'billing_expire_month', 'billing_expire_year', 'billing_cvv');
         $bad_fields = $this->checkFields($billing_information, $billing_required, $bad_fields);
         // get shipping information
         if ($include_shipping && $stage == 'set_info') {
             $shipping_information = $this->getShippingInformation();
             $shipping_required = array('name', 'email', 'street', 'city', 'zip', 'country');
             $bad_fields = $this->checkFields($shipping_information, $shipping_required, $bad_fields);
         }
     }
     $info_available = count($bad_fields) == 0 && !is_null($payment_method);
     if ($info_available) {
         $address_manager = ShopDeliveryAddressManager::getInstance();
         $currency_manager = ShopCurrenciesManager::getInstance();
         // get fields for payment method
         $return_url = url_Make('checkout_completed', 'shop', array('payment_method', $payment_method->get_name()));
         $cancel_url = url_Make('checkout_canceled', 'shop', array('payment_method', $payment_method->get_name()));
         // get currency info
         $currency = $this->settings['default_currency'];
         $currency_item = $currency_manager->getSingleItem(array('id'), array('currency' => $currency));
         if (is_object($currency_item)) {
             $transaction_data['currency'] = $currency_item->id;
         }
         // get buyer
         $buyer = $this->getUserAccount();
         if ($include_shipping) {
             $address = $this->getAddress($buyer, $shipping_information);
         } else {
             $address = null;
         }
         // update transaction
         $transaction_type = $recurring ? TransactionType::SUBSCRIPTION : TransactionType::SHOPPING_CART;
         $summary = $this->updateTransaction($transaction_type, $payment_method, '', $buyer, $address);
         // emit signal and return if handled
         if ($stage == 'set_info') {
             Events::trigger('shop', 'before-checkout', $payment_method->get_name(), $return_url, $cancel_url);
             foreach ($result_list as $result) {
                 if ($result) {
                     $this->showCheckoutRedirect();
                     return;
                 }
             }
         }
         // create new payment
         if ($recurring) {
             // recurring payment
             $checkout_fields = $payment_method->new_recurring_payment($_SESSION['recurring_plan'], $billing_information, $return_url, $cancel_url);
         } else {
             // regular payment
             $checkout_fields = $payment_method->new_payment($transaction_data, $billing_information, $summary['items_for_checkout'], $return_url, $cancel_url);
         }
         // load template
         $template = $this->loadTemplate($tag_params, 'checkout_form.xml');
         $template->registerTagHandler('cms:checkout_items', $this, 'tag_CheckoutItems');
         $template->registerTagHandler('cms:delivery_methods', $this, 'tag_DeliveryMethodsList');
         // parse template
         $params = array('checkout_url' => $payment_method->get_url(), 'checkout_fields' => $checkout_fields, 'checkout_name' => $payment_method->get_title(), 'currency' => $this->getDefaultCurrency(), 'recurring' => $recurring, 'include_shipping' => $include_shipping);
         // for recurring plans add additional params
         if ($recurring) {
             $plans = $payment_method->get_recurring_plans();
             $plan_name = $_SESSION['recurring_plan'];
             $plan = $plans[$plan_name];
             $params['plan_name'] = $plan['name'];
             $params['plan_description'] = $this->formatRecurring(array('price' => $plan['price'], 'period' => $plan['interval_count'], 'period' => $plan['interval_count'], 'unit' => $plan['interval'], 'setup' => $plan['setup_price'], 'trial_period' => $plan['trial_count'], 'trial_unit' => $plan['trial']));
         } else {
             $params['sub-total'] = number_format($summary['total'], 2);
             $params['shipping'] = number_format($summary['shipping'], 2);
             $params['handling'] = number_format($summary['handling'], 2);
             $params['total_weight'] = number_format($summary['weight'], 2);
             $params['total'] = number_format($summary['total'] + $summary['shipping'] + $summary['handling'], 2);
         }
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     } else {
         // no information available, show form
         $template = new TemplateHandler('buyer_information.xml', $this->path . 'templates/');
         $template->setMappedModule($this->name);
         $template->registerTagHandler('cms:card_type', $this, 'tag_CardType');
         // get fixed country if set
         $fixed_country = '';
         if (isset($this->settings['fixed_country'])) {
             $fixed_country = $this->settings['fixed_country'];
         }
         $params = array('include_shipping' => $include_shipping, 'fixed_country' => $fixed_country, 'bad_fields' => $bad_fields, 'recurring' => $recurring);
         $template->restoreXML();
         $template->setLocalParams($params);
         $template->parse();
     }
 }