forked from tareq1988/woocommerce-bkash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bkash.php
110 lines (91 loc) · 2.59 KB
/
bkash.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
Plugin Name: bKash for WooCommerce
Plugin URI: https://wordpress.org/plugins/woocommerce-bkash/
Description: bKash payment gateway integration for WooCommerce
Version: 1.1.1
Author: Tareq Hasan
Author URI: https://tareq.co
License: GPL2
*/
// don't call the file directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* WooCommerce - bKash integration
*
* @author Tareq Hasan
*/
class WeDevs_bKash {
private $db_version = '1.0';
private $version_key = '_bkash_version';
/**
* Kick off the plugin
*/
public function __construct() {
add_action( 'plugins_loaded', array($this, 'init') );
add_filter( 'woocommerce_payment_gateways', array($this, 'register_gateway') );
register_activation_hook( __FILE__, array($this, 'install') );
}
/**
* Load the plugin on `init` hook
*
* @return void
*/
function init() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
return;
}
require_once dirname( __FILE__ ) . '/includes/class-wc-bkash.php';
require_once dirname( __FILE__ ) . '/includes/class-wc-gateway-bkash.php';
}
/**
* Register WooCommerce Gateway
*
* @param array $gateways
*
* @return array
*/
function register_gateway( $gateways ) {
$gateways[] = 'WC_Gateway_bKash';
return $gateways;
}
/**
* Create the transaction table
*
* @return void
*/
function install() {
global $wpdb;
$query = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}wc_bkash` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`trxId` int(11) DEFAULT NULL,
`sender` varchar(15) DEFAULT NULL,
`ref` varchar(100) DEFAULT NULL,
`amount` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `trxId` (`trxId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$wpdb->query( $query );
$this->plugin_upgrades();
update_option( $this->version_key, $this->db_version );
}
/**
* Do plugin upgrade tasks
*
* @return void
*/
private function plugin_upgrades() {
global $wpdb;
$version = get_option( $this->version_key, '0.1' );
if ( version_compare( $this->db_version, $version, '<=' ) ) {
return;
}
switch ( $version ) {
case '0.1':
$sql = "ALTER TABLE `{$wpdb->prefix}wc_bkash` CHANGE `trxId` `trxId` BIGINT(20) NULL DEFAULT NULL;";
$wpdb->query( $sql );
break;
}
}
}
new WeDevs_bKash();