commit bed435640487715148543a956d6903fb5a8f63a6 Author: Thuan Bui Date: Sat Oct 1 12:51:02 2022 +0700 Initial version from VNPay diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cdb1fe8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,4 @@ +MIT License + +Copyright (c) 2016 Thang Nguyen + diff --git a/README.md b/README.md new file mode 100644 index 0000000..1095582 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# vnpay \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d81b4c4 --- /dev/null +++ b/composer.json @@ -0,0 +1,10 @@ +{ + "autoload": { + "psr-4": { + "vnpay\\": "src", + "vnpay\\Gateways\\": "src/gateways", + "vnpay\\Shortcodes\\": "src/shortcodes", + "vnpay\\Traits\\": "src/traits" + } + } +} \ No newline at end of file diff --git a/images/logo.png b/images/logo.png new file mode 100644 index 0000000..cc9ac45 Binary files /dev/null and b/images/logo.png differ diff --git a/src/FacadeResponse.php b/src/FacadeResponse.php new file mode 100644 index 0000000..84a4cd0 --- /dev/null +++ b/src/FacadeResponse.php @@ -0,0 +1,20 @@ +args = $args; + $this->createPage(); + } + + public function createPage() + { + return wp_insert_post($this->args); + } +} \ No newline at end of file diff --git a/src/gateways/international/vnpayGateway.php b/src/gateways/international/vnpayGateway.php new file mode 100644 index 0000000..70ecc43 --- /dev/null +++ b/src/gateways/international/vnpayGateway.php @@ -0,0 +1,226 @@ +id = 'vnpay'; + $this->icon = $this->get_option('logo'); + $this->has_fields = false; + $this->method_title = __('vnpay', 'woocommerce'); + + $this->supports = array( + 'products', + 'refunds' + ); + + // Load the settings. + $this->init_form_fields(); + $this->init_settings(); + + // Define user set variables + $this->title = $this->get_option('title'); + $this->description = $this->get_option('description'); + $this->Url = $this->get_option('Url'); + $this->terminal = $this->get_option('terminal'); + $this->secretkey = $this->get_option('secretkey'); + $this->locale = $this->get_option('locale'); + + if (!$this->isValidCurrency()) { + $this->enabled = 'no'; + } + + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array(&$this, 'process_admin_options')); + } + + public function getPagesList() { + $pagesList = array(); + $pages = get_pages(); + if (!empty($pages)) { + foreach ($pages as $page) { + $pagesList[$page->ID] = $page->post_title; + } + } + return $pagesList; + } + + public function init_form_fields() { + + $this->form_fields = array( + 'enabled' => array( + 'title' => __('Enable/Disable', 'woocommerce'), + 'type' => 'checkbox', + 'label' => __('Enable vnpay Paygate', 'woocommerce'), + 'default' => 'yes', + ), + 'title' => array( + 'title' => __('Tiêu đề', 'woocommerce'), + 'type' => 'text', + 'description' => 'Tiêu đề thanh toán', + 'default' => 'Thanh toán qua VNPAY', + 'desc_tip' => true + ), + 'description' => array( + 'title' => __('Mô tả', 'woocommerce'), + 'type' => 'textarea', + 'description' => __('Mô tả phương thức thanh toán', 'woocommerce'), + 'default' => __('Thanh toán trực tuyến qua VNPAY', 'woocommerce'), + 'desc_tip' => true + ), + 'Url' => array( + 'title' => __('VNPAY URL', 'woocommerce'), + 'type' => 'text', + 'description' => 'Url khởi tạo giao dịch sang VNPAY(VNPAY Cung cấp)', + 'default' => '', + 'desc_tip' => true + ), + 'terminal' => array( + 'title' => __('Terminal ID', 'woocommerce'), + 'type' => 'text', + 'description' => 'Mã terminal VNPAY cung cấp', + 'default' => '', + 'desc_tip' => true + ), + 'secretkey' => array( + 'title' => __('Secret Key', 'woocommerce'), + 'type' => 'password', + 'description' => 'Key cấu hình VNPAY cung cấp', + 'default' => '', + 'desc_tip' => true + ), + 'locale' => array( + 'title' => __('Locale', 'woocommerce'), + 'type' => 'select', + 'class' => 'wc-enhanced-select', + 'description' => __('Choose your locale', 'woocommerce'), + 'desc_tip' => true, + 'default' => 'vn', + 'options' => array( + 'vn' => 'vn', + 'en' => 'en' + ) + ), + ); + } + + public function process_payment($order_id) { + $order = new \WC_Order($order_id); + return array( + 'result' => 'success', + 'redirect' => $this->redirect($order_id) + ); + } + + public function redirect($order_id) { + date_default_timezone_set('Asia/Ho_Chi_Minh'); + $order = new \WC_Order($order_id); + $order->update_status('on-hold'); + $order->add_order_note(__('Giao dịch chờ thanh toán hoặc chưa hoàn tất', 'woocommerce')); + + // + $forenamefw = $order->get_billing_first_name(); + $forename = $this->convert_vi_to_en($forenamefw); + $surnamefw = $order->get_billing_last_name(); + $surname = $this->convert_vi_to_en($surnamefw); + $mobile = $order->get_billing_phone(); + $emailfw = $order->get_billing_email(); + $email = $this->convert_vi_to_en($emailfw); + + $amount = number_format($order->order_total, 2, '.', '') * 100; + $vnp_TxnRef = $order_id; + $date = date('Y-m-d H:i:s'); + $vnp_Url = $this->Url; + $vnp_Returnurl = admin_url('admin-ajax.php') . '?action=payment_response&type=international'; + $vnp_TmnCode = $this->terminal; + $hashSecret = $this->secretkey; + $vnp_OrderInfo = 'Ma giao dich thanh toan:'.$order_id .'-'.'Ho va ten KH:'.$surname. ' ' .$forename. '-'.'SDT:'.$mobile.'-'.'Email:'.$email; + $vnp_OrderType = 'orther'; + $vnp_Amount = $amount; + $vnp_Locale = $this->locale; + $vnp_IpAddr = $_SERVER['REMOTE_ADDR']; + $inputData = array( + "vnp_TmnCode" => $vnp_TmnCode, + "vnp_Amount" => $vnp_Amount, + "vnp_Command" => "pay", + "vnp_CreateDate" => date('YmdHis'), + "vnp_CurrCode" => "VND", + "vnp_IpAddr" => $vnp_IpAddr, + "vnp_Locale" => $vnp_Locale, + "vnp_OrderInfo" => $vnp_OrderInfo, + "vnp_OrderType" => $vnp_OrderType, + "vnp_ReturnUrl" => $vnp_Returnurl, + "vnp_TxnRef" => $vnp_TxnRef, + "vnp_Version" => "2.1.0", + ); + ksort($inputData); + $query = ""; + $i = 0; + $hashdata = ""; + foreach ($inputData as $key => $value) { + if ($i == 1) { + $hashdata .= '&' . urlencode($key) . "=" . urlencode($value); + } else { + $hashdata .= urlencode($key) . "=" . urlencode($value); + $i = 1; + } + $query .= urlencode($key) . "=" . urlencode($value) . '&'; + } + $vnp_Url = $vnp_Url . "?" . $query; + if (isset($hashSecret)) { + $vnpSecureHash = hash_hmac('sha512', $hashdata, $hashSecret); + $vnp_Url .= 'vnp_SecureHash=' . $vnpSecureHash; + } + + return $vnp_Url; + } + + public function isValidCurrency() { + return in_array(get_woocommerce_currency(), array('VND')); + } + + function convert_vi_to_en($str) { + $str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str); + $str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str); + $str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str); + $str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str); + $str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str); + $str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str); + $str = preg_replace("/(đ)/", 'd', $str); + $str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str); + $str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str); + $str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str); + $str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str); + $str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str); + $str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str); + $str = preg_replace("/(Đ)/", 'D', $str); + return $str; + } + + public function admin_options() { + if ($this->isValidCurrency()) { + parent::admin_options(); + } else { + ?> +
+

