public function pay(Request $request)
 {
     \Veritrans_Config::$serverKey = '597bed2a-b11c-4976-ba85-743f54fadaec';
     \Veritrans_Config::$isProduction = false;
     \Veritrans_Config::$isSanitized = false;
     // Populate customer's billing address
     $billing_address = array('first_name' => $request->input('billingFirstName'), 'last_name' => $request->input('billingLastName'), 'address' => $request->input('billingAddress'), 'city' => $request->input('billingCity'), 'postal_code' => $request->input('billingPostalCode'), 'phone' => $request->input('billingPhone'), 'country_code' => 'IDN');
     // Populate customer's shipping address
     $shipping_address = array('first_name' => $request->input('shipmentFirstName'), 'last_name' => $request->input('shipmentLastName'), 'address' => $request->input('shipmentAddress'), 'city' => $request->input('shipmentCity'), 'postal_code' => $request->input('shipmentPostalCode'), 'phone' => $request->input('shipmentPhone'), 'country_code' => 'IDN');
     // Populate customer's info
     $customer_details = array('first_name' => $request->input('customerFirstName'), 'last_name' => $request->input('customerLastName'), 'email' => $request->input('customerEmail'), 'phone' => $request->input('customerPhone'), 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
     //Detail Items
     $detailItems = [];
     foreach (Cart::content() as $item) {
         $detailItems[] = ['id' => $item->id, 'price' => $item->price, 'quantity' => $item->qty, 'name' => $item->name];
     }
     $params = array('customer_details' => $customer_details, 'item_details' => $detailItems, 'transaction_details' => array('order_id' => rand(), 'gross_amount' => Cart::total()), 'vtweb' => array('enabled_payments' => array($request->input('payment')), 'credit_card_3d_secure' => true, 'finish_redirect_url' => route('frontend.payment.finish'), 'unfinish_redirect_url' => route('frontend.payment.unFinish'), 'error_redirect_url' => route('frontend.payment.error')));
     try {
         // Redirect to Veritrans VTWeb page
         return redirect(\Veritrans_Vtweb::getRedirectionUrl($params));
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
 /**
  * Check for Veritrans Web Response
  * Method ini akan dipanggil untuk merespon notifikasi yang
  * diberikan oleh server Veritrans serta melakukan verifikasi
  * apakah notifikasi tersebut berasal dari Veritrans dan melakukan
  * konfirmasi transaksi pembayaran yang dilakukan customer
  *
  * update: sekaligus untuk menjadi finish/failed URL handler.
  * @access public
  * @return void
  */
 function veritrans_vtweb_response()
 {
     global $woocommerce;
     @ob_clean();
     global $woocommerce;
     $order = new WC_Order($order_id);
     Veritrans_Config::$isProduction = $this->environment == 'production' ? true : false;
     if ($this->environment == 'production') {
         Veritrans_Config::$serverKey = $this->server_key_v2_production;
     } else {
         Veritrans_Config::$serverKey = $this->server_key_v2_sandbox;
     }
     // check whether the request is GET or POST,
     // if request == GET, request is for finish OR failed URL, then redirect to WooCommerce's order complete/failed
     // else if request == POST, request is for payment notification, then update the payment status
     if (!isset($_GET['order_id'])) {
         // Check if POST, then create new notification
         $veritrans_notification = new Veritrans_Notification();
         if (in_array($veritrans_notification->status_code, array(200, 201, 202))) {
             header('HTTP/1.1 200 OK');
             if ($order->get_order($veritrans_notification->order_id) == true) {
                 $veritrans_confirmation = Veritrans_Transaction::status($veritrans_notification->order_id);
                 do_action("valid-veritrans-web-request", $veritrans_notification);
             }
         }
     } else {
         // else if GET, redirect to order complete/failed
         // error_log('status_code '. $_GET['status_code']); //debug
         // error_log('status_code '. $_GET['transaction_status']); //debug
         if (isset($_GET['order_id']) && isset($_GET['transaction_status']) && ($_GET['transaction_status'] == 'capture' || $_GET['transaction_status'] == 'pending' || $_GET['transaction_status'] == 'settlement')) {
             $order_id = $_GET['order_id'];
             // error_log($this->get_return_url( $order )); //debug
             $order = new WC_Order($order_id);
             wp_redirect($order->get_checkout_order_received_url());
         } else {
             if (isset($_GET['order_id']) && isset($_GET['transaction_status']) && $_GET['transaction_status'] == 'deny') {
                 $order_id = $_GET['order_id'];
                 $order = new WC_Order($order_id);
                 wp_redirect($order->get_checkout_payment_url(false));
             } else {
                 if (isset($_GET['order_id']) && !isset($_GET['transaction_status'])) {
                     // if customer click "back" button, redirect to checkout page again
                     $order_id = $_GET['order_id'];
                     $order = new WC_Order($order_id);
                     wp_redirect($order->get_checkout_payment_url(false));
                 }
             }
         }
     }
 }
 /**
  * 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();
     }
 }
 public function execNotification()
 {
     $veritrans = new Veritrans_Config();
     Veritrans_Config::$isProduction = Configuration::get('VN_ENVIRONMENT') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Configuration::get('VN_SERVER_KEY');
     $veritrans_notification = new Veritrans_Notification();
     $history = new OrderHistory();
     $history->id_order = (int) $veritrans_notification->order_id;
     //Validating order
     //if ($veritrans_notification->isVerified())
     //{
     //$history->id_order = (int)$veritrans_notification->order_id;
     //error_log('notif verified');
     //error_log('message notif: '.(int)$veritrans_notification->order_id);
     $order_id_notif = (int) $veritrans_notification->order_id;
     if ($veritrans_notification->transaction_status == 'capture') {
         if ($veritrans_notification->fraud_status == 'accept') {
             $history->changeIdOrderState(Configuration::get('VN_PAYMENT_SUCCESS_STATUS_MAP'), $order_id_notif);
             echo 'Valid success notification accepted.';
         } else {
             if ($veritrans_notification->fraud_status == 'challenge') {
                 $history->changeIdOrderState(Configuration::get('VN_PAYMENT_CHALLENGE_STATUS_MAP'), $order_id_notif);
                 echo 'Valid challenge notification accepted.';
             }
         }
     } else {
         if ($veritrans_notification->transaction_status == 'settlement') {
             if ($veritrans_notification->payment_type != 'credit_card') {
                 $history->changeIdOrderState(Configuration::get('VN_PAYMENT_SUCCESS_STATUS_MAP'), $order_id_notif);
                 echo 'Valid success notification accepted.';
             } else {
                 echo 'Credit card settlement notification accepted.';
             }
         } else {
             if ($veritrans_notification->transaction_status == 'pending') {
                 $history->changeIdOrderState(Configuration::get('VN_PAYMENT_CHALLENGE_STATUS_MAP'), $order_id_notif);
                 echo 'Pending notification accepted.';
             } else {
                 if ($veritrans_notification->transaction_status == 'cancel') {
                     $history->changeIdOrderState(Configuration::get('VN_PAYMENT_FAILURE_STATUS_MAP'), $order_id_notif);
                     echo 'Pending notification accepted.';
                 } else {
                     $history->changeIdOrderState(Configuration::get('VN_PAYMENT_FAILURE_STATUS_MAP'), $order_id_notif);
                     echo 'Valid failure notification accepted';
                 }
             }
         }
     }
     $history->add(true);
     //}
     exit;
 }
 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 notificationAction()
 {
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtweb/environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtweb/server_key_v2');
     $notif = new Veritrans_Notification();
     // Mage::log('get status result'.print_r($notif,true),null,'vtwebmandiri.log',true);
     $order = Mage::getModel('sales/order');
     $order->loadByIncrementId($notif->order_id);
     $transaction = $notif->transaction_status;
     $fraud = $notif->fraud_status;
     if ($transaction == 'capture') {
         if ($fraud == 'challenge') {
             $order->setStatus(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW);
         } else {
             if ($fraud == 'accept') {
                 $invoice = $order->prepareInvoice()->setTransactionId($order->getId())->addComment('Payment successfully processed by Veritrans.')->register()->pay();
                 $transaction_save = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
                 $transaction_save->save();
                 $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
                 $order->sendOrderUpdateEmail(true, 'Thank you, your payment is successfully processed.');
             }
         }
     } else {
         if ($transaction == 'cancel' || $transaction == 'deny') {
             $order->setStatus(Mage_Sales_Model_Order::STATE_CANCELED);
         } else {
             if ($transaction == 'settlement') {
                 $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
                 $order->sendOrderUpdateEmail(true, 'Thank you, your payment is successfully processed.');
             } else {
                 if ($transaction == 'pending') {
                     $order->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
                     $order->sendOrderUpdateEmail(true, 'Thank you, your payment is successfully processed.');
                 } else {
                     if ($transaction == 'cancel') {
                         $order->setStatus(Mage_Sales_Model_Order::STATE_CANCELED);
                     } else {
                         $order->setStatus(Mage_Sales_Model_Order::STATUS_FRAUD);
                     }
                 }
             }
         }
     }
     $order->save();
 }
Пример #7
0
 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'] = $order_billing_address->getCountry();
     $billing_address['phone'] = $this->convert_country_code($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';
     }
     $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());
     }
 }
 public function transaction()
 {
     Veritrans_Config::$serverKey = 'VT-server-tHdPoLZ5B9msOwJBt-tN7jOE';
     Veritrans_Config::$isProduction = false;
     if (Veritrans_Config::$serverKey == '<your server key>') {
         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;
     }
     $objUser = new UserModel();
     $objUser->getByID('2');
     $saved_token_id = $objUser->braintree_id;
     $transaction_details = array('order_id' => time(), 'gross_amount' => 300000);
     // Populate customer's info
     $customer_details = array('first_name' => "Andri", 'last_name' => "Litani", 'email' => "*****@*****.**", 'phone' => "081122334455");
     // Transaction data to be sent
     $transaction_data = array('payment_type' => 'credit_card', 'credit_card' => array('token_id' => $saved_token_id), 'transaction_details' => $transaction_details, 'customer_details' => $customer_details);
     try {
         $response = Veritrans_VtDirect::charge($transaction_data);
         //            pr($response);
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
 }
Пример #9
0
 /**
  * Called when Veritrans server sends notification to this server.
  * It will change order status according to transaction status and fraud
  * status sent by Veritrans server.
  */
 public function payment_notification()
 {
     header("HTTP/1.1 200 OK");
     // error_log('payment notification'); //debugan
     $this->load->model('checkout/order');
     $this->load->model('payment/veritransbin');
     Veritrans_Config::$isProduction = $this->config->get('veritransbin_environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = $this->config->get('veritransbin_server_key_v2');
     $notif = new Veritrans_Notification();
     $transaction = $notif->transaction_status;
     $fraud = $notif->fraud_status;
     $logs = '';
     if ($transaction == 'capture') {
         $logs .= 'capture ';
         if ($fraud == 'challenge') {
             $logs .= 'challenge ';
             $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_challenge_mapping'), 'VT-Web payment challenged. Please take action on ' . 'your Merchant Administration Portal.');
         } else {
             if ($fraud == 'accept') {
                 $logs .= 'accept ';
                 $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_success_mapping'), 'VT-Web payment successful.');
             }
         }
     } else {
         if ($transaction == 'cancel') {
             $logs .= 'cancel ';
             $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_failure_mapping'), 'VT-Web payment canceled.');
         } else {
             if ($transaction == 'deny') {
                 $logs .= 'deny ';
                 $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_failure_mapping'), 'VT-Web payment failed.');
             } else {
                 if ($transaction == 'pending') {
                     $logs .= 'pending ';
                     $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_challenge_mapping'), 'VT-Web payment pending.');
                 } else {
                     if ($transaction == 'settlement') {
                         $logs .= 'complete ';
                         $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_success_mapping'), 'VT-Web payment successful.');
                     } else {
                         $logs .= "*{$transaction}:{$fraud} ";
                         $this->model_checkout_order->update($notif->order_id, $this->config->get('veritransbin_vtweb_challenge_mapping'), 'VT-Web payment challenged. Please take action on ' . 'your Merchant Administration Portal.');
                     }
                 }
             }
         }
     }
     // error_log($logs); // debugan
 }
Пример #10
0
 public function redirectAction()
 {
     $orderIncrementId = $this->_getCheckout()->getLastRealOrderId();
     $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
     $sessionId = Mage::getSingleton('core/session');
     /* need to set payment data to Mage::getSingleton('checkout/session')->setPaymentData(); when checkout */
     $pay = Mage::getSingleton('core/session')->getPaymentData();
     $api_version = Mage::getStoreConfig('payment/vtvirtual/api_version');
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtvirtual/environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtvirtual/server_key_v2');
     $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();
     if (strlen($billing_address['city']) > 20) {
         $split = explode('/', $billing_address['city']);
         if (count($split) == 1) {
             $billing_address['city'] = substr($billing_address['city'], 20);
         } else {
             $billing_address['city'] = $split[1];
         }
     }
     $billing_address['postal_code'] = $order_billing_address->getPostcode();
     $billing_address['country_code'] = $this->convert_country_code($order_billing_address->getCountry());
     $billing_address['phone'] = $this->convert_country_code($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();
     if (strlen($shipping_address['city']) > 20) {
         $split = explode('/', $shipping_address['city']);
         if (count($split) == 1) {
             $shipping_address['city'] = substr($shipping_address['city'], 20);
         } else {
             $shipping_address['city'] = $split[1];
         }
     }
     $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/vtvirtual/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['payment_type'] = 'bank_transfer';
     $payloads['bank_transfer'] = array('bank' => "permata");
     try {
         $redirUrl = Veritrans_VtDirect::charge($payloads);
         if ($redirUrl->status_code == '201') {
             /* send an order email when redirecting to payment page although payment
                has not been completed. */
             $order->setState(Mage::getStoreConfig('payment/vtvirtual/'), true, 'New order, waiting for payment.');
             $this->send_new_order_mail(Mage::app()->getStore()->getStoreId(), $order, $order_billing_address, $order->getPayment(), $customer_details['email'], $order_billing_address->getName(), $order->getCustomerIsGuest(), $redirUrl->permata_va_number);
             $order->setEmailSent(true);
             // Redirected by Veritrans, if ok
             Mage::getSingleton('checkout/session')->unsQuoteId();
             $success = "Veritrans success";
             Mage::getSingleton('core/session')->setSVA($redirUrl->permata_va_number);
             Mage::getSingleton('checkout/session')->unsQuoteId();
             foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item) {
                 Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
             }
             Mage::getSingleton('core/session')->unsPaymentData();
             Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure' => true));
         } else {
             // There is a problem in the response we got
             $this->cancelAction();
             Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure' => true));
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
         $this->cancelAction();
         var_dump("<pre> virtual account", $e);
         die;
         Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure' => true));
     }
 }
Пример #11
0
 public static function setUpBeforeClass()
 {
     Veritrans_Config::$serverKey = getenv('SERVER_KEY');
     Veritrans_Config::$clientKey = getenv('CLIENT_KEY');
     Veritrans_Config::$isProduction = false;
 }
Пример #12
0
 public function tearDown()
 {
     Veritrans_Config::$isProduction = false;
 }
Пример #13
0
 function plgVmOnPaymentNotification()
 {
     if (!class_exists('VirtueMartModelOrders')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php';
     }
     $raw_notification = json_decode(file_get_contents('php://input'), true);
     // error_log('xx raw_notification :'.print_r($order_history,true)); // debug purpose
     if (empty($raw_notification)) {
         $this->debugLog('Notification URL accessed with no POST data submitted.', 'plgVmOnPaymentNotification', 'debug', false);
         return FALSE;
     }
     $virtuemart_order_id = $raw_notification['order_id'];
     $orderModel = VmModel::getModel('orders');
     $order = $orderModel->getOrder($virtuemart_order_id);
     $virtuemart_paymentmethod_id = $order['details']['BT']->virtuemart_paymentmethod_id;
     $this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id);
     $interface = $this->_loadVeritransInterface($this);
     Veritrans_Config::$serverKey = $this->_currentMethod->serverkey;
     Veritrans_Config::$isProduction = $this->_currentMethod->shop_mode == 'test' ? FALSE : TRUE;
     $response = new Veritrans_Notification();
     $orderModel = VmModel::getModel('orders');
     $order = $orderModel->getOrder($virtuemart_order_id);
     $order_history = $this->updateOrderStatus($interface, $response, $order);
     // error_log('xx response :'.print_r($response,true)); // debug purpose
     // error_log('xx order history :'.print_r($order_history,true)); // debug purpose
     if ($order_history == FALSE) {
         // error_log("settled"); //debug purpose
         return TRUE;
     }
     return TRUE;
 }
Пример #14
0
function edd_veritrans_notification()
{
    global $edd_options;
    require_once plugin_dir_path(__FILE__) . '/lib/Veritrans.php';
    if (edd_is_test_mode()) {
        // set test credentials here
        // error_log('masuk test mode');  //debugan
        Veritrans_Config::$serverKey = $edd_options['vt_sandbox_api_key'];
        Veritrans_Config::$isProduction = false;
    } else {
        // set test credentials here
        // error_log('masuk production mode'); //debugan
        Veritrans_Config::$serverKey = $edd_options['vt_production_api_key'];
        Veritrans_Config::$isProduction = true;
    }
    // error_log('serverKey: '.Veritrans_Config::$serverKey); //debugan
    // error_log('isProduction: '.Veritrans_Config::$isProduction); //debugan
    $notif = new Veritrans_Notification();
    // error_log('$notif '.print_r($notif)); //debugan
    $transaction = $notif->transaction_status;
    $fraud = $notif->fraud_status;
    $order_id = $notif->order_id;
    // error_log('$order_id '.$order_id); //debugan
    // error_log('$fraud '.$fraud); //debugan
    // error_log('$transaction '.$transaction); //debugan
    if ($transaction == 'capture') {
        if ($fraud == 'challenge') {
            // TODO Set payment status in merchant's database to 'challenge'
            edd_update_payment_status($order_id, 'challenge');
            // error_log('challenge gan!'); //debugan
        } else {
            if ($fraud == 'accept') {
                edd_update_payment_status($order_id, 'complete');
                // error_log('accepted gan!'); //debugan
            }
        }
    } else {
        if ($notif->transaction_status != 'credit_card' && $transaction == 'settlement') {
            edd_update_payment_status($order_id, 'complete');
            // error_log('accepted gan!'); //debugan
        } else {
            if ($transaction == 'cancel') {
                edd_update_payment_status($order_id, 'cancel');
                // error_log('cancelled gan!'); //debugan
            } else {
                if ($transaction == 'deny') {
                    edd_update_payment_status($order_id, 'failed');
                    // error_log('denied gan!'); //debugan
                }
            }
        }
    }
}
Пример #15
0
    $veritrans_live = $data->live_code;
    $veritrans_sandbox = $data->sandbox_code;
    $veritrans_secure = $data->_3dsecure;
}
/* --- SERVER KEY --- */
if ($veritrans_environment == 1) {
    $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')){
Пример #16
0
 public function checkout()
 {
     $link = ["Citilink" => "citilink", "Sriwijaya Air" => "sriwijaya", "Air Asia" => "airasia"];
     $data = Session::get('PESAWAT')['input'];
     unset($data['type']);
     //print_r($data);
     // dd(Session::all());
     $data = array_merge($data, ["depart_value" => Session::get('PESAWAT')['DATA_PESAWAT']['input']['value'], 'return_value' => '0~P~~P~RGFR~~1~X|QG~ 819~ ~~CGK~02/13/2016 21:10~SUB~02/13/2016 22:40~']);
     $data_booking['passengers']['adults'] = [];
     $data_booking['passengers']['children'] = [];
     $data_booking['passengers']['infants'] = [];
     $passenger_type = ["adult" => 'adults', 'children' => 'children', 'infant' => 'infants'];
     for ($i = 0; $i < sizeof(Session::get('PESAWAT')['DATA_COSTUMER']['PASSENGER_DETAIL_TITTLE']); $i++) {
         $nama_penumpang = explode(" ", Session::get('PESAWAT')['DATA_COSTUMER']['PASSENGER_DETAIL_NAME'][$i]);
         $first_name = '';
         if (sizeof($nama_penumpang) == 1) {
             $nama_penumpang[1] = $nama_penumpang[0];
         }
         for ($j = 0; $j < sizeof($nama_penumpang) - 1; $j++) {
             $first_name = $first_name . "" . $nama_penumpang[$j] . " ";
         }
         array_push($data_booking['passengers'][$passenger_type[Session::get('PESAWAT')['DATA_COSTUMER']['passenger_type'][$i]]], array("first_name" => $first_name, "last_name" => $nama_penumpang[sizeof($nama_penumpang) - 1], "title" => Session::get('PESAWAT')['DATA_COSTUMER']['PASSENGER_DETAIL_TITTLE'][$i], "wheelchair" => false, "id" => "5104032709940003", "birthday" => "1990-12-01"));
         /*                array_push($data_booking['passenger'][Session::get('PESAWAT')['DATA_COSTUMER']['passenger_type'][$i]], array("last_name"=>""));
                         array_push($data_booking['passenger'][Session::get('PESAWAT')['DATA_COSTUMER']['passenger_type'][$i]], array("title"=>Session::get('PESAWAT')['DATA_COSTUMER']['PASSENGER_DETAIL_TITTLE'][$i]));
                         array_push($data_booking['passenger'][Session::get('PESAWAT')['DATA_COSTUMER']['passenger_type'][$i]], array("wheelchair"=>false));
                         array_push($data_booking['passenger'][Session::get('PESAWAT')['DATA_COSTUMER']['passenger_type'][$i]], array("id"=>"5104032709940003"));*/
     }
     $nama_penumpang = explode(" ", Session::get('PESAWAT')['DATA_COSTUMER']['COSTUMER_NAME']);
     $first_name = '';
     if (sizeof($nama_penumpang) == 1) {
         $nama_penumpang[1] = $nama_penumpang[0];
     }
     for ($j = 0; $j < sizeof($nama_penumpang) - 1; $j++) {
         $first_name = $first_name . "" . $nama_penumpang[$j] . " ";
     }
     $data_booking['passengers']['contact']['first_name'] = $first_name;
     $data_booking['passengers']['contact']['last_name'] = $nama_penumpang[sizeof($nama_penumpang) - 1];
     $data_booking['passengers']['contact']['origin_phone'] = '0' . Session::get('PESAWAT')['DATA_COSTUMER']['COSTUMER_TELP'];
     /*   
           echo json_encode($data_booking);*/
     //echo json_encode('/');
     $data = array_merge($data, $data_booking);
     $data = json_encode($data);
     $data = str_replace('\\/', '/', $data);
     print_r($data);
     //
     $url = 'localhost:6070/schedule/' . $link[Session::get('PESAWAT')['DATA_PESAWAT']['airline']] . '/reserve';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, TRUE);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec($ch);
     curl_close($ch);
     $result = json_decode($result, true);
     $this->code_booking = $result['booking_code'];
     Session(['booking_code' => $result['booking_code']]);
     $this->setOrderIdType(Session::get('NO_PEMESANAN'));
     \Veritrans_Config::$serverKey = $this->server_key;
     \Veritrans_Config::$isProduction = $this->is_production;
     $transaction_details = array('order_id' => Session::get(Session::get('type'))['DATA_COSTUMER']['NO_PEMESANAN'], 'gross_amount' => Session::get(Session::get('type'))['DATA_' . Session::get('type')]['price']);
     $input = Input::except('_token');
     $payment_method = $input['payment_method'];
     $this->transaction_details = $transaction_details;
     if ($payment_method == "credit_card") {
         $this->token_id = $input['token-id'];
         $status_code = $this->payWithCreditCard();
         $this->saveData($payment_method, $status_code);
         $this->forgetSession();
         if ($status_code == "200" or $status_code == "201") {
             return view('payment::response.success');
         } else {
             return view('payment::response.fail');
         }
     } else {
         if ($payment_method == "bank_transfer") {
             $status_code = $this->payWithBankTransfer();
             $this->saveData($payment_method, $status_code);
             $this->forgetSession();
             if ($status_code == "201") {
                 return view('payment::response.instruction');
             } else {
                 return view('payment::response.fail');
             }
         }
     }
     Session::forget("PESAWAT");
 }
 /**
  * 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();
     }
 }
Пример #18
0
 public function redirectAction()
 {
     $orderIncrementId = $this->_getCheckout()->getLastRealOrderId();
     $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
     $sessionId = Mage::getSingleton('core/session');
     /* need to set payment data to Mage::getSingleton('checkout/session')->setPaymentData(); when checkout */
     $pay = Mage::getSingleton('core/session')->getPaymentData();
     $api_version = Mage::getStoreConfig('payment/vtcimb/api_version');
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtcimb/environment') == 'production' ? true : false;
     /** Veritrans_Config::$serverKey =
         Mage::getStoreConfig('payment/vtcimb/server_key_v2'); **/
     Veritrans_Config::$serverKey = "VT-server-7taUlH8IVx6wcj16D8iZQQSZ";
     $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();
     if (strlen($billing_address['city']) > 20) {
         $split = explode('/', $billing_address['city']);
         if (count($split) == 1) {
             $billing_address['city'] = substr($billing_address['city'], 20);
         } else {
             $billing_address['city'] = $split[1];
         }
     }
     $billing_address['postal_code'] = $order_billing_address->getPostcode();
     $billing_address['country_code'] = $this->convert_country_code($order_billing_address->getCountry());
     $billing_address['phone'] = $this->convert_country_code($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();
     if (strlen($shipping_address['city']) > 20) {
         $split = explode('/', $shipping_address['city']);
         if (count($split) == 1) {
             $shipping_address['city'] = substr($shipping_address['city'], 20);
         } else {
             $shipping_address['city'] = $split[1];
         }
     }
     $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;
         }
         $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;
     }
     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['payment_type'] = 'cimb_clicks';
     $payloads['cimb_clicks'] = array('description' => "Order " . $orderIncrementId);
     try {
         $redirUrl = Veritrans_VtDirect::charge($payloads);
         if ($redirUrl->status_code == '201') {
             /* send an order email when redirecting to payment page although payment
                has not been completed. */
             $order->setState(Mage::getStoreConfig('payment/vtcimb/'), true, 'New order, waiting for payment.');
             $order->sendNewOrderEmail();
             $order->setEmailSent(true);
             // Redirected by Veritrans, if ok
             Mage::getSingleton('checkout/session')->unsQuoteId();
             foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item) {
                 Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
             }
             $this->_redirectUrl($redirUrl->redirect_url);
         } else {
             // There is a problem in the response we got
             $this->cancelAction();
             Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/', array('_secure' => true));
         }
     } catch (Exception $e) {
         error_log($e->getMessage());
         $this->cancelAction();
         Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/', array('_secure' => true));
     }
 }
 public function execNotification()
 {
     $veritrans = new Veritrans_Config();
     Veritrans_Config::$isProduction = Configuration::get('VT_ENVIRONMENT') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Configuration::get('VT_SERVER_KEY');
     $veritrans_notification = new Veritrans_Notification();
     $history = new OrderHistory();
     $history->id_order = (int) $veritrans_notification->order_id;
     error_log('message notif');
     error_log(print_r($veritrans_notification, TRUE));
     error_log('==============================================');
     // check if order history already been updated to payment success, then save to array $order_history.
     $order_id_notif = (int) $veritrans_notification->order_id;
     $order = new Order($order_id_notif);
     $order_histories = $order->getHistory($this->context->language->id, Configuration::get('VT_PAYMENT_SUCCESS_STATUS_MAP'));
     // if (empty($order_histories))
     // 	error_log("not found in DB");
     // error_log(print_r($order_histories,true));
     // print_r($order_histories,true);
     //Validating order
     //if ($veritrans_notification->isVerified())
     //{
     //$history->id_order = (int)$veritrans_notification->order_id;
     //error_log('notif verified');
     //error_log('message notif: '.(int)$veritrans_notification->order_id);
     if ($veritrans_notification->transaction_status == 'capture') {
         if ($veritrans_notification->fraud_status == 'accept') {
             // if order history !contains payment accepted, then update DB. Else, don't update DB
             if (empty($order_histories)) {
                 $history->changeIdOrderState(Configuration::get('VT_PAYMENT_SUCCESS_STATUS_MAP'), $order_id_notif);
                 echo 'Valid success notification accepted.';
             } else {
                 error_log("########## Transaction has already been updated to success status once, no need to update again");
             }
         } else {
             if ($veritrans_notification->fraud_status == 'challenge') {
                 $history->changeIdOrderState(Configuration::get('VT_PAYMENT_CHALLENGE_STATUS_MAP'), $order_id_notif);
                 echo 'Valid challenge notification accepted.';
             }
         }
     } else {
         if ($veritrans_notification->transaction_status == 'settlement') {
             if ($veritrans_notification->payment_type != 'credit_card') {
                 // if order history !contains payment accepted, then update DB. Else, don't update DB
                 if (empty($order_histories)) {
                     $history->changeIdOrderState(Configuration::get('VT_PAYMENT_SUCCESS_STATUS_MAP'), $order_id_notif);
                     echo 'Valid success notification accepted.';
                 } else {
                     error_log("########## Transaction has already been updated to success status once, no need to update again");
                 }
             } else {
                 echo 'Credit card settlement notification accepted.';
             }
         } else {
             if ($veritrans_notification->transaction_status == 'pending') {
                 $history->changeIdOrderState(Configuration::get('VT_PAYMENT_CHALLENGE_STATUS_MAP'), $order_id_notif);
                 echo 'Pending notification accepted.';
             } else {
                 if ($veritrans_notification->transaction_status == 'cancel') {
                     $history->changeIdOrderState(Configuration::get('VT_PAYMENT_FAILURE_STATUS_MAP'), $order_id_notif);
                     echo 'Pending notification accepted.';
                 } else {
                     if ($veritrans_notification->transaction_status == 'expire') {
                         $history->changeIdOrderState(Configuration::get('VT_PAYMENT_FAILURE_STATUS_MAP'), $order_id_notif);
                         echo 'Expire notification accepted.';
                     } else {
                         $history->changeIdOrderState(Configuration::get('VT_PAYMENT_FAILURE_STATUS_MAP'), $order_id_notif);
                         echo 'Valid failure notification accepted';
                     }
                 }
             }
         }
     }
     try {
         $history->add(true);
     } catch (Exception $e) {
         echo 'Order history not added: ' . $e->getMessage();
         exit;
     }
     //}
     exit;
 }
