├── README.md ├── bkash.php ├── images └── bkash-logo.png ├── includes ├── class-wc-bkash.php └── class-wc-gateway-bkash.php ├── plugin-deploy.sh └── readme.txt /README.md: -------------------------------------------------------------------------------- 1 | # WooCommerce bKash 2 | 3 | bKash Payment Gateway for WooCommerce 4 | 5 | This is a very good and excellent plugin to shop online around Bangladesh using bKash payment gateway. If you(Store owner)'re using [WooCommerce](http://www.woothemes.com/woocommerce/) for your store, you should choose bKash for local payment for your shop. 6 | 7 | ### Here is how to use: 8 | 9 | * Download the plugin from [WordPress.org](https://wordpress.org/plugins/woocommerce-bkash/). Typically, your developer will do it for you, if you're not a developer yourself. 10 | 11 | * Install and active it, as you normally install and active other plugin too, 12 | 13 | * Normally, you would not find any settings or options to use in the Dashboard, rather go to WooCommerce > Settings from your Dashboard, location URL would be exactly like below - 14 | 15 | ``` 16 | http://yoursite.ext/wp-admin/admin.php?page=wc-settings 17 | ``` 18 | 19 | * Now click on Checkout tab and you'll now see the bKash link, Click and enter the bKash setting page, 20 | 21 | * Now, do Check the checkbox, if the Enable/Disable option is unchecked, This option must be checked to show this payment method in checkout page. 22 | 23 | * Give a custom Title text by yourself or keep it as is in the text field, 24 | 25 | * Give a Description as you did in the title or keep it as is, 26 | 27 | * Write an Instructions on how do your customer pay you using their bKash account. It'll be showing in front of them when they select bKash Payment option and did complete their Checkout process. 28 | 29 | ### Generally the message would be - 30 | 31 | >Send your payment directly to 01*** *** ***(Your merchant number here) via bKash. Please use your Order ID as the payment reference. Your order won't be shipped until the fund have cleared in our account. 32 | > 33 | >#### How to send payment: 34 | 35 | >1. Dial *247# 36 | >2. Select or Press 3 for "Payment" option 37 | >3. Enter our bKash wallet number 01*** *** ***(Your merchant number here) 38 | >4. Enter amount of fee that you ordered already 39 | >5. Enter a reference, use your Order ID as reference 40 | >6. Enter 1 as counter number 41 | >7 Enter your bKash menu PIN to confirm payment 42 | >8. You'll be getting a confirmation message in a while 43 | >9. That's it! :) 44 | 45 | * Write a custom Transaction Help Text or keep it as is. It'll be showing above the transaction confirmation box! 46 | 47 | * Now you are in the main point - 48 | 49 | Its time to take your bKash Merchant API Access Username and Password from your [bKash Account Manager](http://www.bkash.com/support/contact-us). You should now call them and take the info right around. When you're getting the desired access info, now enter the Username into Merchant Username filed and Password into Merchant Password field in the bKash settings page. And don't forget to enter the Merchant mobile number into the last field. Otherwise your this plugin doesn't work! 50 | 51 | * If everything sounds good, you're ready to sale your product using bKash! :) -------------------------------------------------------------------------------- /bkash.php: -------------------------------------------------------------------------------- 1 | prefix}wc_bkash` ( 71 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 72 | `trxId` int(11) DEFAULT NULL, 73 | `sender` varchar(15) DEFAULT NULL, 74 | `ref` varchar(100) DEFAULT NULL, 75 | `amount` varchar(10) DEFAULT NULL, 76 | PRIMARY KEY (`id`), 77 | KEY `trxId` (`trxId`) 78 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; 79 | 80 | $wpdb->query( $query ); 81 | 82 | $this->plugin_upgrades(); 83 | 84 | update_option( $this->version_key, $this->db_version ); 85 | } 86 | 87 | /** 88 | * Do plugin upgrade tasks 89 | * 90 | * @return void 91 | */ 92 | private function plugin_upgrades() { 93 | global $wpdb; 94 | 95 | $version = get_option( $this->version_key, '0.1' ); 96 | 97 | if ( version_compare( $this->db_version, $version, '<=' ) ) { 98 | return; 99 | } 100 | 101 | switch ( $version ) { 102 | case '0.1': 103 | $sql = "ALTER TABLE `{$wpdb->prefix}wc_bkash` CHANGE `trxId` `trxId` BIGINT(20) NULL DEFAULT NULL;"; 104 | $wpdb->query( $sql ); 105 | break; 106 | } 107 | } 108 | } 109 | 110 | new WeDevs_bKash(); -------------------------------------------------------------------------------- /images/bkash-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tareq1988/woocommerce-bkash/524554ebf398958b2f83e63287b50b8fdc03bbc0/images/bkash-logo.png -------------------------------------------------------------------------------- /includes/class-wc-bkash.php: -------------------------------------------------------------------------------- 1 | has_status( 'on-hold' ) && $order->payment_method == 'bkash' && ( is_view_order_page() || is_order_received_page() ) ) { 20 | self::tranasaction_form( $order->id ); 21 | } 22 | } 23 | 24 | /** 25 | * Show the payment field in checkout 26 | * 27 | * @return void 28 | */ 29 | public static function tranasaction_form( $order_id ) { 30 | $option = get_option( 'woocommerce_bKash_settings', array() ); 31 | ?> 32 | 33 |
34 |
35 |
36 |