+ + + : + +

+
+ get_option('receipt_return_url'); + } + + + +} diff --git a/src/shortcodes/Thankyou.php b/src/shortcodes/Thankyou.php new file mode 100644 index 0000000..d02f3eb --- /dev/null +++ b/src/shortcodes/Thankyou.php @@ -0,0 +1,31 @@ +"; + $content.= "
".$_GET["message"]."
"; + $content.= "
Mã giao dich: " . $_GET["vnp_TxnRef"] . "
"; + $content.= "
Số tiền:  " . $_GET["amount"] . "
"; + $content.= "
Ngân hàng:  " . $_GET["vnp_BankCode"] . "
"; + $content.= "
Về trang chủ
"; + $content.= ""; + echo $content; + } + +} \ No newline at end of file diff --git a/src/traits/Pages.php b/src/traits/Pages.php new file mode 100644 index 0000000..fe48cf0 --- /dev/null +++ b/src/traits/Pages.php @@ -0,0 +1,20 @@ + array( + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Payment Success', + 'post_content' => '' + ) + ); +} \ No newline at end of file diff --git a/src/vnpayResponse.php b/src/vnpayResponse.php new file mode 100644 index 0000000..e2b5832 --- /dev/null +++ b/src/vnpayResponse.php @@ -0,0 +1,137 @@ +action(); + } + + public function action() { + add_action('wp_ajax_payment_response', array($this, 'checkResponse')); + add_action('wp_ajax_nopriv_payment_response', array($this, 'checkResponse')); + add_action('wp_ajax_payment_response_vnpay', array($this, 'ipn_url_vnpay')); + add_action('wp_ajax_nopriv_payment_response_vnpay', array($this, 'ipn_url_vnpay')); + } + + public function checkResponse($txnResponseCode) { + global $woocommerce; + $woocommerce->cart->get_checkout_url(); + $order = $this->getOrder($_GET["vnp_TxnRef"]); + $url = wc_get_checkout_url() . 'order-received/' . $order->id . '/?key=' . $order->order_key; + wp_redirect($url); + WC()->cart->empty_cart(); + exit(); + } + + public function ipn_url_vnpay($txnResponseCode) { + global $woocommerce; + $transStatus = ''; + $checkoutUrl = $woocommerce->cart->get_checkout_url(); + + $order = $this->getOrder($_GET["vnp_TxnRef"]); + $gateway = new vnpayGateway; + $hashSecret = $gateway->get_option('secretkey'); + + // ($hashSecret); + $params = array(); + $returnData = array(); + $data = $_GET; + + foreach ($data as $key => $value) { + if (substr($key, 0, 4) == "vnp_") { + $params[$key] = $value; + } + } + $vnp_SecureHash = $params['vnp_SecureHash']; + unset($params['vnp_SecureHashType']); + unset($params['action']); + unset($params['type']); + unset($params['vnp_SecureHash']); + ksort($params); + $i = 0; + $hashData = ""; + foreach ($params as $key => $value) { + if ($i == 1) { + $hashData = $hashData . '&' . urlencode($key). "=" . urlencode($value); + } else { + $hashData = $hashData . urlencode($key) . "=" . urlencode($value); + $i = 1; + } + } + $secureHash = hash_hmac('sha512', $hashData, $hashSecret); +//Check Orderid + if ($order->post_status != \NULL && $order->post_status != '') { + //Check chữ ký + if ($secureHash == $vnp_SecureHash) { + //Check Status của đơn hàng + if ($order->post_status != \NULL && $order->post_status == 'wc-on-hold'){ + if ($params['vnp_ResponseCode'] == '00') { + $returnData['RspCode'] = '00'; + $returnData['Message'] = 'Confirm Success'; + $returnData['Signature'] = $secureHash; + $transStatus = $this->getResponseDescription($txnResponseCode); + $order->update_status('processing'); + $order->add_order_note(__($transStatus, 'woocommerce')); + WC()->cart->empty_cart(); + } + elseif ($params['vnp_ResponseCode'] == '24') { + $returnData['RspCode'] = '00'; + $returnData['Message'] = 'Confirm Success'; + $returnData['Signature'] = $secureHash; + $order->update_status('cancelled'); + $order->add_order_note(__('Khách hàng hủy giao dịch', 'woocommerce')); + WC()->cart->empty_cart(); + } + else + { + $returnData['RspCode'] = '00'; + $returnData['Message'] = 'Confirm Success'; + $returnData['Signature'] = $secureHash; + $transStatus = $this->getResponseDescription($txnResponseCode); + $order->add_order_note(__($transStatus, 'woocommerce')); + $order->update_status('failed'); + WC()->cart->empty_cart(); + } + } else { + $returnData['RspCode'] = '02'; + $returnData['Message'] = 'Order already confirmed'; + WC()->cart->empty_cart(); + } + } else { + $returnData['RspCode'] = '97'; + $returnData['Message'] = 'Chu ky khong hop le'; + $returnData['Signature'] = $secureHash; + WC()->cart->empty_cart(); + } + } else { + $returnData['RspCode'] = '01'; + $returnData['Message'] = 'Order not found'; + WC()->cart->empty_cart(); + } + echo json_encode($returnData); + exit(); + } + + abstract public function thankyou(); + + abstract public function getResponseDescription($responseCode); + + public function getOrder($orderId) { + preg_match_all('!\d+!', $orderId, $matches); + $order = new \WC_Order($matches[0][0]); + return $order; + } + +} diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 0000000..e69de29 diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 0000000..2b08e65 --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,6 @@ +prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + + public function findFile($class) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative) { + return false; + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if ($file === null && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if ($file === null) { + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE new file mode 100644 index 0000000..1a28124 --- /dev/null +++ b/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) 2016 Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 0000000..d1ae869 --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,16 @@ + $baseDir . '/src/FacadeResponse.php', + 'vnpay\\Gateways\\vnpayGateway' => $baseDir . '/src/gateways/international/vnpayGateway.php', + 'vnpay\\Gateways\\vnpayInternationalResponse' => $baseDir . '/src/gateways/international/vnpayInternationalResponse.php', + 'vnpay\\Page' => $baseDir . '/src/Page.php', + 'vnpay\\Responses\\vnpayResponse' => $baseDir . '/src/vnpayResponse.php', + 'vnpay\\Shortcodes\\Thankyou' => $baseDir . '/src/shortcodes/Thankyou.php', + 'vnpay\\Traits\\Pages' => $baseDir . '/src/traits/Pages.php', +); + diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php new file mode 100644 index 0000000..2b2735d --- /dev/null +++ b/vendor/composer/autoload_namespaces.php @@ -0,0 +1,8 @@ + array($baseDir . '/src/traits'), + 'vnpay\\Shortcodes\\' => array($baseDir . '/src/shortcodes'), + 'vnpay\\Gateways\\' => array($baseDir . '/src/gateways'), + 'vnpay\\' => array($baseDir . '/src'), +); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php new file mode 100644 index 0000000..b1b4f15 --- /dev/null +++ b/vendor/composer/autoload_real.php @@ -0,0 +1,51 @@ += 50600 && !defined('HHVM_VERSION'); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit8f72f3bb7c6ee32c2a5028b2e2d64d68::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php new file mode 100644 index 0000000..7ced056 --- /dev/null +++ b/vendor/composer/autoload_static.php @@ -0,0 +1,56 @@ + + array ( + 'vnpay\\Traits\\' => 17, + 'vnpay\\Shortcodes\\' => 21, + 'vnpay\\Gateways\\' => 19, + 'vnpay\\' => 10, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'vnpay\\Traits\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/traits', + ), + 'vnpay\\Shortcodes\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/shortcodes', + ), + 'vnpay\\Gateways\\' => + array ( + 0 => __DIR__ . '/../..' . '/src/gateways', + ), + 'vnpay\\' => + array ( + 0 => __DIR__ . '/../..' . '/src', + ), + ); + + public static $classMap = array ( + 'vnpay\\Facades\\FacadeResponse' => __DIR__ . '/../..' . '/src/FacadeResponse.php', + 'vnpay\\Gateways\\vnpayGateway' => __DIR__ . '/../..' . '/src/gateways/international/vnpayGateway.php', + 'vnpay\\Gateways\\vnpayInternationalResponse' => __DIR__ . '/../..' . '/src/gateways/international/vnpayInternationalResponse.php', + 'vnpay\\Page' => __DIR__ . '/../..' . '/src/Page.php', + 'vnpay\\Responses\\vnpayResponse' => __DIR__ . '/../..' . '/src/vnpayResponse.php', + 'vnpay\\Shortcodes\\Thankyou' => __DIR__ . '/../..' . '/src/shortcodes/Thankyou.php', + 'vnpay\\Traits\\Pages' => __DIR__ . '/../..' . '/src/traits/Pages.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInit8f72f3bb7c6ee32c2a5028b2e2d64d68::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit8f72f3bb7c6ee32c2a5028b2e2d64d68::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit8f72f3bb7c6ee32c2a5028b2e2d64d68::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1 @@ +[] diff --git a/vnpay.php b/vnpay.php new file mode 100644 index 0000000..4db0b20 --- /dev/null +++ b/vnpay.php @@ -0,0 +1,124 @@ +constants(); + add_action('init', array($this, 'renderPages')); + add_action('plugins_loaded', array($this, 'vnpayInit')); + add_filter('woocommerce_locate_template', array($this, 'vnpayWoocommerceTemplates'), 10, 3); + $this->loadModule(); + $this->responseListener(); + } + + + public function constants() + { + $consts = array( + 'URL' => plugins_url('', __FILE__), + 'IMAGE' => plugins_url('/images', __FILE__) + ); + + foreach ($consts as $key => $value) { + define($key, $value); + } + } + + + public function vnpayInit() + { + add_filter('woocommerce_payment_gateways', array($this, 'addPaymentMethod')); + } + + + public function addPaymentMethod($methods) + { + $methods[] = 'vnpay\Gateways\vnpayGateway'; + return $methods; + } + + + public function loadModule() + { + $this->shortcodes[] = new vnpay\Shortcodes\Thankyou; + } + + public function responseListener() + { + if (isset($_GET['type'])) { + switch ($_GET['type']) { + case 'international': + $this->responses[] = new vnpayInternationalResponse; + break; + + } + } + } + + + public function renderPages() + { + $checkRenderPage = (!get_option('vnpay_settings')) ? false : get_option('vnpay_settings'); + if ($checkRenderPage != false) return; + if (!empty($this->pages)) { + foreach ($this->pages as $slug => $args) { + $page = new vnpay\Page($args); + } + update_option('vnpay_settings', true); + } + } + + public function vnpayWoocommerceTemplates($template, $template_name, $template_path) + { + global $woocommerce; + + $_template = $template; + + if (!$template_path) $template_path = $woocommerce->template_url; + + $plugin_path = __DIR__ . '/woocommerce/'; + + $template = locate_template( + array( + $template_path . $template_name, + $template_name + ) + ); + + if (!$template && file_exists( $plugin_path . $template_name)) + + $template = $plugin_path . $template_name; + + if (!$template) $template = $_template; + + return $template; + } +} + +new vnpay; \ No newline at end of file