public function execValidation($cart)
 {
     global $cookie;
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->active) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process
     $authorized = false;
     foreach (Module::getPaymentModules() as $module) {
         if ($module['name'] == 'veritranspay') {
             $authorized = true;
             break;
         }
     }
     if (!$authorized) {
         die($this->module->l('This payment method is not available.', 'validation'));
     }
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $usd = Configuration::get('VT_KURS');
     $cf = Configuration::get('VT_CONVENIENCE_FEE') * 0.01;
     $list_enable_payments = array();
     if (Configuration::get('ENABLED_CREDIT_CARD')) {
         $list_enable_payments[] = "credit_card";
     }
     if (Configuration::get('ENABLED_CIMB')) {
         $list_enable_payments[] = "cimb_clicks";
     }
     if (Configuration::get('ENABLED_MANDIRI')) {
         $list_enable_payments[] = "mandiri_clickpay";
     }
     if (Configuration::get('ENABLED_PERMATAVA')) {
         $list_enable_payments[] = "bank_transfer";
     }
     if (Configuration::get('ENABLED_BRIEPAY')) {
         $list_enable_payments[] = "bri_epay";
     }
     if (Configuration::get('ENABLED_TELKOMSEL_CASH')) {
         $list_enable_payments[] = "telkomsel_cash";
     }
     if (Configuration::get('ENABLED_XL_TUNAI')) {
         $list_enable_payments[] = "xl_tunai";
     }
     if (Configuration::get('ENABLED_MANDIRI_BILL')) {
         $list_enable_payments[] = "echannel";
     }
     if (Configuration::get('ENABLED_BBM_MONEY')) {
         $list_enable_payments[] = "bbm_money";
     }
     if (Configuration::get('ENABLED_INDOMARET')) {
         $list_enable_payments[] = "cstore";
     }
     if (Configuration::get('ENABLED_INDOSAT_DOMPETKU')) {
         $list_enable_payments[] = "indosat_dompetku";
     }
     if (Configuration::get('ENABLED_MANDIRI_ECASH')) {
         $list_enable_payments[] = "mandiri_ecash";
     }
     //error_log(print_r($list_enable_payments,TRUE));
     $veritrans = new Veritrans_Config();
     //SETUP
     Veritrans_Config::$serverKey = Configuration::get('VT_SERVER_KEY');
     Veritrans_Config::$isProduction = Configuration::get('VT_ENVIRONMENT') == 'production' ? true : false;
     $url = Veritrans_Config::getBaseUrl();
     if (version_compare(Configuration::get('PS_VERSION_DB'), '1.5') == -1) {
         $shipping_cost = $cart->getOrderShippingCost();
     } else {
         $shipping_cost = $cart->getTotalShippingCost();
     }
     $currency = new Currency($cookie->id_currency);
     $total = $cart->getOrderTotal(true, Cart::BOTH);
     $mailVars = array();
     $billing_address = new Address($cart->id_address_invoice);
     $delivery_address = new Address($cart->id_address_delivery);
     if (Configuration::get('VT_3D_SECURE') == 'on' || Configuration::get('VT_3D_SECURE') == 1) {
         Veritrans_Config::$is3ds = true;
     }
     if (Configuration::get('VT_SANITIZED') == 'on' || Configuration::get('VT_SANITIZED') == 1) {
         Veritrans_Config::$isSanitized = true;
     }
     //error_log('sanitized '.Configuration::get('VT_SANITIZED'));
     // Billing Address
     $params_billing_address = array('first_name' => $billing_address->firstname, 'last_name' => $billing_address->lastname, 'address' => $billing_address->address1, 'city' => $billing_address->city, 'postal_code' => $billing_address->postcode, 'phone' => $this->determineValidPhone($billing_address->phone, $billing_address->phone_mobile), 'country_code' => 'IDN');
     if ($cart->isVirtualCart()) {
     } else {
         if ($cart->id_address_delivery != $cart->id_address_invoice) {
             $params_shipping_address = array('first_name' => $delivery_address->firstname, 'last_name' => $delivery_address->lastname, 'address' => $delivery_address->address1, 'city' => $delivery_address->city, 'postal_code' => $delivery_address->postcode, 'phone' => $this->determineValidPhone($delivery_address->phone, $delivery_address->phone_mobile), 'country_code' => 'IDN');
         } else {
             $params_shipping_address = $params_billing_address;
         }
     }
     $params_customer_details = array('first_name' => $billing_address->firstname, 'last_name' => $billing_address->lastname, 'email' => $customer->email, 'phone' => $this->determineValidPhone($billing_address->phone, $billing_address->phone_mobile), 'billing_address' => $params_billing_address, 'shipping_address' => $params_shipping_address);
     $items = $this->addCommodities($cart, $shipping_cost, $usd);
     // convert the currency
     $cart_currency = new Currency($cart->id_currency);
     if ($cart_currency->iso_code != 'IDR') {
         // check whether if the IDR is installed or not
         if (Currency::exists('IDR', null)) {
             // use default rate
             if (version_compare(Configuration::get('PS_VERSION_DB'), '1.5') == -1) {
                 $conversion_func = function ($input) use($cart_currency) {
                     return Tools::convertPrice($input, new Currency(Currency::getIdByIsoCode('IDR')), true);
                 };
             } else {
                 $conversion_func = function ($input) use($cart_currency) {
                     return Tools::convertPriceFull($input, $cart_currency, new Currency(Currency::getIdByIsoCode('IDR')));
                 };
             }
         } else {
             // use rate
             $conversion_func = function ($input) {
                 return $input * intval(Configuration::get('VT_KURS'));
             };
         }
         foreach ($items as &$item) {
             $item['price'] = intval(round(call_user_func($conversion_func, $item['price'])));
         }
     } else {
         if ($cart_currency->iso_code == 'IDR') {
             foreach ($items as &$item) {
                 $item['price'] = intval(round($item['price']));
             }
         }
     }
     $this->validateOrder($cart->id, Configuration::get('VT_ORDER_STATE_ID'), $cart->getOrderTotal(true, Cart::BOTH), $this->displayName, NULL, $mailVars, (int) $currency->id, false, $customer->secure_key);
     $gross_amount = 0;
     unset($item);
     foreach ($items as $item) {
         $gross_amount += $item['price'] * $item['quantity'];
     }
     $isBniInstallment = Configuration::get('ENABLED_BNI_INSTALLMENT') == 1;
     $isMandiriInstallment = Configuration::get('ENABLED_MANDIRI_INSTALLMENT') == 1;
     $warning_redirect = false;
     $fullPayment = true;
     $installment_type_val = Configuration::get('VT_ENABLE_INSTALLMENT');
     $param_required;
     switch ($installment_type_val) {
         case 'all_product':
             if ($isBniInstallment) {
                 //$bni_term2 = $this->getTermInstallment('BNI');
                 $a = Configuration::get('VT_INSTALLMENTS_BNI');
                 $term = explode(',', $a);
                 $bni_term = $term;
                 //error_log(print_r($bni_term,true));
                 //error_log($bni_term,true);
             }
             if ($isMandiriInstallment) {
                 $mandiri_term = $this->getTermInstallment('MANDIRI');
                 $a = Configuration::get('VT_INSTALLMENTS_MANDIRI');
                 $term = explode(',', $a);
                 $mandiri_term = $term;
                 //error_log($mandiri_term,true);
                 //error_log(print_r($mandiri_term,true));
             }
             $param_installment = array();
             if ($isBniInstallment) {
                 $param_installment['bni'] = $bni_term;
             }
             if ($isMandiriInstallment) {
                 $param_installment['mandiri'] = $mandiri_term;
             }
             $param_required = "false";
             $fullPayment = false;
             break;
         case 'certain_product':
             $param_installment = null;
             $products_cart = $cart->getProducts();
             $num_product = count($products_cart);
             if ($num_product == 1) {
                 $attr_product = explode(',', $products_cart[0]['attributes_small']);
                 foreach ($attr_product as $att) {
                     $att_trim = ltrim($att);
                     $att_arr = explode(' ', $att_trim);
                     //error_log(print_r($att_arr,true));
                     if (strtolower($att_arr[0]) == 'installment') {
                         $fullPayment = false;
                         $param_installment = array();
                         $param_installment[strtolower($att_arr[1])] = array($att_arr[2]);
                     }
                 }
             } else {
                 $warning_redirect = true;
                 $keys['message'] = 1;
             }
             $param_required = "true";
             break;
         case 'off':
             $param_installment = null;
             break;
     }
     //error_log($param_installment,true);
     // $param_payment_option = array(
     // 	'installment' => array(
     // 						'required' => $param_required,
     // 						'installment_terms' => $param_installment
     // 					)
     // 	);
     $params_all = array('payment_type' => Configuration::get('VT_PAYMENT_TYPE'), 'vtweb' => array('enabled_payments' => $list_enable_payments), 'transaction_details' => array('order_id' => $this->currentOrder, 'gross_amount' => $gross_amount), 'item_details' => $items, 'customer_details' => $params_customer_details);
     if ($gross_amount < 500000) {
         $warning_redirect = true;
         $keys['message'] = 2;
     }
     if (!$warning_redirect && ($isBniInstallment || $isMandiriInstallment) && !$fullPayment) {
         $params_all['vtweb']['payment_options'] = $param_payment_option;
     }
     if (Configuration::get('VT_API_VERSION') == 2 && Configuration::get('VT_PAYMENT_TYPE') != 'vtdirect') {
         try {
             // Redirect to Veritrans VTWeb page
             if ($this->isInstallmentCart($cart->getProducts()) || $installment_type_val == 'all_product') {
                 $keys['isWarning'] = $warning_redirect;
             } else {
                 $keys['isWarning'] = false;
             }
             $keys['redirect_url'] = Veritrans_Vtweb::getRedirectionUrl($params_all);
         } catch (Exception $e) {
             $keys['errors'] = $e->getMessage();
             echo $e->getMessage();
         }
         return $keys;
     } else {
         if (Configuration::get('VT_API_VERSION') == 2 && Configuration::get('VT_PAYMENT_TYPE') == 'vtdirect') {
             echo 'not yet implementation.';
             exit;
         } else {
             echo 'The Veritrans API versions and the payment type is not valid.';
             exit;
         }
     }
 }
