mirror of
https://github.com/10h30/vnpay-pay-woocommerce.git
synced 2026-06-05 15:09:47 +09:00
Initial version from VNPay
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"vnpay\\": "src",
|
||||
"vnpay\\Gateways\\": "src/gateways",
|
||||
"vnpay\\Shortcodes\\": "src/shortcodes",
|
||||
"vnpay\\Traits\\": "src/traits"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.2
|
||||
*/
|
||||
|
||||
namespace vnpay\Facades;
|
||||
|
||||
interface FacadeResponse {
|
||||
|
||||
public function getResponseDescription($responseCode);
|
||||
|
||||
public function checkResponse($txnResponseCode);
|
||||
|
||||
public function ipn_url_vnpay($txnResponfseCode);
|
||||
|
||||
public function getOrder($orderId);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.1
|
||||
*/
|
||||
|
||||
namespace vnpay;
|
||||
|
||||
class Page
|
||||
{
|
||||
|
||||
protected $args;
|
||||
|
||||
public function __construct($args)
|
||||
{
|
||||
|
||||
$this->args = $args;
|
||||
$this->createPage();
|
||||
}
|
||||
|
||||
public function createPage()
|
||||
{
|
||||
return wp_insert_post($this->args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace vnpay\Gateways;
|
||||
|
||||
class vnpayGateway extends \WC_Payment_Gateway {
|
||||
|
||||
public function __construct() {
|
||||
$this->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 {
|
||||
?>
|
||||
<div class="inline error">
|
||||
<p>
|
||||
<strong>
|
||||
<?php _e('Gateway Disabled', 'woocommerce'); ?>
|
||||
</strong> :
|
||||
<?php
|
||||
_e('vnpay does not support your store currency. Currently, vnpay only supports VND currency.', 'woocommerce');
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.2
|
||||
*/
|
||||
|
||||
namespace vnpay\Gateways;
|
||||
|
||||
use vnpay\Responses\vnpayResponse;
|
||||
use vnpay\Gateways\vnpayGateway;
|
||||
|
||||
class vnpayInternationalResponse extends vnpayResponse {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getResponseDescription($responseCode) {
|
||||
if ($_GET['vnp_ResponseCode'] == '00') {
|
||||
$result= "Giao dịch thanh toán thành công qua VNPAY";
|
||||
} else {
|
||||
$result= "Giao dịch không thành công";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function thankyou() {
|
||||
$gateway = new vnpayGateway;
|
||||
return $gateway->get_option('receipt_return_url');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace vnpay\Shortcodes;
|
||||
|
||||
class Thankyou
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_shortcode('vnpay_thankyou', array($this, 'callback'));
|
||||
}
|
||||
|
||||
|
||||
public function callback($atts)
|
||||
{
|
||||
$content = "<div style=\"margin-left: 100px;width: 250px;float: left\">";
|
||||
$content.= "<div style=\"color: red;font-size: 20px\">".$_GET["message"]."</div>";
|
||||
$content.= "<div >Mã giao dich: <b>" . $_GET["vnp_TxnRef"] . "</b></div>";
|
||||
$content.= "<div >Số tiền:  <b>" . $_GET["amount"] . "</b></div>";
|
||||
$content.= "<div >Ngân hàng:  <b>" . $_GET["vnp_BankCode"] . "</b></div>";
|
||||
$content.= "<div><a style=\"color: green\" href=" . get_site_url() . ">Về trang chủ</a></div>";
|
||||
$content.= "</div>";
|
||||
echo $content;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.1
|
||||
*/
|
||||
|
||||
namespace vnpay\Traits;
|
||||
|
||||
trait Pages
|
||||
{
|
||||
protected $pages = array(
|
||||
'thank-you' => array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => 'Payment Success',
|
||||
'post_content' => ''
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author thangnh
|
||||
* @since 1.0.2
|
||||
*/
|
||||
|
||||
namespace vnpay\Responses;
|
||||
|
||||
use vnpay\Gateways\vnpayGateway;
|
||||
use vnpay\Facades\FacadeResponse;
|
||||
|
||||
abstract class vnpayResponse implements FacadeResponse {
|
||||
protected $hashCode;
|
||||
public function __construct() {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
require_once __DIR__ . '/composer' . '/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit8f72f3bb7c6ee32c2a5028b2e2d64d68::getLoader();
|
||||
Vendored
+309
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
|
||||
class ClassLoader
|
||||
{
|
||||
// PSR-4
|
||||
private $prefixLengthsPsr4 = array();
|
||||
private $prefixDirsPsr4 = array();
|
||||
private $fallbackDirsPsr4 = array();
|
||||
|
||||
// PSR-0
|
||||
private $prefixesPsr0 = array();
|
||||
private $fallbackDirsPsr0 = array();
|
||||
|
||||
private $useIncludePath = false;
|
||||
private $classMap = array();
|
||||
|
||||
private $classMapAuthoritative = false;
|
||||
|
||||
public function getPrefixes()
|
||||
{
|
||||
if (!empty($this->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;
|
||||
}
|
||||
Vendored
+21
@@ -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.
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'vnpay\\Facades\\FacadeResponse' => $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',
|
||||
);
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
|
||||
$vendorDir = dirname(dirname(__FILE__));
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'vnpay\\Traits\\' => array($baseDir . '/src/traits'),
|
||||
'vnpay\\Shortcodes\\' => array($baseDir . '/src/shortcodes'),
|
||||
'vnpay\\Gateways\\' => array($baseDir . '/src/gateways'),
|
||||
'vnpay\\' => array($baseDir . '/src'),
|
||||
);
|
||||
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ComposerAutoloaderInit8f72f3bb7c6ee32c2a5028b2e2d64d68
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
public static function loadClassLoader($class)
|
||||
{
|
||||
if ('Composer\Autoload\ClassLoader' === $class) {
|
||||
require __DIR__ . '/ClassLoader.php';
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLoader()
|
||||
{
|
||||
if (null !== self::$loader) {
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit8f72f3bb7c6ee32c2a5028b2e2d64d68', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit8f72f3bb7c6ee32c2a5028b2e2d64d68', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 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;
|
||||
}
|
||||
}
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit8f72f3bb7c6ee32c2a5028b2e2d64d68
|
||||
{
|
||||
public static $prefixLengthsPsr4 = array (
|
||||
'W' =>
|
||||
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);
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: VNPAY
|
||||
* Description: Integrate VNPAY paygate into Woocommerce
|
||||
* Version: 1.0.3
|
||||
* Author: VNPAY
|
||||
* Author URI: http://vnpayment.vnpay.vn/
|
||||
* License: NHT
|
||||
*/
|
||||
|
||||
use vnpay\Gateways\vnpayGateway;
|
||||
use vnpay\Gateways\vnpayInternationalResponse;
|
||||
use vnpay\Traits\Pages;
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
//require 'src/return.php';
|
||||
|
||||
/**
|
||||
*/
|
||||
class vnpay
|
||||
{
|
||||
use vnpay\Traits\Pages;
|
||||
|
||||
|
||||
protected $shortcodes = array();
|
||||
|
||||
|
||||
protected $responses;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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;
|
||||
Reference in New Issue
Block a user