コード例 #1
0
 public function testCancelPermataVa()
 {
     $charge_params = VtChargeFixture::build('bank_transfer', array("bank" => "permata"));
     $charge_response = Veritrans_VtDirect::charge($charge_params);
     $cancel_status_code = Veritrans_Transaction::cancel($charge_response->transaction_id);
     $this->assertEquals($cancel_status_code, '200');
 }
コード例 #2
0
 public function testChargeIndomaret()
 {
     $this->prepareChargeParams('cstore', array("store" => "indomaret", "message" => "Item descriptions"));
     $this->charge_response = Veritrans_VtDirect::charge($this->charge_params);
     $this->assertEquals($this->charge_response->transaction_status, 'pending');
     $this->assertTrue(isset($this->charge_response->payment_code));
 }
コード例 #3
0
 public function testExpirePermataVa()
 {
     $charge_params = VtChargeFixture::build('bank_transfer', array("bank" => "permata"));
     $charge_response = Veritrans_VtDirect::charge($charge_params);
     $expire = Veritrans_Transaction::expire($charge_response->transaction_id);
     $this->assertEquals($expire->status_code, '407');
     // Verify transaction via API
     $txn_status = Veritrans_Transaction::status($charge_response->transaction_id);
     $this->assertEquals($txn_status->status_code, "407");
     $this->assertEquals($txn_status->transaction_status, "expire");
 }
コード例 #4
0
 public function payment($order_id, $order, $save_cc = false)
 {
     $VT_Config = new \Veritrans_Config();
     //set server key
     $VT_Config::$serverKey = $this->server_key;
     // Development Environment (the default), use sandbox
     $VT_Config::$isProduction = false;
     // Set sanitization off (default)
     $VT_Config::$isSanitized = false;
     /*==================== dummy data, should have set from $payment variable =========================*/
     $transaction_details = array('order_id' => $order_id, 'gross_amount' => $order['order_totals']['grandtotal']);
     // Populate items
     $items = array();
     foreach ($order['order_products'] as $key => $item) {
         $items[$key]['id'] = $item['product_id'];
         $items[$key]['price'] = $item['price'];
         $items[$key]['quantity'] = $item['quantity'];
         $items[$key]['name'] = $item['product_name'];
     }
     //additional cost
     $add_cost = AdditionalCost::find('shipping_handling');
     array_push($items, ['id' => $add_cost->cost_id, 'price' => $order['order_totals']['shipping_handling'], 'quantity' => 1, 'name' => $add_cost->cost_title]);
     // Populate customer's shipping address
     $shipping_address = array('first_name' => $order['firstname'], 'last_name' => $order['lastname'], 'address' => $order['shipping_address'][0] ? $order['shipping_address'][0] : $order['shipping_address'][1], 'city' => $order['shipping_city'], 'postal_code' => $order['shipping_postcode'], 'phone' => $order['phone'], 'country_code' => $this->getCountryCode($order['shipping_country']));
     // Populate customer's billing address
     $billing_address = $shipping_address;
     // Populate customer's info
     $customer_details = array('first_name' => $order['firstname'], 'last_name' => $order['lastname'], 'email' => $order['email'], 'phone' => $order['phone'], 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
     // Token ID from checkout page
     $token_id = $order['credit_card']['token_id'];
     //$_POST['token_id'];
     // Transaction data to be sent
     $transaction_data = array('payment_type' => 'credit_card', 'credit_card' => array('token_id' => $token_id, 'bank' => 'bni', 'save_token_id' => isset($_POST['save_cc'])), 'transaction_details' => $transaction_details, 'item_details' => $items, 'customer_details' => $customer_details);
     // dd($transaction_data);
     /*===================================== dummy data end ===========================================*/
     # send data ke veritrans
     $response = \Veritrans_VtDirect::charge($transaction_data);
     if (is_array($response) && $response[1]) {
         if (!in_array($response[1], array(200, 201, 202, 407))) {
             return $response;
         }
     }
     # set callback response
     return $this->callback($response);
 }
コード例 #5
0
 public function testCapture()
 {
     VT_Tests::$stubHttp = true;
     VT_Tests::$stubHttpResponse = '{
     "status_code": "200",
     "status_message": "Success, Credit Card capture transaction is successful",
     "transaction_id": "1ac1a089d-a587-40f1-a936-a7770667d6dd",
     "order_id": "A27550",
     "payment_type": "credit_card",
     "transaction_time": "2014-08-25 10:20:54",
     "transaction_status": "capture",
     "fraud_status": "accept",
     "masked_card": "481111-1114",
     "bank": "bni",
     "approval_code": "1408937217061",
     "gross_amount": "55000.00"
   }';
     $capture = Veritrans_VtDirect::capture("A27550");
     $this->assertEquals($capture->status_code, "200");
     $this->assertEquals(VT_Tests::$lastHttpRequest["url"], "https://api.sandbox.veritrans.co.id/v2/capture");
     $fields = VT_Tests::lastReqOptions();
     $this->assertEquals($fields["POST"], 1);
     $this->assertEquals($fields["POSTFIELDS"], '{"transaction_id":"A27550"}');
 }
コード例 #6
0
 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;
     }
 }