예제 #2
0
    $server_key = $veritrans_live;
} else {
    $server_key = $veritrans_sandbox;
}
Veritrans_Config::$serverKey = $server_key;
/* --- ENVIRONMENT --- */
if ($veritrans_environment == 1) {
    Veritrans_Config::$isProduction = true;
} else {
    Veritrans_Config::$isProduction = false;
}
/* --- 3D Secure --- */
if ($veritrans_secure == 1) {
    Veritrans_Config::$is3ds = true;
} else {
    Veritrans_Config::$is3ds = false;
}
// Uncomment to enable sanitization
// Veritrans_Config::$isSanitized = true;
/*
foreach($data_item as $key=>$data_item){
   
   if($data_item->promo_item_id != ''){
      
      if($data_item->promo_start_datetime <= date('Y-m-d') and $data_item->promo_end_datetime >= date('Y-m-d')){
	     if($data_item->promo_id == '1'){
	     
		    $data_item->type_price = $data_item->type_price - (($data_item->promo_value / 100) * $data_item->type_price);
		 
		 }else if($data_item->promo_id == '2'){
	        $data_item->type_price = $data_item->type_price - $data_item->promo_value;
 /**
  * Called when a customer checkouts.
  * If it runs successfully, it will redirect to VT-Web payment page.
  */
 public function process_order()
 {
     $this->load->model('payment/veritransbca');
     $this->load->model('checkout/order');
     $this->load->model('total/shipping');
     $this->load->language('payment/veritransbca');
     $data['errors'] = array();
     $data['button_confirm'] = $this->language->get('button_confirm');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('veritransbca_vtweb_challenge_mapping'));
     $transaction_details = array();
     $transaction_details['order_id'] = $this->session->data['order_id'];
     $transaction_details['gross_amount'] = $order_info['total'];
     $billing_address = array();
     $billing_address['first_name'] = $order_info['payment_firstname'];
     $billing_address['last_name'] = $order_info['payment_lastname'];
     $billing_address['address'] = $order_info['payment_address_1'];
     $billing_address['city'] = $order_info['payment_city'];
     $billing_address['postal_code'] = $order_info['payment_postcode'];
     $billing_address['phone'] = $order_info['telephone'];
     $billing_address['country_code'] = strlen($order_info['payment_iso_code_3'] != 3) ? 'IDN' : $order_info['payment_iso_code_3'];
     if ($this->cart->hasShipping()) {
         $shipping_address = array();
         $shipping_address['first_name'] = $order_info['shipping_firstname'];
         $shipping_address['last_name'] = $order_info['shipping_lastname'];
         $shipping_address['address'] = $order_info['shipping_address_1'];
         $shipping_address['city'] = $order_info['shipping_city'];
         $shipping_address['postal_code'] = $order_info['shipping_postcode'];
         $shipping_address['phone'] = $order_info['telephone'];
         $shipping_address['country_code'] = strlen($order_info['payment_iso_code_3'] != 3) ? 'IDN' : $order_info['payment_iso_code_3'];
     } else {
         $shipping_address = $billing_address;
     }
     $customer_details = array();
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $shipping_address;
     $customer_details['first_name'] = $order_info['payment_firstname'];
     $customer_details['last_name'] = $order_info['payment_lastname'];
     $customer_details['email'] = $order_info['email'];
     $customer_details['phone'] = $order_info['telephone'];
     $products = $this->cart->getProducts();
     $item_details = array();
     foreach ($products as $product) {
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $product['price'] = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
         }
         $item = array('id' => $product['product_id'], 'price' => $product['price'], 'quantity' => $product['quantity'], 'name' => $product['name']);
         $item_details[] = $item;
     }
     unset($product);
     $num_products = count($item_details);
     if ($this->cart->hasShipping()) {
         $shipping_info = $this->session->data['shipping_method'];
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $shipping_info['cost'] = $this->tax->calculate($shipping_info['cost'], $shipping_info['tax_class_id'], $this->config->get('config_tax'));
         }
         $shipping_item = array('id' => 'SHIPPING', 'price' => $shipping_info['cost'], 'quantity' => 1, 'name' => 'SHIPPING');
         $item_details[] = $shipping_item;
     }
     // convert all item prices to IDR
     if ($this->config->get('config_currency') != 'IDR') {
         if ($this->currency->has('IDR')) {
             foreach ($item_details as &$item) {
                 $item['price'] = intval($this->currency->convert($item['price'], $this->config->get('config_currency'), 'IDR'));
             }
             unset($item);
             $transaction_details['gross_amount'] = intval($this->currency->convert($transaction_details['gross_amount'], $this->config->get('config_currency'), 'IDR'));
         } else {
             if ($this->config->get('veritransbca_currency_conversion') > 0) {
                 foreach ($item_details as &$item) {
                     $item['price'] = intval($item['price'] * $this->config->get('veritransbca_currency_conversion'));
                 }
                 unset($item);
                 $transaction_details['gross_amount'] = intval($transaction_details['gross_amount'] * $this->config->get('veritransbca_currency_conversion'));
             } else {
                 $data['errors'][] = "Either the IDR currency is not installed or " . "the Veritrans currency conversion rate is valid. " . "Please review your currency setting.";
             }
         }
     }
     $total_price = 0;
     foreach ($item_details as $item) {
         $total_price += $item['price'] * $item['quantity'];
     }
     if ($total_price != $transaction_details['gross_amount']) {
         $coupon_item = array('id' => 'COUPON', 'price' => $transaction_details['gross_amount'] - $total_price, 'quantity' => 1, 'name' => 'COUPON');
         $item_details[] = $coupon_item;
     }
     Veritrans_Config::$serverKey = $this->config->get('veritransbca_server_key_v2');
     Veritrans_Config::$isProduction = $this->config->get('veritransbca_environment') == 'production' ? true : false;
     //Veritrans_Config::$is3ds = $this->config->get('veritrans_3d_secure') == 'on' ? true : false;
     Veritrans_Config::$is3ds = true;
     Veritrans_Config::$isSanitized = true;
     $payloads = array();
     $payloads['transaction_details'] = $transaction_details;
     $payloads['item_details'] = $item_details;
     $payloads['customer_details'] = $customer_details;
     $threshold = $this->config->get('veritransbca_threshold');
     try {
         $enabled_payments = array();
         $enabled_payments[] = 'credit_card';
         $payloads['vtweb']['enabled_payments'] = $enabled_payments;
         $payloads['vtweb']['credit_card']['bank'] = 'bca';
         $payloads['vtweb']['credit_card']['channel'] = 'migs';
         error_log(print_r($payloads, TRUE));
         $redirUrl = Veritrans_VtWeb::getRedirectionUrl($payloads);
         // $this->cart->clear();
         //$this->response->redirect($redirUrl);
         $this->response->setOutput($redirUrl);
     } catch (Exception $e) {
         $data['errors'][] = $e->getMessage();
         error_log($e->getMessage());
         echo $e->getMessage();
     }
 }
 /**
  * Called when a customer checkouts.
  * If it runs successfully, it will redirect to VT-Web payment page.
  */
 public function process_order()
 {
     $this->load->model('payment/veritransbni');
     $this->load->model('checkout/order');
     $this->load->model('total/shipping');
     $this->load->language('payment/veritransbni');
     $data['errors'] = array();
     $data['button_confirm'] = $this->language->get('button_confirm');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('veritransbni_vtweb_challenge_mapping'));
     $transaction_details = array();
     $transaction_details['order_id'] = $this->session->data['order_id'];
     $transaction_details['gross_amount'] = $order_info['total'];
     $billing_address = array();
     $billing_address['first_name'] = $order_info['payment_firstname'];
     $billing_address['last_name'] = $order_info['payment_lastname'];
     $billing_address['address'] = $order_info['payment_address_1'];
     $billing_address['city'] = $order_info['payment_city'];
     $billing_address['postal_code'] = $order_info['payment_postcode'];
     $billing_address['phone'] = $order_info['telephone'];
     $billing_address['country_code'] = strlen($order_info['payment_iso_code_3'] != 3) ? 'IDN' : $order_info['payment_iso_code_3'];
     if ($this->cart->hasShipping()) {
         $shipping_address = array();
         $shipping_address['first_name'] = $order_info['shipping_firstname'];
         $shipping_address['last_name'] = $order_info['shipping_lastname'];
         $shipping_address['address'] = $order_info['shipping_address_1'];
         $shipping_address['city'] = $order_info['shipping_city'];
         $shipping_address['postal_code'] = $order_info['shipping_postcode'];
         $shipping_address['phone'] = $order_info['telephone'];
         $shipping_address['country_code'] = strlen($order_info['payment_iso_code_3'] != 3) ? 'IDN' : $order_info['payment_iso_code_3'];
     } else {
         $shipping_address = $billing_address;
     }
     $customer_details = array();
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $shipping_address;
     $customer_details['first_name'] = $order_info['payment_firstname'];
     $customer_details['last_name'] = $order_info['payment_lastname'];
     $customer_details['email'] = $order_info['email'];
     $customer_details['phone'] = $order_info['telephone'];
     $products = $this->cart->getProducts();
     $item_details = array();
     foreach ($products as $product) {
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $product['price'] = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
         }
         $item = array('id' => $product['product_id'], 'price' => $product['price'], 'quantity' => $product['quantity'], 'name' => $product['name']);
         $item_details[] = $item;
     }
     unset($product);
     $num_products = count($item_details);
     if ($this->cart->hasShipping()) {
         $shipping_info = $this->session->data['shipping_method'];
         if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
             $shipping_info['cost'] = $this->tax->calculate($shipping_info['cost'], $shipping_info['tax_class_id'], $this->config->get('config_tax'));
         }
         $shipping_item = array('id' => 'SHIPPING', 'price' => $shipping_info['cost'], 'quantity' => 1, 'name' => 'SHIPPING');
         $item_details[] = $shipping_item;
     }
     // convert all item prices to IDR
     if ($this->config->get('config_currency') != 'IDR') {
         if ($this->currency->has('IDR')) {
             foreach ($item_details as &$item) {
                 $item['price'] = intval($this->currency->convert($item['price'], $this->config->get('config_currency'), 'IDR'));
             }
             unset($item);
             $transaction_details['gross_amount'] = intval($this->currency->convert($transaction_details['gross_amount'], $this->config->get('config_currency'), 'IDR'));
         } else {
             if ($this->config->get('veritransbni_currency_conversion') > 0) {
                 foreach ($item_details as &$item) {
                     $item['price'] = intval($item['price'] * $this->config->get('veritransbni_currency_conversion'));
                 }
                 unset($item);
                 $transaction_details['gross_amount'] = intval($transaction_details['gross_amount'] * $this->config->get('veritransbni_currency_conversion'));
             } else {
                 $data['errors'][] = "Either the IDR currency is not installed or " . "the Veritrans currency conversion rate is valid. " . "Please review your currency setting.";
             }
         }
     }
     $total_price = 0;
     foreach ($item_details as $item) {
         $total_price += $item['price'] * $item['quantity'];
     }
     if ($total_price != $transaction_details['gross_amount']) {
         $coupon_item = array('id' => 'COUPON', 'price' => $transaction_details['gross_amount'] - $total_price, 'quantity' => 1, 'name' => 'COUPON');
         $item_details[] = $coupon_item;
     }
     Veritrans_Config::$serverKey = $this->config->get('veritransbni_server_key_v2');
     Veritrans_Config::$isProduction = $this->config->get('veritransbni_environment') == 'production' ? true : false;
     //Veritrans_Config::$is3ds = $this->config->get('veritrans_3d_secure') == 'on' ? true : false;
     Veritrans_Config::$is3ds = false;
     Veritrans_Config::$isSanitized = true;
     $payloads = array();
     $payloads['transaction_details'] = $transaction_details;
     $payloads['item_details'] = $item_details;
     $payloads['customer_details'] = $customer_details;
     try {
         $enabled_payments = array();
         $enabled_payments[] = 'credit_card';
         $payloads['vtweb']['enabled_payments'] = $enabled_payments;
         $bins = $this->config->get('veritransbni_bin_number');
         $bins = explode(',', $bins);
         $payloads['vtweb']['credit_card_bins'] = $bins;
         $is_installment = true;
         if ($this->config->get('veritransbni_installment_option') == 'all_product') {
             $payment_options = array('installment' => array('required' => true));
             $installment_terms = array();
             $term = $this->config->get('veritransbni_installment_bni_term');
             $term_array = explode(',', $term);
             $installment_terms['bni'] = $term_array;
             $payment_options['installment']['installment_terms'] = $installment_terms;
             if ($transaction_details['gross_amount'] >= 500000) {
                 $payloads['vtweb']['payment_options'] = $payment_options;
             }
         } else {
             if ($this->config->get('veritransbni_installment_option') == 'certain_product') {
                 $payment_options = array('installment' => array('required' => true));
                 $installment_terms = array();
                 foreach ($products as $product) {
                     //$options = $product['option'];
                     foreach ($product['option'] as $option) {
                         if ($option['name'] == 'Payment') {
                             $installment_value = explode(' ', $option['value']);
                             if (strtolower($installment_value[0]) == 'installment') {
                                 $is_installment = true;
                                 $installment_terms[strtolower($installment_value[1])] = array($installment_value[2]);
                             }
                         }
                     }
                 }
                 if ($is_installment && $num_products == 1 && $transaction_details['gross_amount'] >= 500000) {
                     $payment_options['installment']['installment_terms'] = $installment_terms;
                     $payloads['vtweb']['payment_options'] = $payment_options;
                 }
             }
         }
         $redirUrl = Veritrans_VtWeb::getRedirectionUrl($payloads);
         if ($is_installment) {
             $warningUrl = 'index.php?route=information/warning&redirLink=';
             if ($num_products > 1) {
                 $redirUrl = $warningUrl . $redirUrl . '&message=1';
             } else {
                 if ($transaction_details['gross_amount'] < 500000) {
                     $redirUrl = $warningUrl . $redirUrl . '&message=2';
                 }
             }
         } else {
             if ($this->config->get('veritransbni_installment_option') == 'all_product' && $transaction_details['gross_amount'] < 500000 && $option_flag == 0) {
                 $warningUrl = 'index.php?route=information/warning&redirLink=';
                 $redirUrl = $warningUrl . $redirUrl . '&message=2';
             }
         }
         // $this->cart->clear();
         //$this->response->redirect($redirUrl);
         $this->response->setOutput($redirUrl);
     } catch (Exception $e) {
         $data['errors'][] = $e->getMessage();
         error_log($e->getMessage());
         echo $e->getMessage();
     }
 }
 /**
  * Charge Payment
  * Method ini digunakan untuk mendapatkan link halaman pembayaran Veritrans
  * dengan mengirimkan JSON yang berisi data transaksi
  */
 function charge_payment($order_id)
 {
     global $woocommerce;
     $order_items = array();
     $cart = $woocommerce->cart;
     $order = new WC_Order($order_id);
     // add discount
     // WC()->cart->add_discount( 'veritrans' );
     $cart->add_discount('veritrans');
     $order->add_coupon('veritrans', WC()->cart->get_coupon_discount_amount('veritrans'), WC()->cart->get_coupon_discount_tax_amount('veritrans'));
     $order->set_total(WC()->cart->shipping_total, 'shipping');
     $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
     $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
     $order->set_total(WC()->cart->tax_total, 'tax');
     $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
     $order->set_total(WC()->cart->total);
     // $order->add_coupon('veritrans',10000);
     // end of add discount
     Veritrans_Config::$isProduction = $this->environment == 'production' ? true : false;
     Veritrans_Config::$serverKey = Veritrans_Config::$isProduction ? $this->server_key_v2_production : $this->server_key_v2_sandbox;
     Veritrans_Config::$is3ds = true;
     Veritrans_Config::$isSanitized = $this->enable_sanitization == 'yes' ? true : false;
     $params = array('transaction_details' => array('order_id' => $order_id, 'gross_amount' => 0), 'vtweb' => array());
     $enabled_payments = array();
     // if ($this->enable_credit_card == 'yes'){
     //   $enabled_payments[] = 'credit_card';
     // }
     // check enabled payment
     if ($this->enable_credit_card == 'yes') {
         $params['vtweb']['enabled_payments'] = 'credit_card';
     }
     if ($this->enable_permata_va == 'yes') {
         $params['vtweb']['enabled_payments'] = 'bank_transfer';
     }
     // add bin filter
     $bins = $this->bin_filter;
     $bins = explode(',', $bins);
     $params['vtweb']['credit_card_bins'] = $bins;
     $customer_details = array();
     $customer_details['first_name'] = $order->billing_first_name;
     $customer_details['last_name'] = $order->billing_last_name;
     $customer_details['email'] = $order->billing_email;
     $customer_details['phone'] = $order->billing_phone;
     $billing_address = array();
     $billing_address['first_name'] = $order->billing_first_name;
     $billing_address['last_name'] = $order->billing_last_name;
     $billing_address['address'] = $order->billing_address_1;
     $billing_address['city'] = $order->billing_city;
     $billing_address['postal_code'] = $order->billing_postcode;
     $billing_address['phone'] = $order->billing_phone;
     $billing_address['country_code'] = strlen($this->convert_country_code($order->billing_country) != 3) ? 'IDN' : $this->convert_country_code($order->billing_country);
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $billing_address;
     if (isset($_POST['ship_to_different_address'])) {
         $shipping_address = array();
         $shipping_address['first_name'] = $order->shipping_first_name;
         $shipping_address['last_name'] = $order->shipping_last_name;
         $shipping_address['address'] = $order->shipping_address_1;
         $shipping_address['city'] = $order->shipping_city;
         $shipping_address['postal_code'] = $order->shipping_postcode;
         $shipping_address['phone'] = $order->billing_phone;
         $shipping_address['country_code'] = strlen($this->convert_country_code($order->shipping_country) != 3) ? 'IDN' : $this->convert_country_code($order->billing_country);
         $customer_details['shipping_address'] = $shipping_address;
     }
     $params['customer_details'] = $customer_details;
     //error_log(print_r($params,true));
     $items = array();
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['qty']) {
                 $product = $order->get_product_from_item($item);
                 $veritrans_item = array();
                 $veritrans_item['id'] = $item['product_id'];
                 $veritrans_item['price'] = $order->get_item_subtotal($item, false);
                 $veritrans_item['quantity'] = $item['qty'];
                 $veritrans_item['name'] = $item['name'];
                 $items[] = $veritrans_item;
             }
         }
     }
     // Shipping fee
     if ($order->get_total_shipping() > 0) {
         $items[] = array('id' => 'shippingfee', 'price' => $order->get_total_shipping(), 'quantity' => 1, 'name' => 'Shipping Fee');
     }
     // Tax
     if ($order->get_total_tax() > 0) {
         $items[] = array('id' => 'taxfee', 'price' => $order->get_total_tax(), 'quantity' => 1, 'name' => 'Tax');
     }
     // Discount
     if ($order->get_cart_discount() > 0) {
         $items[] = array('id' => 'totaldiscount', 'price' => $order->get_cart_discount() * -1, 'quantity' => 1, 'name' => 'Total Discount');
     }
     // Fees
     if (sizeof($order->get_fees()) > 0) {
         $fees = $order->get_fees();
         $i = 0;
         foreach ($fees as $item) {
             $items[] = array('id' => 'itemfee' . $i, 'price' => $item['line_total'], 'quantity' => 1, 'name' => $item['name']);
             $i++;
         }
     }
     //calculate gross amount
     $total_amount = 0;
     // error_log('print r items[]' . print_r($items,true)); //debugan
     foreach ($items as $item) {
         $total_amount += $item['price'] * $item['quantity'];
         // error_log('|||| Per item[]' . print_r($item,true)); //debugan
     }
     $params['transaction_details']['gross_amount'] = $total_amount;
     // error_log('bni'.$this->enable_bni);
     // error_log('mandiri'.$this->enable_mandiri);
     // if($this->enable_bni == 'yes' || $this->enable_mandiri == 'yes')
     if (false) {
         $installment_terms = array();
         $payment_options = array('installment' => array('required' => true, 'installment_terms' => new stdClass(), 'offline_installment_terms' => array()));
         // $term_bni = $this->bni_terms;
         // error_log('term bni '.$term_bni);
         // $term_bni_array = explode(',' , $term_bni);
         // if($term_bni == "yes" || $term_bni_array != null)
         // {
         //   $installment_terms['bni'] = $term_bni_array;
         // }
         // $term_mandiri =  $this->mandiri_terms;
         // error_log('term mandiri '.$term_mandiri);
         // $term_mandiri_array = explode(',' , $term_mandiri);
         // if($term_mandiri == "yes" || $term_mandiri_array != null)
         // {
         //   $installment_terms['mandiri'] = $term_mandiri_array;
         // }
         $term = $this->installment_terms;
         error_log('============installment_terms ' . $term);
         $term_array = explode(',', $term);
     }
     // sift through the entire item to ensure that currency conversion is applied
     if (get_woocommerce_currency() != 'IDR') {
         foreach ($items as &$item) {
             $item['price'] = $item['price'] * $this->to_idr_rate;
         }
         unset($item);
         $params['transaction_details']['gross_amount'] *= $this->to_idr_rate;
     }
     $params['item_details'] = $items;
     // if($params['transaction_details']['gross_amount'] >= $this->min_amount)
     // {
     //   $payment_options['installment']['offline_installment_terms'] = $term_array;
     //   $params['vtweb']['payment_options'] = $payment_options;
     // }
     $woocommerce->cart->empty_cart();
     error_log(print_r($params, TRUE));
     // error_log(json_encode($params));
     return Veritrans_VtWeb::getRedirectionUrl($params);
 }
 /**
  * Charge Payment
  * Method ini digunakan untuk mendapatkan link halaman pembayaran Veritrans
  * dengan mengirimkan JSON yang berisi data transaksi
  */
 function charge_payment($order_id)
 {
     global $woocommerce;
     $order_items = array();
     $cart = $woocommerce->cart;
     $order = new WC_Order($order_id);
     Veritrans_Config::$isProduction = $this->environment == 'production' ? true : false;
     Veritrans_Config::$serverKey = Veritrans_Config::$isProduction ? $this->server_key_v2_production : $this->server_key_v2_sandbox;
     Veritrans_Config::$is3ds = $this->enable_3d_secure == 'yes' ? true : false;
     Veritrans_Config::$isSanitized = $this->enable_sanitization == 'yes' ? true : false;
     $params = array('transaction_details' => array('order_id' => $order_id, 'gross_amount' => 0), 'vtweb' => array());
     $enabled_payments = array();
     if ($this->enable_credit_card == 'yes') {
         $enabled_payments[] = 'credit_card';
     }
     if ($this->enable_mandiri_clickpay == 'yes') {
         $enabled_payments[] = 'mandiri_clickpay';
     }
     if ($this->enable_cimb_clicks == 'yes') {
         $enabled_payments[] = 'cimb_clicks';
     }
     if ($this->enable_permata_va == 'yes') {
         $enabled_payments[] = 'bank_transfer';
     }
     if ($this->enable_bri_epay == 'yes') {
         $enabled_payments[] = 'bri_epay';
     }
     if ($this->enable_telkomsel_cash == 'yes') {
         $enabled_payments[] = 'telkomsel_cash';
     }
     if ($this->enable_xl_tunai == 'yes') {
         $enabled_payments[] = 'xl_tunai';
     }
     if ($this->enable_mandiri_bill == 'yes') {
         $enabled_payments[] = 'echannel';
     }
     if ($this->enable_bbmmoney == 'yes') {
         $enabled_payments[] = 'bbm_money';
     }
     if ($this->enable_indomaret == 'yes') {
         $enabled_payments[] = 'cstore';
     }
     if ($this->enable_indosat_dompetku == 'yes') {
         $enabled_payments[] = 'indosat_dompetku';
     }
     if ($this->enable_mandiri_ecash == 'yes') {
         $enabled_payments[] = 'mandiri_ecash';
     }
     $params['vtweb']['enabled_payments'] = $enabled_payments;
     $customer_details = array();
     $customer_details['first_name'] = $order->billing_first_name;
     $customer_details['last_name'] = $order->billing_last_name;
     $customer_details['email'] = $order->billing_email;
     $customer_details['phone'] = $order->billing_phone;
     $billing_address = array();
     $billing_address['first_name'] = $order->billing_first_name;
     $billing_address['last_name'] = $order->billing_last_name;
     $billing_address['address'] = $order->billing_address_1;
     $billing_address['city'] = $order->billing_city;
     $billing_address['postal_code'] = $order->billing_postcode;
     $billing_address['phone'] = $order->billing_phone;
     $billing_address['country_code'] = strlen($this->convert_country_code($order->billing_country) != 3) ? 'IDN' : $this->convert_country_code($order->billing_country);
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $billing_address;
     if (isset($_POST['ship_to_different_address'])) {
         $shipping_address = array();
         $shipping_address['first_name'] = $order->shipping_first_name;
         $shipping_address['last_name'] = $order->shipping_last_name;
         $shipping_address['address'] = $order->shipping_address_1;
         $shipping_address['city'] = $order->shipping_city;
         $shipping_address['postal_code'] = $order->shipping_postcode;
         $shipping_address['phone'] = $order->billing_phone;
         $shipping_address['country_code'] = strlen($this->convert_country_code($order->shipping_country) != 3) ? 'IDN' : $this->convert_country_code($order->billing_country);
         $customer_details['shipping_address'] = $shipping_address;
     }
     $params['customer_details'] = $customer_details;
     //error_log(print_r($params,true));
     $items = array();
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if ($item['qty']) {
                 $product = $order->get_product_from_item($item);
                 $veritrans_item = array();
                 $veritrans_item['id'] = $item['product_id'];
                 $veritrans_item['price'] = $order->get_item_subtotal($item, false);
                 $veritrans_item['quantity'] = $item['qty'];
                 $veritrans_item['name'] = $item['name'];
                 $items[] = $veritrans_item;
             }
         }
     }
     // Shipping fee
     if ($order->get_total_shipping() > 0) {
         $items[] = array('id' => 'shippingfee', 'price' => $order->get_total_shipping(), 'quantity' => 1, 'name' => 'Shipping Fee');
     }
     // Tax
     if ($order->get_total_tax() > 0) {
         $items[] = array('id' => 'taxfee', 'price' => $order->get_total_tax(), 'quantity' => 1, 'name' => 'Tax');
     }
     // Discount
     if ($cart->get_cart_discount_total() > 0) {
         $items[] = array('id' => 'totaldiscount', 'price' => $cart->get_cart_discount_total() * -1, 'quantity' => 1, 'name' => 'Total Discount');
     }
     // Fees
     if (sizeof($order->get_fees()) > 0) {
         $fees = $order->get_fees();
         $i = 0;
         foreach ($fees as $item) {
             $items[] = array('id' => 'itemfee' . $i, 'price' => $item['line_total'], 'quantity' => 1, 'name' => $item['name']);
             $i++;
         }
     }
     $total_amount = 0;
     // error_log('print r items[]' . print_r($items,true)); //debugan
     foreach ($items as $item) {
         $total_amount += $item['price'] * $item['quantity'];
         // error_log('|||| Per item[]' . print_r($item,true)); //debugan
     }
     error_log('order get total = ' . $order->get_total());
     error_log('total amount = ' . $total_amount);
     $params['transaction_details']['gross_amount'] = $total_amount;
     // sift through the entire item to ensure that currency conversion is applied
     if (get_woocommerce_currency() != 'IDR') {
         foreach ($items as &$item) {
             $item['price'] = $item['price'] * $this->to_idr_rate;
         }
         unset($item);
         $params['transaction_details']['gross_amount'] *= $this->to_idr_rate;
     }
     $params['item_details'] = $items;
     $woocommerce->cart->empty_cart();
     return Veritrans_VtWeb::getRedirectionUrl($params);
 }
 public function redirectAction()
 {
     $orderIncrementId = $this->_getCheckout()->getLastRealOrderId();
     $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
     $sessionId = Mage::getSingleton('core/session');
     /* send an order email when redirecting to payment page although payment
        has not been completed. */
     $order->setState(Mage::getStoreConfig('payment/vtweb/'), true, 'New order, waiting for payment.');
     $order->sendNewOrderEmail();
     $order->setEmailSent(true);
     $payment_type = Mage::getStoreConfig('payment/vtweb/payment_types');
     $enable_installment = Mage::getStoreConfig('payment/vtweb/enable_installment');
     $is_enabled_bni = Mage::getStoreConfig('payment/vtweb/enable_installment_bni');
     $is_enabled_mandiri = Mage::getStoreConfig('payment/vtweb/enable_installment_mandiri');
     $bin_list = Mage::getStoreConfig('payment/vtwebbin/bin_number_list');
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtweb/environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtweb/server_key_v2');
     Veritrans_Config::$is3ds = Mage::getStoreConfig('payment/vtweb/enable_3d_secure') == '1' ? true : false;
     Veritrans_Config::$isSanitized = Mage::getStoreConfig('payment/vtweb/enable_sanitized') == '1' ? true : false;
     $transaction_details = array();
     $transaction_details['order_id'] = $orderIncrementId;
     $order_billing_address = $order->getBillingAddress();
     $billing_address = array();
     $billing_address['first_name'] = $order_billing_address->getFirstname();
     $billing_address['last_name'] = $order_billing_address->getLastname();
     $billing_address['address'] = $order_billing_address->getStreet(1);
     $billing_address['city'] = $order_billing_address->getCity();
     $billing_address['postal_code'] = $order_billing_address->getPostcode();
     $billing_address['country_code'] = $this->convert_country_code($order_billing_address->getCountry());
     $billing_address['phone'] = $order_billing_address->getTelephone();
     $order_shipping_address = $order->getShippingAddress();
     $shipping_address = array();
     $shipping_address['first_name'] = $order_shipping_address->getFirstname();
     $shipping_address['last_name'] = $order_shipping_address->getLastname();
     $shipping_address['address'] = $order_shipping_address->getStreet(1);
     $shipping_address['city'] = $order_shipping_address->getCity();
     $shipping_address['postal_code'] = $order_shipping_address->getPostcode();
     $shipping_address['phone'] = $order_shipping_address->getTelephone();
     $shipping_address['country_code'] = $this->convert_country_code($order_shipping_address->getCountry());
     $customer_details = array();
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $shipping_address;
     $customer_details['first_name'] = $order_billing_address->getFirstname();
     $customer_details['last_name'] = $order_billing_address->getLastname();
     $customer_details['email'] = $order_billing_address->getEmail();
     $customer_details['phone'] = $order_billing_address->getTelephone();
     $items = $order->getAllItems();
     $shipping_amount = $order->getShippingAmount();
     $shipping_tax_amount = $order->getShippingTaxAmount();
     $tax_amount = $order->getTaxAmount();
     $item_details = array();
     foreach ($items as $each) {
         $item = array('id' => $each->getProductId(), 'price' => $each->getPrice(), 'quantity' => $each->getQtyToInvoice(), 'name' => $each->getName());
         if ($item['quantity'] == 0) {
             continue;
         }
         // error_log(print_r($each->getProductOptions(), true));
         $item_details[] = $item;
     }
     $num_products = count($item_details);
     unset($each);
     if ($order->getDiscountAmount() != 0) {
         $couponItem = array('id' => 'DISCOUNT', 'price' => $order->getDiscountAmount(), 'quantity' => 1, 'name' => 'DISCOUNT');
         $item_details[] = $couponItem;
     }
     if ($shipping_amount > 0) {
         $shipping_item = array('id' => 'SHIPPING', 'price' => $shipping_amount, 'quantity' => 1, 'name' => 'Shipping Cost');
         $item_details[] = $shipping_item;
     }
     if ($shipping_tax_amount > 0) {
         $shipping_tax_item = array('id' => 'SHIPPING_TAX', 'price' => $shipping_tax_amount, 'quantity' => 1, 'name' => 'Shipping Tax');
         $item_details[] = $shipping_tax_item;
     }
     if ($tax_amount > 0) {
         $tax_item = array('id' => 'TAX', 'price' => $tax_amount, 'quantity' => 1, 'name' => 'Tax');
         $item_details[] = $tax_item;
     }
     // convert to IDR
     $current_currency = Mage::app()->getStore()->getCurrentCurrencyCode();
     if ($current_currency != 'IDR') {
         $conversion_func = function ($non_idr_price) {
             return $non_idr_price * Mage::getStoreConfig('payment/vtweb/conversion_rate');
         };
         foreach ($item_details as &$item) {
             $item['price'] = intval(round(call_user_func($conversion_func, $item['price'])));
         }
         unset($item);
     } else {
         foreach ($item_details as &$each) {
             $each['price'] = (int) $each['price'];
         }
         unset($each);
     }
     $payloads = array();
     $payloads['transaction_details'] = $transaction_details;
     $payloads['item_details'] = $item_details;
     $payloads['customer_details'] = $customer_details;
     $payloads['vtweb'] = array('enabled_payments' => 'credit_card');
     $isWarning = false;
     $isInstallment = false;
     $totalPrice = 0;
     foreach ($item_details as $item) {
         $totalPrice += $item['price'] * $item['quantity'];
     }
     $bin_list = Mage::getStoreConfig('payment/vtwebbin/bin_number_list');
     if ($bin_list) {
         $bin_list_array = explode(',', $bin_list);
         $payloads['vtweb']['credit_card_bins'] = $bin_list_array;
         Mage::log('bin list = ' . print_r($bin_list_array, true), null, 'vtweb.log', true);
     }
     //Mage::log('payloads:'.print_r($payloads,true),null,'vtweb.log',true);
     try {
         $redirUrl = Veritrans_VtWeb::getRedirectionUrl($payloads);
         if ($isWarning) {
             $this->_getCheckout()->setMsg($redirUrl);
             $this->_redirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'vtweb/paymentwarning/warning/message/1');
         } else {
             if ($totalPrice < 500000 && $isInstallment) {
                 $this->_getCheckout()->setMsg($redirUrl);
                 $this->_redirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'vtweb/paymentwarning/warning/message/2');
             } else {
                 $this->_redirectUrl($redirUrl);
             }
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
         Mage::log('error:' . print_r($e->getMessage(), true), null, 'vtweb.log', true);
     }
 }
 public function redirectAction()
 {
     $orderIncrementId = $this->_getCheckout()->getLastRealOrderId();
     $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
     $sessionId = Mage::getSingleton('core/session');
     /* send an order email when redirecting to payment page although payment
        has not been completed. */
     $order->setState(Mage::getStoreConfig('payment/vtweb/'), true, 'New order, waiting for payment.');
     $order->sendNewOrderEmail();
     $order->setEmailSent(true);
     $api_version = Mage::getStoreConfig('payment/vtweb/api_version');
     $payment_type = Mage::getStoreConfig('payment/vtweb/payment_types');
     $enable_installment = Mage::getStoreConfig('payment/vtweb/enable_installment');
     $is_enabled_bni = Mage::getStoreConfig('payment/vtweb/enable_installment_bni');
     $is_enabled_mandiri = Mage::getStoreConfig('payment/vtweb/enable_installment_mandiri');
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtweb/environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtweb/server_key_v2');
     Veritrans_Config::$is3ds = Mage::getStoreConfig('payment/vtweb/enable_3d_secure') == '1' ? true : false;
     Veritrans_Config::$isSanitized = Mage::getStoreConfig('payment/vtweb/enable_sanitized') == '1' ? true : false;
     $transaction_details = array();
     $transaction_details['order_id'] = $orderIncrementId;
     $order_billing_address = $order->getBillingAddress();
     $billing_address = array();
     $billing_address['first_name'] = $order_billing_address->getFirstname();
     $billing_address['last_name'] = $order_billing_address->getLastname();
     $billing_address['address'] = $order_billing_address->getStreet(1);
     $billing_address['city'] = $order_billing_address->getCity();
     $billing_address['postal_code'] = $order_billing_address->getPostcode();
     $billing_address['country_code'] = $this->convert_country_code($order_billing_address->getCountry());
     $billing_address['phone'] = $order_billing_address->getTelephone();
     $order_shipping_address = $order->getShippingAddress();
     $shipping_address = array();
     $shipping_address['first_name'] = $order_shipping_address->getFirstname();
     $shipping_address['last_name'] = $order_shipping_address->getLastname();
     $shipping_address['address'] = $order_shipping_address->getStreet(1);
     $shipping_address['city'] = $order_shipping_address->getCity();
     $shipping_address['postal_code'] = $order_shipping_address->getPostcode();
     $shipping_address['phone'] = $order_shipping_address->getTelephone();
     $shipping_address['country_code'] = $this->convert_country_code($order_shipping_address->getCountry());
     $customer_details = array();
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $shipping_address;
     $customer_details['first_name'] = $order_billing_address->getFirstname();
     $customer_details['last_name'] = $order_billing_address->getLastname();
     $customer_details['email'] = $order_billing_address->getEmail();
     $customer_details['phone'] = $order_billing_address->getTelephone();
     $items = $order->getAllItems();
     $shipping_amount = $order->getShippingAmount();
     $shipping_tax_amount = $order->getShippingTaxAmount();
     $tax_amount = $order->getTaxAmount();
     $item_details = array();
     foreach ($items as $each) {
         $item = array('id' => $each->getProductId(), 'price' => $each->getPrice(), 'quantity' => $each->getQtyToInvoice(), 'name' => $each->getName());
         if ($item['quantity'] == 0) {
             continue;
         }
         // error_log(print_r($each->getProductOptions(), true));
         $item_details[] = $item;
     }
     $num_products = count($item_details);
     unset($each);
     if ($order->getDiscountAmount() != 0) {
         $couponItem = array('id' => 'DISCOUNT', 'price' => $order->getDiscountAmount(), 'quantity' => 1, 'name' => 'DISCOUNT');
         $item_details[] = $couponItem;
     }
     if ($shipping_amount > 0) {
         $shipping_item = array('id' => 'SHIPPING', 'price' => $shipping_amount, 'quantity' => 1, 'name' => 'Shipping Cost');
         $item_details[] = $shipping_item;
     }
     if ($shipping_tax_amount > 0) {
         $shipping_tax_item = array('id' => 'SHIPPING_TAX', 'price' => $shipping_tax_amount, 'quantity' => 1, 'name' => 'Shipping Tax');
         $item_details[] = $shipping_tax_item;
     }
     if ($tax_amount > 0) {
         $tax_item = array('id' => 'TAX', 'price' => $tax_amount, 'quantity' => 1, 'name' => 'Tax');
         $item_details[] = $tax_item;
     }
     // convert to IDR
     $current_currency = Mage::app()->getStore()->getCurrentCurrencyCode();
     if ($current_currency != 'IDR') {
         $conversion_func = function ($non_idr_price) {
             return $non_idr_price * Mage::getStoreConfig('payment/vtweb/conversion_rate');
         };
         foreach ($item_details as &$item) {
             $item['price'] = intval(round(call_user_func($conversion_func, $item['price'])));
         }
         unset($item);
     } else {
         foreach ($item_details as &$each) {
             $each['price'] = (int) $each['price'];
         }
         unset($each);
     }
     $list_enable_payments = array();
     if (Mage::getStoreConfig('payment/vtweb/enable_creditcard') == '1') {
         $list_enable_payments[] = 'credit_card';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_cimbclick') == '1') {
         $list_enable_payments[] = 'cimb_clicks';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_mandiriclickpay') == '1') {
         $list_enable_payments[] = 'mandiri_clickpay';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_permatava') == '1') {
         $list_enable_payments[] = 'bank_transfer';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_briepay') == '1') {
         $list_enable_payments[] = 'bri_epay';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_tcash') == '1') {
         $list_enable_payments[] = 'telkomsel_cash';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_xltunai') == '1') {
         $list_enable_payments[] = 'xl_tunai';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_mandiribill') == '1') {
         $list_enable_payments[] = 'echannel';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_bbmmoney') == '1') {
         $list_enable_payments[] = 'bbm_money';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_indomaret') == '1') {
         $list_enable_payments[] = 'cstore';
     }
     if (Mage::getStoreConfig('payment/vtweb/enable_dompetku') == '1') {
         $list_enable_payments[] = 'indosat_dompetku';
     }
     $payloads = array();
     $payloads['transaction_details'] = $transaction_details;
     $payloads['item_details'] = $item_details;
     $payloads['customer_details'] = $customer_details;
     $payloads['vtweb'] = array('enabled_payments' => $list_enable_payments);
     $isWarning = false;
     $isInstallment = false;
     $totalPrice = 0;
     foreach ($item_details as $item) {
         $totalPrice += $item['price'] * $item['quantity'];
     }
     if ($enable_installment == 'allProducts') {
         $installment_terms = array();
         if ($is_enabled_bni == 1) {
             $bni_term = Mage::getStoreConfig('payment/vtweb/installment_bni_term');
             $bni_term_array = explode(',', $bni_term);
             if (strlen($bni_term) != 0) {
                 $isInstallment = true;
                 $installment_terms['bni'] = $bni_term_array;
             }
         }
         if ($is_enabled_mandiri == 1) {
             $mandiri_term = Mage::getStoreConfig('payment/vtweb/installment_mandiri_term');
             $mandiri_term_array = explode(',', $mandiri_term);
             if (strlen($mandiri_term) != 0) {
                 $isInstallment = true;
                 $installment_terms['mandiri'] = $mandiri_term_array;
             }
         }
         $payment_options = array('installment' => array('required' => false, 'installment_terms' => $installment_terms));
         if ($isInstallment && $totalPrice >= 500000) {
             $payloads['vtweb']['payment_options'] = $payment_options;
         }
     } else {
         if ($enable_installment == 'certainProducts') {
             if ($num_products == 1) {
                 $productOptions = $items[0]->getProductOptions();
                 if (array_key_exists('attributes_info', $productOptions)) {
                     foreach ($productOptions['attributes_info'] as $attribute) {
                         if (in_array('Payment', $attribute)) {
                             $installment_value = explode(',', $attribute['value']);
                             if (strtolower($installment_value[0]) == 'installment') {
                                 $installment_terms = array();
                                 $installment_terms[strtolower($installment_value[1])] = array($installment_value[2]);
                                 $payment_options = array('installment' => array('required' => true, 'installment_terms' => $installment_terms));
                                 $isInstallment = true;
                                 if ($totalPrice >= 500000) {
                                     $payloads['vtweb']['payment_options'] = $payment_options;
                                 }
                             }
                         }
                     }
                     unset($attribute);
                 }
             } else {
                 foreach ($items as $each) {
                     $productOptions = $each->getProductOptions();
                     if (array_key_exists('attributes_info', $productOptions)) {
                         foreach ($productOptions['attributes_info'] as $attribute) {
                             if (in_array('Payment', $attribute)) {
                                 $installment_value = explode(',', $attribute['value']);
                                 if (strtolower($installment_value[0]) == 'installment') {
                                     $isWarning = true;
                                 }
                             }
                         }
                     }
                 }
                 unset($each);
             }
         }
     }
     try {
         $redirUrl = Veritrans_VtWeb::getRedirectionUrl($payloads);
         if ($isWarning) {
             $this->_getCheckout()->setMsg($redirUrl);
             $this->_redirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'vtweb/paymentwarning/warning/message/1');
         } else {
             if ($totalPrice < 500000 && $isInstallment) {
                 $this->_getCheckout()->setMsg($redirUrl);
                 $this->_redirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'vtweb/paymentwarning/warning/message/2');
             } else {
                 $this->_redirectUrl($redirUrl);
             }
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
         Mage::log('error:' . print_r($e->getMessage(), true), null, 'vtweb.log', true);
     }
 }
