public function testGetRedirectionUrl() { Veritrans_Config::$serverKey = 'My Very Secret Key'; VT_Tests::$stubHttp = true; VT_Tests::$stubHttpResponse = '{ "status_code": 200, "redirect_url": "http://host.com/pay" }'; $params = array('transaction_details' => array('order_id' => "Order-111", 'gross_amount' => 10000)); $paymentUrl = Veritrans_Vtweb::getRedirectionUrl($params); $this->assertEquals($paymentUrl, "http://host.com/pay"); $this->assertEquals(VT_Tests::$lastHttpRequest["url"], "https://api.sandbox.veritrans.co.id/v2/charge"); $this->assertEquals(VT_Tests::$lastHttpRequest["server_key"], 'My Very Secret Key'); $fields = VT_Tests::lastReqOptions(); $this->assertEquals($fields["POST"], 1); $this->assertEquals($fields["POSTFIELDS"], '{"payment_type":"vtweb","vtweb":{"credit_card_3d_secure":false},' . '"transaction_details":{"order_id":"Order-111","gross_amount":10000}}'); }
public static function charge($params) { $payloads = array('payment_type' => 'credit_card'); if (array_key_exists('item_details', $params)) { $gross_amount = 0; foreach ($params['item_details'] as $item) { $gross_amount += $item['quantity'] * $item['price']; } $payloads['transaction_details']['gross_amount'] = $gross_amount; } $payloads = array_replace_recursive($payloads, $params); if (Veritrans_Config::$isSanitized) { Veritrans_Sanitizer::jsonRequest($payloads); } $result = Veritrans_ApiRequestor::post(Veritrans_Config::getBaseUrl() . '/charge', Veritrans_Config::$serverKey, $payloads); return $result; }
public function testFailureStatus() { Veritrans_Config::$serverKey = 'My Very Secret Key'; VT_Tests::$stubHttp = true; VT_Tests::$stubHttpResponse = '{ "status_code": "404", "status_message": "The requested resource is not found" }'; try { $status = Veritrans_Transaction::status("Order-111"); } catch (Exception $error) { $errorHappen = true; $this->assertEquals($error->getMessage(), "Veritrans Error (404): The requested resource is not found"); } $this->assertTrue($errorHappen); VT_Tests::reset(); }
function checkout() { Veritrans_Config::$serverKey = self::$serverKey; echo "haha"; // 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; // Required $transaction_details = array('order_id' => rand(), 'gross_amount' => 1545000); // Optional $item1_details = array('id' => 'kb1', 'price' => 1500000, 'quantity' => 1, 'name' => "Apple"); // Optional $item2_details = array('id' => 'a2', 'price' => 45000, 'quantity' => 1, 'name' => "Orange"); // Optional $item_details = array($item1_details, $item2_details); // Optional $billing_address = array('first_name' => "Efindi", 'last_name' => "Litani", 'address' => "Mangga 20", 'city' => "Jakarta", 'postal_code' => "16602", 'phone' => "081122334455", 'country_code' => 'IDN'); // Optional $shipping_address = array('first_name' => "Obet", 'last_name' => "Supriadi", 'address' => "Manggis 90", 'city' => "Jakarta", 'postal_code' => "16601", 'phone' => "08113366345", 'country_code' => 'IDN'); // Optional $customer_details = array('first_name' => "Andri", 'last_name' => "Litani", 'email' => "*****@*****.**", 'phone' => "081122334455", 'billing_address' => $billing_address, 'shipping_address' => $shipping_address); // Fill transaction details $transaction = array('transaction_details' => $transaction_details, '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; } } echo "hihi"; }
public function status() { // Includes Veritrans include app_path() . '/packages/veritrans/Veritrans.php'; // Veritans configuration Veritrans_Config::$serverKey = 'VT-server-YN3xDgcjXol4o0mgbOs-A72D'; // init $data = array(); // get input $param = Input::all(); try { // Check status transaksi ke server Veritrans $check = Veritrans_Transaction::status($param['order_id']); var_dump($check); // Order id $cipher = 'm4t4h4r1899'; $iv = sprintf("%016d", Auth::user()->id); // Mempola Initialization Vector dengan User id // -- Decrypt order_id dengan algoritma AES-256 $order_id = openssl_decrypt($param['order_id'], 'AES-256-CBC', $cipher, 0, $iv); $order_id = explode("_", $order_id, 2); $donation_id = (int) $order_id[1]; $donation = Donation::where('id', '=', $donation_id)->where('status', '!=', 3)->first(); // Check $code = DB::table('payment_code')->where('order_id', $param['order_id']); if ($code->count() > 0) { $vtweb_url = 'https://vtweb.sandbox.veritrans.co.id/v2/vtweb/' . $code->pluck('code'); } else { $transaction = array('transaction_details' => array('order_id' => $param['order_id'], 'gross_amount' => (int) $donation->total), "vtweb" => array("credit_card_3d_secure" => true), 'customer_details' => array('first_name' => Auth::user()->firstname, 'last_name' => Auth::user()->lastname)); // Mendapatkan checkout url $vtweb_url = Veritrans_Vtweb::getRedirectionUrl($transaction); $insert_code = DB::table('payment_code')->insert(array('order_id' => $param['order_id'], 'user_id' => Auth::user()->id, 'donation_id' => $donation->id, 'code' => basename($vtweb_url))); } $data = array('status_code' => $check->status_code, 'donation' => $donation); } catch (Exception $ex) { $data['status_code'] = '404'; } return View::make('bagikasih.donation.status', $data); }
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(); } }
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(); }
<?php $order_id = filter_var($_REQUEST['order_number'], FILTER_SANITIZE_STRING); $order_total = filter_var($_REQUEST['total'], FILTER_SANITIZE_NUMBER_INT); require_once dirname(__FILE__) . '/../../Veritrans.php'; /* --- SANDBOX --- */ Veritrans_Config::$serverKey = '2d7b85ab-f67a-43fd-9a85-95ffc9ef7f22'; /* --- PRODUCTION --- */ //Veritrans_Config::$serverKey = '88dd5ab2-218e-4b2f-8f0d-09e2e5275068'; // Uncomment for production environment Veritrans_Config::$isProduction = false; // Uncomment to enable sanitization // Veritrans_Config::$isSanitized = true; // Uncomment to enable 3D-Secure //Veritrans_Config::$is3ds = true; $params = array('transaction_details' => array('order_id' => $order_id, 'gross_amount' => $order_total)); try { // Redirect to Veritrans VTWeb page header('Location: ' . Veritrans_Vtweb::getRedirectionUrl($params)); } catch (Exception $e) { echo $e->getMessage(); }
$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;
/** * 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(); } }
<?php require_once dirname(__FILE__) . '/../Veritrans.php'; /* --- SANDBOX --- */ Veritrans_Config::$serverKey = '71c4c006-f73b-4312-b602-18425c79e5d0'; /* --- PRODUCTION --- */ //Veritrans_Config::$serverKey = '88dd5ab2-218e-4b2f-8f0d-09e2e5275068'; $notif = new Veritrans_Notification(); if ($notif->isVerified()) { $transaction = $notif->transaction_status; $fraud = $notif->fraud_status; error_log("Order ID {$notif->order_id}: " . "transaction status = {$transaction}, fraud staus = {$fraud}"); if ($transaction == 'capture') { if ($fraud == 'challenge') { // TODO Set payment status in merchant's database to 'challenge' } else { if ($fraud == 'accept') { // TODO Set payment status in merchant's database to 'success' } } } else { if ($transaction == 'cancel') { if ($fraud == 'challenge') { // TODO Set payment status in merchant's database to 'failure' } else { if ($fraud == 'accept') { // TODO Set payment status in merchant's database to 'failure' } } } else { if ($transaction == 'deny') {
public static function setUpBeforeClass() { Veritrans_Config::$serverKey = getenv('SERVER_KEY'); Veritrans_Config::$clientKey = getenv('CLIENT_KEY'); Veritrans_Config::$isProduction = false; }
<?php require_once dirname(__FILE__) . '/../../Veritrans.php'; // YOUR CLIENT KEY // can find in Merchant Portal -> Settings -> Access keys Veritrans_Config::$clientKey = "VT-client-cRFZZ6zvtii0FO88"; if (Veritrans_Config::$clientKey == "<your client key>") { echo "<p style='background: #FFB588; padding: 10px;'>"; echo "Please set your client key in file " . __FILE__; echo "</p>"; } ?> <html> <head> <title>Checkout</title> <link rel="stylesheet" href="jquery.fancybox.css"> </head> <body> <script type="text/javascript" src="https://api.sandbox.veritrans.co.id/v2/assets/js/veritrans.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="jquery.fancybox.pack.js"></script> <h1>Checkout</h1> <form action="checkout-process.php" method="POST" id="payment-form"> <fieldset> <legend>Checkout</legend> <p> <label>Card Number</label> <input class="card-number" value="4011 1111 1111 1112" size="23" type="text" autocomplete="off" />
@extends('bagikasih.theme.templating') @section('header') @include('bagikasih.theme.header') @stop @section('navbar') @include('bagikasih.theme.navbar') @stop @section('sidebar') <?php // Includes Veritrans include app_path() . '/packages/veritrans/Veritrans.php'; // Veritans configuration Veritrans_Config::$serverKey = 'VT-server-YN3xDgcjXol4o0mgbOs-A72D'; ?> <!-- Container - mulai--> <div class="container"> <div class="row"> <div class="col-lg-12"> <div class="page-header"> </div> </div> </div> <div class="row"> <?php switch ($status_code) { case "201": // Donasi UNPAID echo ' <div class="panel-body col-lg-9"> <div class="panel panel-default"> <div class="panel-body"> <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12 text-center">
/** * Capture pre-authorized transaction * * @param string $param Order ID or transaction ID, that you want to capture */ public static function capture($param) { $payloads = array('transaction_id' => $param); $result = Veritrans_ApiRequestor::post(Veritrans_Config::getBaseUrl() . '/capture', Veritrans_Config::$serverKey, $payloads); return $result; }
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); } }
/** * 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'); $this->load->model('checkout/order'); $this->load->model('payment/veritrans'); Veritrans_Config::$serverKey = $this->config->get('veritrans_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('veritrans_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('veritrans_vtweb_success_mapping'), 'VT-Web payment successful.'); } } } else { if ($transaction == 'cancel') { $logs .= 'cancel '; if ($fraud == 'challenge') { $logs .= 'challenge '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment failed.'); } else { if ($fraud == 'accept') { $logs .= 'accept '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment failed.'); } else { $logs .= 'cancel '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment canceled.'); } } } else { if ($transaction == 'deny') { $logs .= 'deny '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment failed.'); } else { if ($transaction == 'pending') { $logs .= 'pending '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_challenge_mapping'), 'VT-Web payment pending.'); } else { if ($transaction == 'settlement') { $logs .= 'complete '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_success_mapping'), 'VT-Web payment successful.'); } else { if ($transaction == 'cancel') { $logs .= 'cancel '; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment failed.'); } else { $logs .= "*{$transaction}:{$fraud} "; $this->model_checkout_order->update($notif->order_id, $this->config->get('veritrans_vtweb_challenge_mapping'), 'VT-Web payment challenged. Please take action on ' . 'your Merchant Administration Portal.'); } } } } } } error_log($logs); }
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; }
/** * Expire transaction before it's setteled * @param string $id Order ID or transaction ID * @return mixed[] */ public static function expire($id) { return Veritrans_ApiRequestor::post(Veritrans_Config::getBaseUrl() . '/' . $id . '/expire', Veritrans_Config::$serverKey, false); }
<?php require_once dirname(__FILE__) . '/../../Veritrans.php'; // YOUR CLIENT KEY // can find in Merchant Portal -> Settings -> Access keys Veritrans_Config::$clientKey = "<your client key>"; if (Veritrans_Config::$clientKey == "<your client key>") { echo "<p style='background: #FFB588; padding: 10px;'>"; echo "Please set your client key in file " . __FILE__; echo "</p>"; } ?> <html> <head> <title>Checkout</title> <link rel="stylesheet" href="jquery.fancybox.css"> </head> <body> <script type="text/javascript" src="https://api.sandbox.veritrans.co.id/v2/assets/js/veritrans.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="jquery.fancybox.pack.js"></script> <h1>Checkout</h1> <form action="checkout-process.php" method="POST" id="payment-form"> <fieldset> <legend>Checkout</legend> <p> <label>Card Number</label> <input class="card-number" value="4011 1111 1111 1112" size="23" type="text" autocomplete="off" />
/** * 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 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"); Veritrans_Config::$isProduction = $this->config->get('veritrans_environment') == 'production' ? true : false; Veritrans_Config::$serverKey = $this->config->get('veritrans_server_key_v2'); $this->load->model('checkout/order'); $this->load->model('payment/veritrans'); $notif = new Veritrans_Notification(); $transaction = $notif->transaction_status; $fraud = $notif->fraud_status; $payment_type = $notif->payment_type; $logs = ''; // error_log(print_r($notif,true)); // debugan if ($transaction == 'capture') { $logs .= 'capture '; if ($fraud == 'challenge') { $logs .= 'challenge '; $this->model_checkout_order->addOrderHistory($notif->order_id, $this->config->get('veritrans_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->addOrderHistory($notif->order_id, $this->config->get('veritrans_vtweb_success_mapping'), 'VT-Web payment successful.'); } } } else { if ($transaction == 'cancel') { $logs .= 'cancel '; $this->model_checkout_order->addOrderHistory($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment canceled.'); } else { if ($transaction == 'deny') { $logs .= 'deny '; $this->model_checkout_order->addOrderHistory($notif->order_id, $this->config->get('veritrans_vtweb_failure_mapping'), 'VT-Web payment failed.'); } else { if ($transaction == 'pending') { $logs .= 'pending '; $this->model_checkout_order->addOrderHistory($notif->order_id, $this->config->get('veritrans_vtweb_challenge_mapping'), 'VT-Web payment pending.'); } else { if ($transaction == 'settlement') { if ($payment_type != 'credit_card') { $logs .= 'complete '; $this->model_checkout_order->addOrderHistory($notif->order_id, $this->config->get('veritrans_vtweb_success_mapping'), 'VT-Web payment successful.'); } } else { $logs .= "*{$transaction}:{$fraud} "; $this->model_checkout_order->addOrderHistory($notif->order_id, $this->config->get('veritrans_vtweb_challenge_mapping'), 'VT-Web payment challenged. Please take action on ' . 'your Merchant Administration Portal.'); } } } } } error_log($logs); //debugan to be commented }
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; }
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"); }
public function tearDown() { Veritrans_Config::$isProduction = false; }
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; } }
public function notificationAction() { error_log('payment notification'); Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtcimb/server_key_v2'); $notif = new Veritrans_Notification(); $order = Mage::getModel('sales/order'); $order->loadByIncrementId($notif->order_id); $transaction = $notif->transaction_status; $fraud = $notif->fraud_status; $logs = ''; if ($transaction == 'settlement') { $logs .= '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('processing'); $order->sendOrderUpdateEmail(true, 'Thank you, your payment is successfully processed.'); } else { if ($transaction == 'pending') { $logs .= 'pending '; $order->setStatus('pending'); } else { $logs .= 'deny '; $order->setStatus('canceled'); } } $order->save(); error_log($logs); }
<?php require_once dirname(__FILE__) . '/../Veritrans.php'; Veritrans_Config::$isProduction = false; Veritrans_Config::$serverKey = '<your serverkey>'; $notif = new Veritrans_Notification(); $transaction = $notif->transaction_status; $type = $notif->payment_type; $order_id = $notif->order_id; $fraud = $notif->fraud_status; 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"; } else { // TODO set payment status in merchant's database to 'Success' echo "Transaction order_id: " . $order_id . " successfully captured using " . $type; } } } else { if ($transaction == 'settlement') { // TODO set payment status in merchant's database to 'Settlement' echo "Transaction order_id: " . $order_id . " successfully transfered using " . $type; } 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; } else {
public function tearDown() { VT_Tests::reset(); Veritrans_Config::$curlOptions = array(); }