Пример #20
0
 function handling()
 {
     echo 1;
     if ($this->isProd) {
         Veritrans_Config::$isProduction = true;
     }
     echo 3;
     Veritrans_Config::$serverKey = $this->getKeyUsed();
     echo 4;
     $raw_notification = "";
     try {
         $notif = new Veritrans_Notification();
         $input_source = "php://input";
         $raw_notification = file_get_contents($input_source);
     } catch (Exception $e) {
         echo "<h2>" . $e->getMessage() . "</h2>";
     }
     echo "<h1>jahahaa</h1>";
     $transaction = $notif->transaction_status;
     $type = $notif->payment_type;
     $order_id = $notif->order_id;
     $fraud = $notif->fraud_status;
     $vpt = new VpTransaction();
     $vpt->getByID($order_id);
     //dataemail
     $dataemail = new DataEmail();
     if ($transaction == 'capture') {
         // For credit card transaction, we need to check whether transaction is challenge by FDS or not
         if ($type == 'credit_card') {
             if ($fraud == 'challenge') {
                 // TODO set payment status in merchant's database to 'Challenge by FDS'
                 // TODO merchant should decide whether this transaction is authorized or not in MAP
                 echo "Transaction order_id: " . $order_id . " is challenged by FDS";
                 $vpt->order_message = "Transaction order_id: " . $order_id . " is challenged by FDS";
                 $vpt->order_status = 3;
                 $vpt->save();
                 //notify User
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, $fraud);
             } else {
                 // TODO set payment status in merchant's database to 'Success'
                 echo "Transaction order_id: " . $order_id . " successfully captured using " . $type;
                 $vpt->order_message = "Transaction order_id: " . $order_id . " successfully captured using " . $type;
                 $vpt->order_status = 2;
                 $vpt->save();
                 //notify User
                 //update active di app
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $app->app_contract_start = date("Y-m-d");
                 $app->app_contract_end = date('Y-m-d', strtotime(date("Y-m-d", mktime()) . " + 365 day"));
                 $app->app_active = 1;
                 $app->app_paket_id = $vpt->order_paket_id;
                 $app->save();
                 //notify Admins kalau ada app active
                 $dataemail->appBisaDibuat($app->app_name, $app->app_id, $transaction);
                 //notify User
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentSuccess($acc->admin_email, $acc->admin_username, $app->app_name);
                 //hitung komisi
                 //ini belum bener
                 //TODO 31 maret 2016
                 KomisiModel::log($app, $vpt);
                 //email dapat komisi
             }
         }
     } else {
         if ($transaction == 'settlement') {
             // TODO set payment status in merchant's database to 'Settlement'
             echo "Transaction order_id: " . $order_id . " successfully transfered using " . $type;
             $oldstatus = $vpt->order_status;
             $vpt->order_message = "Transaction order_id: " . $order_id . " successfully transfered using " . $type;
             $vpt->order_status = 1;
             $vpt->save();
             if ($oldstatus != 2) {
                 //update active di app
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $app->app_contract_start = date("Y-m-d");
                 $app->app_contract_end = date('Y-m-d', strtotime(date("Y-m-d", mktime()) . " + 365 day"));
                 $app->app_active = 1;
                 $app->app_paket_id = $vpt->order_paket_id;
                 $app->save();
                 //notify Admins kalau ada app active
                 $dataemail->appBisaDibuat($app->app_name, $app->app_id, $transaction);
                 //notify User
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentSettle($acc->admin_email, $acc->admin_username, $app->app_name);
                 //hitung komisi
                 //TODO 31 maret 2016
                 KomisiModel::log($app, $vpt);
                 //email dpt komisi
             }
         } else {
             if ($transaction == 'pending') {
                 // TODO set payment status in merchant's database to 'Pending'
                 echo "Waiting customer to finish transaction order_id: " . $order_id . " using " . $type;
                 $vpt->order_message = "Waiting customer to finish transaction order_id: " . $order_id . " using " . $type;
                 $vpt->order_status = 4;
                 $vpt->save();
                 //notify User
                 $app = new AppAccount();
                 $app->getByID($vpt->order_app_id);
                 $acc = new Account();
                 $acc->getByID($app->app_client_id);
                 $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, $transaction);
             } else {
                 if ($transaction == 'deny') {
                     // TODO set payment status in merchant's database to 'Denied'
                     echo "Payment using " . $type . " for transaction order_id: " . $order_id . " is denied.";
                     $vpt->order_message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is denied.";
                     $vpt->order_status = 5;
                     $vpt->save();
                     //notify User
                     $app = new AppAccount();
                     $app->getByID($vpt->order_app_id);
                     $acc = new Account();
                     $acc->getByID($app->app_client_id);
                     $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, "denied");
                 } else {
                     if ($transaction == 'cancel') {
                         // TODO set payment status in merchant's database to 'Denied'
                         echo "Payment using " . $type . " for transaction order_id: " . $order_id . " is canceled.";
                         $vpt->order_message = "Payment using " . $type . " for transaction order_id: " . $order_id . " is canceled.";
                         $vpt->order_status = 6;
                         $vpt->save();
                         //notify User
                         $app = new AppAccount();
                         $app->getByID($vpt->order_app_id);
                         $acc = new Account();
                         $acc->getByID($app->app_client_id);
                         $dataemail->appPaymentMode($acc->admin_email, $acc->admin_username, $app->app_name, "canceled");
                     }
                 }
             }
         }
     }
     $vp = new VpData();
     $vp->vp_date = leap_mysqldate();
     $vp->vp_obj = serialize($notif) . " ||| " . $raw_notification;
     $vp->approval_code = $notif->approval_code;
     $vp->order_id = $notif->order_id;
     $vp->status_code = $notif->status_code;
     $vp->transaction_status = $notif->transaction_status;
     $vp->status_message = $notif->status_message;
     $vp->transaction_id = $notif->transaction_id;
     $vp->masked_card = $notif->masked_card;
     $vp->gross_amount = $notif->gross_amount;
     $vp->payment_type = $notif->payment_type;
     $vp->transaction_time = $notif->transaction_time;
     $vp->fraud_status = $notif->fraud_status;
     $vp->approval_code = $notif->approval_code;
     $vp->signature_key = $notif->signature_key;
     $vp->bank = $notif->bank;
     $vp->eci = $notif->eci;
     $vp->save();
     pr($notif);
     /*
              * Veritrans_Notification Object
     (
         [response:Veritrans_Notification:private] => stdClass Object
             (
                 [status_code] => 200
                 [status_message] => Success, transaction found
                 [transaction_id] => a293ec21-9572-4333-9a41-640a6789b713
                 [masked_card] => 518323-9790
                 [order_id] => 1084599542
                 [gross_amount] => 10000.00
                 [payment_type] => credit_card
                 [transaction_time] => 2016-02-17 15:20:37
                 [transaction_status] => capture
                 [fraud_status] => accept
                 [approval_code] => T08489
                 [signature_key] => 12a2c1d52cdd03326727b1ee0cc8a9f658146dbaedac46490f269183291885772e5a31a121c94ebde9f501733c8e7802cf74c3bb839ad687188456c3bf0d45e0
                 [bank] => bni
                 [eci] => 02
             )
     
     )
     */
     die;
 }