예제 #9
0
 function plgVmConfirmedOrder($cart, $order)
 {
     // error_log('plgVmConfirmedOrder'); // debug purpose
     if (!($this->_currentMethod = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {
         return NULL;
         // Another method was selected, do nothing
     }
     if (!$this->selectedThisElement($this->_currentMethod->payment_element)) {
         return FALSE;
     }
     $interface = $this->_loadVeritransInterface($this);
     // DONE function
     $interface->setOrder($order);
     $interface->setCart($cart);
     $this->getPaymentCurrency($this->_currentMethod);
     $interface->setTotal($order['details']['BT']->order_total);
     $this->logInfo('plgVmConfirmedOrder order number: ' . $order['details']['BT']->order_number, 'message');
     $subscribe_id = NULL;
     if (!class_exists('VirtueMartModelOrders')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php';
     }
     if (!class_exists('VirtueMartModelCurrency')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'currency.php';
     }
     $email_currency = $this->getEmailCurrency($this->_currentMethod);
     // TODO save to DB!
     // Prepare data that should be stored in the database
     // $dbValues['order_number'] = $order['details']['BT']->order_number;
     // $dbValues['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id;
     // $dbValues['payment_name'] = $this->renderPluginName($this->_currentMethod);
     // $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id;
     // $dbValues['klikandpay_custom'] = $this->getContext();
     // $dbValues['cost_per_transaction'] = $this->_currentMethod->cost_per_transaction;
     // $dbValues['cost_percent_total'] = $this->_currentMethod->cost_percent_total;
     // $dbValues['payment_currency'] = $this->_currentMethod->payment_currency;
     // $dbValues['email_currency'] = $email_currency;
     // $dbValues['payment_order_total'] = $post_variables["MONTANT"];
     // $dbValues['tax_id'] = $this->_currentMethod->tax_id;
     // $this->storePSPluginInternalData($dbValues);
     // Set our server key
     Veritrans_Config::$serverKey = $this->_currentMethod->serverkey;
     Veritrans_Config::$isProduction = $this->_currentMethod->shop_mode == 'test' ? FALSE : TRUE;
     Veritrans_Config::$is3ds = $this->_currentMethod->is3ds ? TRUE : FALSE;
     if ($this->_currentMethod->credit_card) {
         $payements_type[] = 'credit_card';
     }
     if ($this->_currentMethod->mandiri_clickpay) {
         $payements_type[] = 'mandiri_clickpay';
     }
     if ($this->_currentMethod->cimb_clicks) {
         $payements_type[] = 'cimb_clicks';
     }
     if ($this->_currentMethod->bank_transfer) {
         $payements_type[] = 'bank_transfer';
     }
     if ($this->_currentMethod->bri_epay) {
         $payements_type[] = 'bri_epay';
     }
     if ($this->_currentMethod->telkomsel_cash) {
         $payements_type[] = 'telkomsel_cash';
     }
     if ($this->_currentMethod->xl_tunai) {
         $payements_type[] = 'xl_tunai';
     }
     if ($this->_currentMethod->echannel) {
         $payements_type[] = 'echannel';
     }
     if ($this->_currentMethod->bbm_money) {
         $payements_type[] = 'bbm_money';
     }
     if ($this->_currentMethod->cstore) {
         $payements_type[] = 'cstore';
     }
     if ($this->_currentMethod->credit_card) {
         $payements_type[] = 'indosat_dompetku';
     }
     $conversion_rate = floatval($this->_currentMethod->conversion_rate);
     if (!isset($conversion_rate) or $conversion_rate = '' or $conversion_rate = '1') {
         $conversion_rate = 1;
     }
     $gross_amount = 0;
     $items_details = array();
     //push item to item details array
     foreach ($order['items'] as $line_item_wrapper) {
         $item = array();
         $line_item_price = $line_item_wrapper->product_final_price;
         $item['id'] = $line_item_wrapper->virtuemart_order_item_id;
         $item['quantity'] = $line_item_wrapper->product_quantity;
         $item['price'] = ceil($line_item_price * $conversion_rate);
         $item['name'] = $line_item_wrapper->order_item_name;
         $items_details[] = $item;
         $gross_amount += $item['price'] * $item['quantity'];
     }
     //push shipment & shipment tax to item details
     $item = array();
     $item['id'] = 'sp';
     $item['quantity'] = 1;
     $item['price'] = ceil(($order['details']['BT']->order_shipment + $order['details']['BT']->order_shipment_tax) * $conversion_rate);
     $item['name'] = "Shipment & Shipment tax";
     $items_details[] = $item;
     $gross_amount += $item['price'] * $item['quantity'];
     //push discount to item details
     $item = array();
     $item['id'] = 'dc';
     $item['quantity'] = 1;
     $item['price'] = -(ceil($order['details']['BT']->coupon_discount) * $conversion_rate);
     $item['name'] = "Coupon Discount";
     $items_details[] = $item;
     $gross_amount += $item['price'] * $item['quantity'];
     // Billing name
     $fname = $order['details']['BT']->first_name;
     if (isset($order['details']['BT']->middle_name) and $order['details']['BT']->middle_name) {
         $fname .= $order['details']['BT']->middle_name;
     }
     $lname = $order['details']['BT']->last_name;
     $address = $order['details']['BT']->address_1;
     if (isset($order['details']['BT']->address_2) and $order['details']['BT']->address_2) {
         $address .= $order['details']['BT']->address_2;
     }
     // check if both phone field filled, append both
     $appender = '';
     if (isset($order['details']['BT']->phone_1) && isset($order['details']['BT']->phone_2)) {
         $appender = ', ';
     }
     // Fill transaction data
     // /index.php?option=com_virtuemart&view=vmplg&task=pluginUserPaymentCancel
     $finish_url = JURI::root() . 'index.php?option=com_virtuemart&view=vmplg&task=pluginresponsereceived&';
     $back_url = JURI::root() . 'index.php?option=com_virtuemart&view=vmplg&task=pluginUserPaymentCancel&';
     // error_log($back_url);  // debug purpose
     $transaction = array("vtweb" => array('finish_redirect_url' => $finish_url, 'unfinish_redirect_url' => $back_url, 'error_redirect_url' => $back_url, 'enabled_payments' => $payements_type), 'transaction_details' => array('order_id' => $order['details']['BT']->virtuemart_order_id, 'gross_amount' => $gross_amount), 'item_details' => $items_details, 'customer_details' => array('first_name' => $fname, 'last_name' => $lname, 'email' => $order['details']['BT']->email, 'phone' => $order['details']['BT']->phone_1, 'billing_address' => array('first_name' => $fname, 'last_name' => $lname, 'address' => $address, 'city' => $order['details']['BT']->city, 'postal_code' => $order['details']['BT']->zip, 'phone' => $order['details']['BT']->phone_1 . $appender . $order['details']['BT']->phone_2)));
     // Add shipment details if exists
     if (array_key_exists('ST', $order['details'])) {
         // check if both phone field filled, append both
         $appender = '';
         if (isset($order['details']['ST']->phone_1) && isset($order['details']['ST']->phone_2)) {
             $appender = ', ';
         }
         // Shipping name
         $sfname = $order['details']['ST']->first_name;
         if (isset($order['details']['ST']->middle_name) and $order['details']['ST']->middle_name) {
             $sfname .= $order['details']['ST']->middle_name;
         }
         $slname = $order['details']['ST']->last_name;
         $saddress = $order['details']['ST']->address_1;
         if (isset($order['details']['ST']->address_2) and $order['details']['ST']->address_2) {
             $saddress .= $order['details']['ST']->address_2;
         }
         $shipping_address = array('first_name' => $sfname, 'last_name' => $slname, 'address' => $saddress, 'city' => $order['details']['ST']->city, 'postal_code' => $order['details']['ST']->zip, 'phone' => $order['details']['ST']->phone_1 . $appender . $order['details']['ST']->phone_2);
         $transaction['customer_details']['shipping_address'] = $shipping_address;
     }
     // error_log('$transaction = '.print_r($transaction,true)); // debug purpose
     $vtweb_url = Veritrans_Vtweb::getRedirectionUrl($transaction);
     $html = $this->getConfirmedHtml($vtweb_url, $interface, $subscribe_id);
     // 	2 = don't delete the cart, don't send email and don't redirect
     $cart->_confirmDone = FALSE;
     $cart->_dataValidated = FALSE;
     $cart->setCartIntoSession();
     vRequest::setVar('display_title', false);
     vRequest::setVar('html', $html);
     // $this->emptyCart();
     header("Location: " . $vtweb_url);
     return;
 }
예제 #10
0
/**
 * Get Enabled Payment from backend settings
 * @return array $enabled_payment
 **/
function edd_get_vtpayment_ops()
{
    global $edd_options;
    //get 3ds opts from backend
    Veritrans_Config::$is3ds = $edd_options['vt_3ds'] ? true : false;
    // error_log('vt_3ds '.$edd_options['vt_3ds']); //debugan
    // error_log('credit_card '.$edd_options['vt_credit_card']); //debugan
    $enabled_payments = array();
    if ($edd_options['vt_credit_card']) {
        $enabled_payments[] = 'credit_card';
        // error_log('masuk cc '.$edd_options['credit_card']); //debugan
    }
    if ($edd_options['vt_mandiri_clickpay']) {
        $enabled_payments[] = 'mandiri_clickpay';
    }
    if ($edd_options['vt_cimb_clicks']) {
        $enabled_payments[] = 'cimb_clicks';
    }
    if ($edd_options['vt_bank_transfer']) {
        $enabled_payments[] = 'bank_transfer';
    }
    if ($edd_options['vt_bri_epay']) {
        $enabled_payments[] = 'bri_epay';
    }
    if ($edd_options['vt_telkomsel_cash']) {
        $enabled_payments[] = 'telkomsel_cash';
    }
    if ($edd_options['vt_xl_tunai']) {
        $enabled_payments[] = 'xl_tunai';
    }
    if ($edd_options['vt_echannel']) {
        $enabled_payments[] = 'echannel';
    }
    if ($edd_options['vt_bbm_money']) {
        $enabled_payments[] = 'bbm_money';
    }
    if ($edd_options['vt_cstore']) {
        $enabled_payments[] = 'cstore';
    }
    if ($edd_options['vt_indosat_dompetku']) {
        $enabled_payments[] = 'indosat_dompetku';
    }
    // error_log('enabled payments array'.print_r($enabled_payments,true)); //debugan
    return $enabled_payments;
}
 public function redirectAction()
 {
     $orderIncrementId = $this->_getCheckout()->getLastRealOrderId();
     $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
     $sessionId = Mage::getSingleton('core/session');
     /* send an order email when redirecting to payment page although payment
        has not been completed. */
     $order->setState(Mage::getStoreConfig('payment/vtweb/'), true, 'New order, waiting for payment.');
     $order->sendNewOrderEmail();
     $order->setEmailSent(true);
     $enable_installment = Mage::getStoreConfig('payment/vtwebio/enable_installment');
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtweb/environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtweb/server_key_v2');
     Veritrans_Config::$is3ds = true;
     Veritrans_Config::$isSanitized = Mage::getStoreConfig('payment/vtweb/enable_sanitized') == '1' ? true : false;
     $transaction_details = array();
     $transaction_details['order_id'] = $orderIncrementId;
     $order_billing_address = $order->getBillingAddress();
     $billing_address = array();
     $billing_address['first_name'] = $order_billing_address->getFirstname();
     $billing_address['last_name'] = $order_billing_address->getLastname();
     $billing_address['address'] = $order_billing_address->getStreet(1);
     $billing_address['city'] = $order_billing_address->getCity();
     $billing_address['postal_code'] = $order_billing_address->getPostcode();
     $billing_address['country_code'] = $this->convert_country_code($order_billing_address->getCountry());
     $billing_address['phone'] = $order_billing_address->getTelephone();
     $order_shipping_address = $order->getShippingAddress();
     $shipping_address = array();
     $shipping_address['first_name'] = $order_shipping_address->getFirstname();
     $shipping_address['last_name'] = $order_shipping_address->getLastname();
     $shipping_address['address'] = $order_shipping_address->getStreet(1);
     $shipping_address['city'] = $order_shipping_address->getCity();
     $shipping_address['postal_code'] = $order_shipping_address->getPostcode();
     $shipping_address['phone'] = $order_shipping_address->getTelephone();
     $shipping_address['country_code'] = $this->convert_country_code($order_shipping_address->getCountry());
     $customer_details = array();
     $customer_details['billing_address'] = $billing_address;
     $customer_details['shipping_address'] = $shipping_address;
     $customer_details['first_name'] = $order_billing_address->getFirstname();
     $customer_details['last_name'] = $order_billing_address->getLastname();
     $customer_details['email'] = $order_billing_address->getEmail();
     $customer_details['phone'] = $order_billing_address->getTelephone();
     $items = $order->getAllItems();
     $shipping_amount = $order->getShippingAmount();
     $shipping_tax_amount = $order->getShippingTaxAmount();
     $tax_amount = $order->getTaxAmount();
     $item_details = array();
     foreach ($items as $each) {
         $item = array('id' => $each->getProductId(), 'price' => $each->getPrice(), 'quantity' => $each->getQtyToInvoice(), 'name' => $each->getName());
         if ($item['quantity'] == 0) {
             continue;
         }
         // error_log(print_r($each->getProductOptions(), true));
         $item_details[] = $item;
     }
     $num_products = count($item_details);
     unset($each);
     if ($order->getDiscountAmount() != 0) {
         $couponItem = array('id' => 'DISCOUNT', 'price' => $order->getDiscountAmount(), 'quantity' => 1, 'name' => 'DISCOUNT');
         $item_details[] = $couponItem;
     }
     if ($shipping_amount > 0) {
         $shipping_item = array('id' => 'SHIPPING', 'price' => $shipping_amount, 'quantity' => 1, 'name' => 'Shipping Cost');
         $item_details[] = $shipping_item;
     }
     if ($shipping_tax_amount > 0) {
         $shipping_tax_item = array('id' => 'SHIPPING_TAX', 'price' => $shipping_tax_amount, 'quantity' => 1, 'name' => 'Shipping Tax');
         $item_details[] = $shipping_tax_item;
     }
     if ($tax_amount > 0) {
         $tax_item = array('id' => 'TAX', 'price' => $tax_amount, 'quantity' => 1, 'name' => 'Tax');
         $item_details[] = $tax_item;
     }
     // convert to IDR
     $current_currency = Mage::app()->getStore()->getCurrentCurrencyCode();
     if ($current_currency != 'IDR') {
         $conversion_func = function ($non_idr_price) {
             return $non_idr_price * Mage::getStoreConfig('payment/vtweb/conversion_rate');
         };
         foreach ($item_details as &$item) {
             $item['price'] = intval(round(call_user_func($conversion_func, $item['price'])));
         }
         unset($item);
     } else {
         foreach ($item_details as &$each) {
             $each['price'] = (int) $each['price'];
         }
         unset($each);
     }
     $payloads = array();
     $payloads['transaction_details'] = $transaction_details;
     $payloads['item_details'] = $item_details;
     $payloads['customer_details'] = $customer_details;
     $payloads['vtweb'] = array('enabled_payments' => 'credit_card');
     $isWarning = false;
     $isInstallment = false;
     $totalPrice = 0;
     $threshold = Mage::getStoreConfig('payment/vtwebio/threshold');
     Mage::log('$threshold = ' . print_r($threshold, true), null, 'vtwebmandiri.log', true);
     foreach ($item_details as $item) {
         $totalPrice += $item['price'] * $item['quantity'];
     }
     $bin_list = Mage::getStoreConfig('payment/vtwebio/bin_number_list');
     if ($bin_list) {
         $bin_list_array = explode(',', $bin_list);
         $payloads['vtweb']['credit_card_bins'] = $bin_list_array;
         Mage::log('bin list = ' . print_r($bin_list_array, true), null, 'vtwebio.log', true);
     }
     $installment_terms = Mage::getStoreConfig('payment/vtwebio/installment_term');
     $installment_terms = explode(',', $installment_terms);
     $payment_options = array('installment' => array('required' => true, 'installment_terms' => new stdClass(), 'offline_installment_terms' => $installment_terms));
     if ($totalPrice >= $threshold) {
         $payloads['vtweb']['payment_options'] = $payment_options;
     }
     /*    if ($enable_installment == 'allProducts') {
           $installment_terms = array();
           
             $mandiri_term = Mage::getStoreConfig('payment/vtwebmandiri/installment_mandiri_term');
             $mandiri_term_array = explode(',', $mandiri_term);
             
             if (strlen($mandiri_term) != 0) {
               $isInstallment = true;
               $installment_terms['mandiri'] = $mandiri_term_array;
             }
                   // Mage::log('masuk allProducts \n installement terms:'.print_r($installment_terms,true),null,'vtwebmandiri.log',true); //debugan
     
           $payment_options = array(
             'installment' => array(
               'required' => true,
               'installment_terms' => $installment_terms
             )
           );
     
           if ($isInstallment && ($totalPrice >= $threshold )) {
             $payloads['vtweb']['payment_options'] = $payment_options;
           }
           else{
              $payloads['vtweb'] = array('enabled_payments'=> $this->enable_payment());
           }
         }
         else if ($enable_installment == 'certainProducts') {
           if ($num_products == 1) {
             $productOptions = $items[0]->getProductOptions();
             // Mage::log('productOptions:'.print_r($productOptions,true),null,'vtwebmandiri.log',true); //debug
     
     
            if (array_key_exists('attributes_info', $productOptions)) {
               foreach ($productOptions['attributes_info'] as $attribute) {
                 if (in_array('Payment', $attribute)) {
                   $installment_value = explode(' ', $attribute['value']);
     
                   if (strtolower($installment_value[0]) == 'installment') {
                     $installment_terms = array();
                     $installment_terms[strtolower($installment_value[1])] = array($installment_value[2]);
     
                     if (strtolower($installment_value[1]) == 'bni') {
                       Veritrans_Config::$is3ds = false;
                     } else {
                       Veritrans_Config::$is3ds = true;
                     }
     
                     $payment_options = array(
                       'installment' => array(
                         'required' => true,
                         'installment_terms' => $installment_terms
                       )
                     );
     
                     $isInstallment = true;
     
                     if ($totalPrice >= $threshold ) {
                       $payloads['vtweb']['payment_options'] = $payment_options;
                     }
                     else{
                        $payloads['vtweb'] = array('enabled_payments'=> $this->enable_payment());
                     }
                   }
                 }
               }
     
               unset($attribute);
             }
           }
           else {
             foreach ($items as $each) {
               $productOptions = $each->getProductOptions();
     
               if (array_key_exists('attributes_info', $productOptions)) {
                 foreach ($productOptions['attributes_info'] as $attribute) {
                   if (in_array('Payment', $attribute)) {
                     $installment_value = explode(' ', $attribute['value']);
     
                     if (strtolower($installment_value[0]) == 'installment') {
                       $isWarning = true;
                     }
                   }
                 }
               }
             }
     
             unset($each);
           }
         }*/
     error_log(print_r($payloads, TRUE));
     try {
         $redirUrl = Veritrans_VtWeb::getRedirectionUrl($payloads);
         error_log($redirUrl);
         if ($isWarning) {
             $this->_getCheckout()->setMsg($redirUrl);
             $this->_redirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'vtwebio/paymentwarning/warning/message/1');
         } else {
             if ($totalPrice < $threshold) {
                 $this->_getCheckout()->setMsg($redirUrl);
                 $this->_redirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . 'vtwebio/paymentwarning/warning/message/2');
             } else {
                 $this->_redirectUrl($redirUrl);
             }
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
         Mage::log('error:' . print_r($e->getMessage(), true), null, 'vtwebio.log', true);
     }
 }
예제 #12
0
 function pay()
 {
     $app_id = addslashes($_GET['app_id']);
     $app = new AppAccount();
     $app->getByID($app_id);
     AppAccount::checkOwnership($app);
     $paket_id = addslashes($_GET['paket']);
     $paket = new Paket();
     $paket->getByID($paket_id);
     global $db;
     //create new order
     $vpt = new VpTransaction();
     $vpt->order_id = mt_rand() . $app->app_id . Account::getMyID();
     $vpt->order_acc_id = Account::getMyID();
     $vpt->order_app_id = $app->app_id;
     $vpt->order_date = leap_mysqldate();
     $vpt->order_paket_id = $paket->paket_id;
     $vpt->order_value = $paket->paket_price;
     $vpt->order_status = 0;
     $vpt->order_status_from = 0;
     //hapus yang blom ada action apa2
     $q = "DELETE FROM {$vpt->table_name} WHERE order_app_id = '{$app->app_id}' AND order_status = '0' AND order_status_from = '0'";
     $db->query($q, 0);
     $arrVpt = $vpt->getWhere("order_app_id = '{$app->app_id}' AND order_status = '0' AND order_status_from != '0' ");
     if (count($arrVpt) > 0) {
         die("Please wait for the payment response");
     }
     if ($vpt->save()) {
         //        pr($paket);
         //        pr($app);
         try {
             // Set our server key
             //live
             //            Veritrans_Config::$serverKey = 'VT-server-3UfrS7tn0EDT99S2B18TnUh_';
             //sandbox
             Veritrans_Config::$serverKey = $this->getKeyUsed();
         } catch (Exception $e) {
             echo $e->getMessage();
         }
         if ($this->isProd) {
             // Uncomment for production environment
             Veritrans_Config::$isProduction = true;
             // Uncomment to enable sanitization
             Veritrans_Config::$isSanitized = true;
             // Uncomment to enable 3D-Secure
             Veritrans_Config::$is3ds = true;
         }
         $acc = Account::getAccountObject();
         $exp = explode(" ", $acc->admin_nama_depan);
         $billing_address = array('first_name' => $exp[0], 'last_name' => $exp[1], 'phone' => $acc->admin_phone, 'country_code' => 'IDN');
         $customer_details = array('first_name' => $exp[0], 'last_name' => $exp[1], 'email' => $acc->admin_email, 'phone' => $acc->admin_phone, 'billing_address' => $billing_address);
         $item1_details = array('id' => $app->app_id, 'price' => $paket->paket_price, 'quantity' => 1, 'name' => $app->app_name . " " . $paket->paket_name . " 1 year");
         $item_details = array($item1_details);
         $transaction = array('transaction_details' => array('order_id' => $vpt->order_id, 'gross_amount' => $paket->paket_price), 'customer_details' => $customer_details, 'item_details' => $item_details);
         try {
             // Redirect to Veritrans VTWeb page
             header('Location: ' . Veritrans_VtWeb::getRedirectionUrl($transaction));
         } catch (Exception $e) {
             echo $e->getMessage();
             if (strpos($e->getMessage(), "Access denied due to unauthorized")) {
                 echo "<code>";
                 echo "<h4>Please set real server key from sandbox</h4>";
                 echo "In file: " . __FILE__;
                 echo "<br>";
                 echo "<br>";
                 echo htmlspecialchars('Veritrans_Config::$serverKey = \'<your server key>\';');
                 die;
             }
         }
     } else {
         //if save
         die("Please contact admin");
     }
 }