37 | 38 | 39 | 40 | 41 |

42 | 43 |

44 | 45 | 46 | 47 | 48 | 49 | 50 |

51 |
52 |
53 | 54 | 74 | do_request( $transaction_id ); 87 | 88 | if ( ! $response ) { 89 | wp_send_json_error( __( 'Something went wrong submitting the request', 'wc-bkash' ) ); 90 | return; 91 | } 92 | 93 | if ( $this->transaction_exists( $response->trxId ) ) { 94 | wp_send_json_error( __('This transaction has already been used!', 'wc-bkash' ) ); 95 | return; 96 | } 97 | 98 | switch ($response->trxStatus) { 99 | 100 | case '0010': 101 | case '0011': 102 | wp_send_json_error( __( 'Transaction is pending, please try again later', 'wc-bkash' ) ); 103 | return; 104 | 105 | case '0100': 106 | wp_send_json_error( __( 'Transaction ID is valid but transaction has been reversed. ', 'wc-bkash' ) ); 107 | return; 108 | 109 | case '0111': 110 | wp_send_json_error( __( 'Transaction is failed.', 'wc-bkash' ) ); 111 | return; 112 | 113 | case '1001': 114 | wp_send_json_error( __( 'Invalid MSISDN input. Try with correct mobile no.', 'wc-bkash' ) ); 115 | break; 116 | 117 | case '1002': 118 | wp_send_json_error( __( 'Invalid transaction ID', 'wc-bkash' ) ); 119 | return; 120 | 121 | case '1003': 122 | wp_send_json_error( __( 'Authorization Error, please contact site admin.', 'wc-bkash' ) ); 123 | return; 124 | 125 | case '1004': 126 | wp_send_json_error( __( 'Transaction ID not found.', 'wc-bkash' ) ); 127 | return; 128 | 129 | case '9999': 130 | wp_send_json_error( __( 'System error, could not process request. Please contact site admin.', 'wc-bkash' ) ); 131 | return; 132 | 133 | case '0000': 134 | $price = (float) $order->get_total(); 135 | 136 | // check for BDT if exists 137 | $bdt_price = get_post_meta( $order->id, '_bdt', true ); 138 | if ( $bdt_price != '' ) { 139 | $price = $bdt_price; 140 | } 141 | 142 | if ( $price > (float) $response->amount ) { 143 | wp_send_json_error( __( 'Transaction amount didn\'t match, are you cheating?', 'wc-bkash' ) ); 144 | return; 145 | } 146 | 147 | $this->insert_transaction( $response ); 148 | 149 | $order->add_order_note( sprintf( __( 'bKash payment completed with TrxID#%s! bKash amount: %s', 'wc-bkash' ), $response->trxId, $response->amount ) ); 150 | $order->payment_complete(); 151 | 152 | wp_send_json_success( $order->get_view_order_url() ); 153 | 154 | break; 155 | } 156 | 157 | wp_send_json_error(); 158 | } 159 | 160 | /** 161 | * Do the remote request 162 | * 163 | * For some reason, WP_HTTP doesn't work here. May be 164 | * some implementation related problem in their side. 165 | * 166 | * @param string $transaction_id 167 | * 168 | * @return object 169 | */ 170 | function do_request( $transaction_id ) { 171 | 172 | $option = get_option( 'woocommerce_bKash_settings', array() ); 173 | $query = array( 174 | 'user' => isset( $option['username'] ) ? $option['username'] : '', 175 | 'pass' => isset( $option['pass'] ) ? $option['pass'] : '', 176 | 'msisdn' => isset( $option['mobile'] ) ? $option['mobile'] : '', 177 | 'trxid' => $transaction_id 178 | ); 179 | 180 | $url = self::base_url . '?' . http_build_query( $query, '', '&' ); 181 | $response = file_get_contents( $url ); 182 | 183 | if ( false !== $response ) { 184 | $response = json_decode( $response ); 185 | 186 | return $response->transaction; 187 | } 188 | 189 | return false; 190 | } 191 | 192 | /** 193 | * Insert transaction info in the db table 194 | * 195 | * @param object $response 196 | * 197 | * @return void 198 | */ 199 | function insert_transaction( $response ) { 200 | global $wpdb; 201 | 202 | $wpdb->insert( $wpdb->prefix . $this->table, array( 203 | 'trxId' => $response->trxId, 204 | 'sender' => $response->sender, 205 | 'ref' => $response->reference, 206 | 'amount' => $response->amount 207 | ), array( 208 | '%d', 209 | '%s', 210 | '%s', 211 | '%s' 212 | ) ); 213 | } 214 | 215 | /** 216 | * Check if a transaction exists 217 | * 218 | * @param string $transaction_id 219 | * 220 | * @return bool 221 | */ 222 | function transaction_exists( $transaction_id ) { 223 | global $wpdb; 224 | 225 | $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}{$this->table} WHERE trxId = %d", $transaction_id ); 226 | $result = $wpdb->get_row( $query ); 227 | 228 | if ( $result ) { 229 | return true; 230 | } 231 | 232 | return false; 233 | } 234 | } 235 | 236 | new WC_bKash(); -------------------------------------------------------------------------------- /includes/class-wc-gateway-bkash.php: -------------------------------------------------------------------------------- 1 | id = 'bkash'; 15 | $this->icon = false; 16 | $this->has_fields = true; 17 | $this->method_title = __( 'bKash', 'wc-bkash' ); 18 | $this->method_description = __( 'Pay via bKash payment', 'wc-bkash' ); 19 | $this->icon = apply_filters( 'woo_bkash_logo', plugins_url( 'images/bkash-logo.png', dirname( __FILE__ ) ) ); 20 | 21 | $title = $this->get_option( 'title' ); 22 | $this->title = empty( $title ) ? __( 'bKash', 'wc-bkash' ) : $title; 23 | $this->description = $this->get_option( 'description' ); 24 | $this->instructions = $this->get_option( 'instructions', $this->description ); 25 | 26 | $this->init_form_fields(); 27 | $this->init_settings(); 28 | 29 | add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); 30 | add_action( 'woocommerce_thankyou_bKash', array( $this, 'thankyou_page' ) ); 31 | add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options') ); 32 | } 33 | 34 | /** 35 | * Admin configuration parameters 36 | * 37 | * @return void 38 | */ 39 | public function init_form_fields() { 40 | $this->form_fields = array( 41 | 'enabled' => array( 42 | 'title' => __( 'Enable/Disable', 'wc-bkash' ), 43 | 'type' => 'checkbox', 44 | 'label' => __( 'Enable bKash', 'wc-bkash' ), 45 | 'default' => 'yes' 46 | ), 47 | 'title' => array( 48 | 'title' => __( 'Title', 'wc-bkash' ), 49 | 'type' => 'text', 50 | 'default' => __( 'bKash Payment', 'wc-bkash' ), 51 | ), 52 | 'description' => array( 53 | 'title' => __( 'Description', 'wc-bkash' ), 54 | 'type' => 'textarea', 55 | 'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-bkash' ), 56 | 'default' => __( 'Send your payment directly to +8801****** via bKash. Please use your Order ID as the payment reference. Your order won\'t be shipped until the funds have cleared in our account.', 'wc-bkash' ), 57 | 'desc_tip' => true, 58 | ), 59 | 'instructions' => array( 60 | 'title' => __( 'Instructions', 'wc-bkash' ), 61 | 'type' => 'textarea', 62 | 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'wc-bkash' ), 63 | 'default' => __( 'Send your payment directly to +8801****** via bKash. Please use your Order ID as the payment reference. Your order won\'t be shipped until the funds have cleared in our account.', 'wc-bkash' ), 64 | 'desc_tip' => true, 65 | ), 66 | 'trans_help' => array( 67 | 'title' => __( 'Transaction Help Text', 'wc-bkash' ), 68 | 'type' => 'textarea', 69 | 'description' => __( 'Instructions that will be added to the transaction form.', 'wc-bkash' ), 70 | 'default' => __( 'Please enter your transaction ID from the bKash payment to confirm the order.', 'wc-bkash' ), 71 | 'desc_tip' => true, 72 | ), 73 | 'username' => array( 74 | 'title' => __( 'Merchant Username', 'wc-bkash' ), 75 | 'type' => 'text', 76 | ), 77 | 'pass' => array( 78 | 'title' => __( 'Merchant password', 'wc-bkash' ), 79 | 'type' => 'text', 80 | ), 81 | 'mobile' => array( 82 | 'title' => __( 'Merchant mobile no.', 'wc-bkash' ), 83 | 'type' => 'text', 84 | 'description' => __( 'Enter your registered merchant mobile number.', 'wc-bkash' ), 85 | ), 86 | ); 87 | } 88 | 89 | /** 90 | * Output for the order received page. 91 | * 92 | * @return void 93 | */ 94 | public function thankyou_page( $order_id ) { 95 | 96 | if ( $this->instructions ) { 97 | echo wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ); 98 | } 99 | 100 | $order = wc_get_order( $order_id ); 101 | 102 | if ( $order->has_status( 'on-hold' ) ) { 103 | WC_bKash::tranasaction_form( $order_id ); 104 | } 105 | } 106 | 107 | /** 108 | * Add content to the WC emails. 109 | * 110 | * @access public 111 | * @param WC_Order $order 112 | * @param bool $sent_to_admin 113 | * @param bool $plain_text 114 | * 115 | * @return void 116 | */ 117 | public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { 118 | 119 | if ( ! $sent_to_admin && 'bKash' === $order->payment_method && $order->has_status( 'on-hold' ) ) { 120 | if ( $this->instructions ) { 121 | echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; 122 | } 123 | } 124 | 125 | } 126 | 127 | /** 128 | * Process the gateway integration 129 | * 130 | * @param int $order_id 131 | * 132 | * @return void 133 | */ 134 | public function process_payment( $order_id ) { 135 | 136 | $order = wc_get_order( $order_id ); 137 | 138 | // Mark as on-hold (we're awaiting the payment) 139 | $order->update_status( 'on-hold', __( 'Awaiting bKash payment', 'wc-bkash' ) ); 140 | 141 | // Remove cart 142 | WC()->cart->empty_cart(); 143 | 144 | // Return thankyou redirect 145 | return array( 146 | 'result' => 'success', 147 | 'redirect' => $this->get_return_url( $order ) 148 | ); 149 | } 150 | 151 | /** 152 | * Validate place order submission 153 | * 154 | * @return bool 155 | */ 156 | public function validate_fieldss() { 157 | global $woocommerce; 158 | 159 | if ( empty( $_POST['bkash_trxid'] ) ) { 160 | wc_add_notice( __( 'Please type the transaction ID.', 'wc-bkash' ), 'error' ); 161 | return; 162 | } 163 | 164 | return true; 165 | } 166 | 167 | } -------------------------------------------------------------------------------- /plugin-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # args 4 | MSG=${1-'deploy from git'} 5 | BRANCH=${2-'trunk'} 6 | 7 | # paths 8 | SRC_DIR=$(git rev-parse --show-toplevel) 9 | DIR_NAME=$(basename $SRC_DIR) 10 | DEST_DIR=~/svn/wp-plugins/$DIR_NAME/$BRANCH 11 | 12 | # make sure we're deploying from the right dir 13 | if [ ! -d "$SRC_DIR/.git" ]; then 14 | echo "$SRC_DIR doesn't seem to be a git repository" 15 | exit 16 | fi 17 | 18 | # make sure the destination dir exists 19 | svn mkdir $DEST_DIR 2> /dev/null 20 | svn add $DEST_DIR 2> /dev/null 21 | 22 | # delete everything except .svn dirs 23 | for file in $(find $DEST_DIR/* -not -path "*.svn*") 24 | do 25 | rm $file 2>/dev/null 26 | #echo $file 27 | done 28 | 29 | # copy everything over from git 30 | #rsync -r --exclude='*.git*' $SRC_DIR/* $DEST_DIR 31 | git checkout-index -a -f --prefix=$DEST_DIR/ 32 | 33 | # delete readme.md from git checkout 34 | rm $DEST_DIR/readme.md 35 | 36 | # copy readme.txt to svn folder 37 | cp $SRC_DIR/readme.txt $DEST_DIR/readme.txt 38 | 39 | 40 | cd $DEST_DIR 41 | 42 | # check .svnignore 43 | for file in $(cat "$SRC_DIR/.svnignore" 2>/dev/null) 44 | do 45 | rm $file -rf 46 | done 47 | 48 | # Transform the readme 49 | #README=$(find $DEST_DIR -iname 'README.m*') 50 | #sed -i '' -e 's/^# \(.*\)$/=== \1 ===/' -e 's/ #* ===$/ ===/' -e 's/^## \(.*\)$/== \1 ==/' -e 's/ #* ==$/ ==/' -e 's/^### \(.*\)$/= \1 =/' -e 's/ #* =$/ =/' $README 51 | 52 | #mv $README $DEST_DIR/readme.txt 53 | 54 | # svn addremove 55 | svn stat | grep '^\?' | awk '{print $2}' | xargs svn add > /dev/null 2>&1 56 | svn stat | grep '^\!' | awk '{print $2}' | xargs svn rm > /dev/null 2>&1 57 | 58 | svn stat 59 | svn ci -m "$MSG" 60 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === WooCommerce bKash === 2 | Contributors: tareq1988 3 | Donate link: http://tareq.wedevs.com/donate/ 4 | Tags: bkash, gateway, woocommerce, bdt, bangladesh 5 | Requires at least: 3.6 6 | Tested up to: 4.6.1 7 | Stable tag: trunk 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | bKash Payment gateway for WooCommerce 12 | 13 | == Description == 14 | 15 | This is a very good and excellent plugin to shop online around Bangladesh using bKash payment gateway. If you(Store owner)'re using [WooCommerce](http://www.woothemes.com/woocommerce/) for your store, you should choose bKash for local payment for your shop. 16 | 17 | = Using the Plugin = 18 | 19 | * Download the plugin, Install and active it, as you normally install and active other plugin too, 20 | 21 | * Normally, you would not find any settings or options to use in the Dashboard, rather go to WooCommerce > Settings from your Dashboard, location URL would be exactly like below - 22 | 23 | ` 24 | http://yoursite.ext/wp-admin/admin.php?page=wc-settings 25 | ` 26 | 27 | * Now click on Checkout tab and you'll now see the bKash link, Click and enter the bKash setting page, 28 | 29 | * Now, do Check the checkbox, if the Enable/Disable option is unchecked, This option must be checked to show this payment method in checkout page. 30 | 31 | * Give a custom Title text by yourself or keep it as is in the text field, 32 | 33 | * Give a Description as you did in the title or keep it as is, 34 | 35 | * Write an Instructions on how do your customer pay you using their bKash account. It'll be showing in front of them when they select bKash Payment option and did complete their Checkout process. 36 | 37 | ### Generally the message would be - 38 | 39 | >Send your payment directly to 01*** *** ***(Your merchant number here) via bKash. Please use your Order ID as the payment reference. Your order won't be shipped until the fund have cleared in our account. 40 | > 41 | >#### How to send payment: 42 | 43 | >1. Dial *247# 44 | >2. Select or Press 3 for "Payment" option 45 | >3. Enter our bKash wallet number 01*** *** ***(Your merchant number here) 46 | >4. Enter amount of fee that you ordered already 47 | >5. Enter a reference, use your Order ID as reference 48 | >6. Enter 1 as counter number 49 | >7 Enter your bKash menu PIN to confirm payment 50 | >8. You'll be getting a confirmation message in a while 51 | >9. That's it! :) 52 | 53 | * Write a custom Transaction Help Text or keep it as is. It'll be showing above the transaction confirmation box! 54 | 55 | * Now you are in the main point - 56 | 57 | Its time to take your bKash Merchant API Access Username and Password from your [bKash Account Manager](http://www.bkash.com/support/contact-us). You should now call them and take the info right around. When you're getting the desired access info, now enter the Username into Merchant Username filed and Password into Merchant Password field in the bKash settings page. And don't forget to enter the Merchant mobile number into the last field. Otherwise your this plugin doesn't work! 58 | 59 | * If everything sounds good, you're ready to sale your product using bKash! :) 60 | 61 | = Contribute = 62 | 63 | [Fork in Github](https://github.com/tareq1988/woocommerce-bkash) 64 | 65 | 66 | = Author = 67 | 68 | Brought to you by [Tareq Hasan](https://tareq.co) from [weDevs](http://wedevs.com) 69 | 70 | == Installation == 71 | 72 | 73 | 1. Upload the plugin folder to the `/wp-content/plugins/` directory 74 | 1. Activate the plugin through the 'Plugins' menu in WordPress 75 | 76 | == Frequently Asked Questions == 77 | 78 | Nothing here yet 79 | 80 | == Screenshots == 81 | 82 | 1. Gateway Settings 83 | 2. Checkout page 84 | 3. Order received page 85 | 4. Order details page (pending order) 86 | 87 | == Changelog == 88 | 89 | = 1.1.1 (24 Oct, 2016) = 90 | 91 | * [fix] Fix the order received page form display 92 | 93 | = 1.1.0 (20 July, 2016) = 94 | 95 | * [fix] WooCommerce 3.6 compatibility. Settings screen was broken. 96 | 97 | = 1.0 = 98 | * Moved the transaction ID form to order received page and order details page. 99 | 100 | = 0.1 = 101 | * First release 102 | 103 | == Upgrade Notice == 104 | 105 | Nothing here --------------------------------------------------------------------------------