コード例 #7
0
ファイル: PaymentController.php プロジェクト: victorkho/telor
 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));
     }
 }
コード例 #8
0
 public function payWithBankTransfer()
 {
     // Data that will be send for credit card charge TRANSACTION request.
     $transaction_data = array('payment_type' => 'bank_transfer', 'bank_transfer' => array('bank' => 'permata'), 'transaction_details' => $this->transaction_details);
     $result = \Veritrans_VtDirect::charge($transaction_data);
     $code_booking = $this->code_booking;
     if ($result->status_code == "201") {
         // pending
         Mail::send('payment::mail-templates.va-instruction', compact('result', 'code_booking'), function ($message) use($result) {
             $message->to(Session::get(Session::get('type'))['DATA_COSTUMER']['COSTUMER_EMAIL'], Session::get('DATA_COSTUMER')['COSTUMER_NAME'])->subject('Instruksi Pembayaran ' . $result->order_id);
         });
     }
     return $result->status_code;
 }
コード例 #9
0
ファイル: PaymentController.php プロジェクト: victorkho/telor
 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));
     }
 }
コード例 #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('core/session')->setPaymentData(); when checkout */
     $pay = Mage::getSingleton('core/session')->getPaymentData();
     $payment_type = Mage::getStoreConfig('payment/vtdirect/payment_types');
     Veritrans_Config::$isProduction = Mage::getStoreConfig('payment/vtdirect/environment') == 'production' ? true : false;
     Veritrans_Config::$serverKey = Mage::getStoreConfig('payment/vtdirect/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' => substr($each->getName(), 0, 50));
         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/vtdirect/conversion_rate');
         };
         foreach ($item_details as &$item) {
             $item['price'] = call_user_func($conversion_func, intval(round($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'] = 'credit_card';
     $payloads['credit_card'] = array('token_id' => $pay['token-id'], 'bank' => Mage::getStoreConfig('payment/vtdirect/bank'));
     try {
         $response = Veritrans_VtDirect::charge($payloads);
         Mage::log('payloads= ' . print_r($payloads, true), null, 'vtdirect_veritrans.log', true);
         Mage::log('response= ' . print_r($response, true), null, 'vtdirect_veritrans.log', true);
         if ($response->status_code == '200' || $response->status_code == '201') {
             if ($response->status_code == '200') {
                 $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
                 $order->save();
             } else {
                 $order->setStatus(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW);
                 $order->save();
             }
             // Redirected by Veritrans, if ok
             Mage::getSingleton('checkout/session')->unsQuoteId();
             //delete item from cart
             foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item) {
                 Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
             }
             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/', array('_secure' => true));
         }
     } catch (Exception $e) {
         Mage::log($e, null, 'vtdirect_veritrans.log', true);
         error_log($e);
         error_log($e->getMessage());
         Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure' => true));
     }
 }
コード例 #11
0
// Veritrans_Config::$isSanitized = true;
$transaction_details = array('order_id' => time(), 'gross_amount' => 200000);
// Populate items
$items = array(array('id' => 'item1', 'price' => 100000, 'quantity' => 1, 'name' => 'Adidas f50'), array('id' => 'item2', 'price' => 50000, 'quantity' => 2, 'name' => 'Nike N90'));
// Populate customer's billing address
$billing_address = array('first_name' => "Andri", 'last_name' => "Setiawan", 'address' => "Karet Belakang 15A, Setiabudi.", 'city' => "Jakarta", 'postal_code' => "51161", 'phone' => "081322311801", 'country_code' => 'IDN');
// Populate customer's shipping address
$shipping_address = array('first_name' => "John", 'last_name' => "Watson", 'address' => "Bakerstreet 221B.", 'city' => "Jakarta", 'postal_code' => "51162", 'phone' => "081322311801", 'country_code' => 'IDN');
// Populate customer's info
$customer_details = array('first_name' => "Andri", 'last_name' => "Setiawan", 'email' => "*****@*****.**", 'phone' => "081322311801", 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
// Token ID from checkout page
$token_id = $_POST['token_id'];
// Transaction data to be sent
$transaction_data = array('payment_type' => 'credit_card', 'credit_card' => array('token_id' => $token_id, 'bank' => 'bni', 'save_token_id' => isset($_POST['save_cc'])), 'transaction_details' => $transaction_details, 'item_details' => $items, 'customer_details' => $customer_details);
try {
    $response = Veritrans_VtDirect::charge($transaction_data);
} catch (Exception $e) {
    echo $e->getMessage();
    die;
}
// Success
if ($response->transaction_status == 'capture') {
    echo "<p>Transaksi berhasil.</p>";
    echo "<p>Status transaksi untuk order id {$response->order_id}: " . "{$response->transaction_status}</p>";
    echo "<h3>Detail transaksi:</h3>";
    echo "<pre>";
    var_dump($response);
    echo "</pre>";
} else {
    if ($response->transaction_status == 'deny') {
        echo "<p>Transaksi ditolak.</p>";
コード例 #12
0
 public function setUp()
 {
     $charge_params = VtChargeFixture::build('bri_epay');
     $charge_response = Veritrans_VtDirect::charge($charge_params);
     $this->status_response = Veritrans_Transaction::status($charge_response->transaction_id);
 }