-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# IDE | ||
.idea | ||
.vscode | ||
|
||
# dependency | ||
bower_components | ||
node_modules | ||
|
||
# dist | ||
*.min.js | ||
|
||
# log | ||
*.log | ||
|
||
# lock | ||
yarn.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.ppy-input-desc { | ||
padding-top: 4px; | ||
padding-left: 4px; | ||
color: #afafaf; | ||
} | ||
|
||
.ppy-qrcode { | ||
max-width: 340px; | ||
max-height: 340px; | ||
} | ||
|
||
.ppy-qrcode svg { | ||
width: 100%; | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const qrcode = require('qrcode'); | ||
const generatePayload = require('promptpay-qr'); | ||
|
||
const opt = { | ||
type: 'svg' | ||
}; | ||
|
||
jQuery(document).ready(function () { | ||
const $body = jQuery('body'); | ||
const isAdmin = $body.hasClass('wp-admin'); | ||
|
||
if (isAdmin) { | ||
// do live edit | ||
} else { | ||
const $qrcodes = jQuery('.ppy-qrcode'); | ||
jQuery.each($qrcodes, function () { | ||
const $ele = jQuery(this); | ||
/** @type string */ | ||
const id = jQuery(this).data('promptpay-id').toString(); | ||
/** @type number */ | ||
const amount = parseFloat(jQuery(this).data('amount')); | ||
|
||
if (id) { | ||
const payload = generatePayload(id, { | ||
amount: 0 | ||
}); | ||
|
||
qrcode.toString(payload, opt, function (err, svg) { | ||
if (err) { | ||
console.log('err', err); | ||
} else { | ||
$ele.html(svg); | ||
} | ||
}) | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"scripts": { | ||
"build.watch": "webpack js/main.js js/main.min.js -d --watch", | ||
"build.prod": "webpack js/main.js js/main.min.js -p" | ||
}, | ||
"dependencies": { | ||
"promptpay-qr": "^0.4.3", | ||
"qrcode": "^0.9.0", | ||
"webpack": "^3.5.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
<?php | ||
/* | ||
Plugin Name: PromptPay | ||
Plugin URI: https://wordpress.org/plugins/promptpay/ | ||
Description: PromptPay integration for WordPress | ||
Version: 1.0.0 | ||
Author: Nathachai Thongniran | ||
Author URI: http://jojoee.com/ | ||
Text Domain: ppy | ||
License: GPL2+ | ||
License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
*/ | ||
|
||
define( 'PPY_BASE_FILE', plugin_basename( __FILE__ ) ); | ||
define( 'PPY_PLUGIN_NAME', 'PromptPay' ); | ||
|
||
class PromptPay { | ||
|
||
public function __construct() { | ||
$this->is_debug = false; | ||
$this->menu_page = 'promptpay'; | ||
$this->option_group_name = 'ppy_option_group'; | ||
$this->option_field_name = 'ppy_option_field'; | ||
$this->setting_section_id = 'ppy_setting_section_id'; | ||
|
||
$this->options = get_option( $this->option_field_name ); | ||
|
||
// set default prop | ||
// for only | ||
// - first time | ||
// - no submitting form | ||
$this->set_default_prop(); | ||
|
||
// backend: menu | ||
add_action( 'admin_menu', array( $this, 'admin_menu' ) ); | ||
add_action( 'admin_init', array( $this, 'admin_init' ) ); | ||
|
||
// backend: plugin | ||
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 4 ); | ||
|
||
// script | ||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | ||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | ||
|
||
// shortcode | ||
add_shortcode( 'promptpayqr', array( $this, 'shortcode_qrcode' ) ); | ||
} | ||
|
||
/** ================================================================ shortcode | ||
*/ | ||
|
||
public function shortcode_qrcode() { | ||
$options = $this->options; | ||
$promptpay_id = $options['field_promptpay_id']; | ||
$amount = 0; | ||
$html = sprintf( '<div class="ppy-qrcode" data-promptpay-id="%s" data-amount="%f"></div>', | ||
$promptpay_id, | ||
$amount | ||
); | ||
|
||
return $html; | ||
} | ||
|
||
/** ================================================================ backend: menu | ||
*/ | ||
|
||
public function admin_menu() { | ||
add_options_page( | ||
PPY_PLUGIN_NAME, | ||
PPY_PLUGIN_NAME, | ||
'manage_options', | ||
$this->menu_page, | ||
array( $this, 'admin_page' ) | ||
); | ||
} | ||
|
||
public function admin_page() { | ||
$this->dump(); ?> | ||
<div class="wrap"> | ||
<h1><?= PPY_PLUGIN_NAME; ?></h1> | ||
<form method="post" action="options.php"> | ||
<?php | ||
settings_fields( $this->option_group_name ); | ||
do_settings_sections( $this->menu_page ); | ||
submit_button(); | ||
?> | ||
</form> | ||
</div> | ||
<style> | ||
<?php | ||
} | ||
|
||
public function admin_init() { | ||
register_setting( | ||
$this->option_group_name, | ||
$this->option_field_name, | ||
array( $this, 'sanitize' ) | ||
); | ||
|
||
// section | ||
add_settings_section( | ||
$this->setting_section_id, | ||
'Settings', | ||
array( $this, 'print_section_info' ), | ||
$this->menu_page | ||
); | ||
|
||
// option field(s) | ||
// - field_promptpay_id | ||
add_settings_field( | ||
'field_promptpay_id', | ||
'PromptPay ID', | ||
array( $this, 'field_promptpay_id_callback' ), | ||
$this->menu_page, | ||
$this->setting_section_id | ||
); | ||
} | ||
|
||
/** ================================================================ backend: page | ||
*/ | ||
|
||
/** ================================================================ backend: field | ||
*/ | ||
|
||
public function set_default_prop() { | ||
// default | ||
// [ | ||
// 'field_promptpay_id' => '' | ||
// ] | ||
|
||
$options = $this->options; | ||
|
||
if ( ! isset( $options['field_promptpay_id'] ) ) { | ||
$options['field_promptpay_id'] = ''; | ||
} | ||
|
||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* Sanitize each setting field as needed | ||
* | ||
* @param array $input Contains all settings fields as array keys | ||
* | ||
* @return array[] | ||
*/ | ||
public function sanitize( $input ) { | ||
$result = array(); | ||
|
||
// text | ||
$text_input_ids = array( | ||
'field_promptpay_id', | ||
); | ||
foreach ( $text_input_ids as $text_input_id ) { | ||
$result[ $text_input_id ] = isset( $input[ $text_input_id ] ) | ||
? sanitize_text_field( $input[ $text_input_id ] ) | ||
: ''; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function print_section_info() { | ||
print 'Enter your settings below:'; | ||
} | ||
|
||
/** ================================================================ backend: field | ||
*/ | ||
|
||
public function field_promptpay_id_callback() { | ||
$field_id = 'field_promptpay_id'; | ||
$field_name = $this->option_field_name . "[$field_id]"; | ||
$field_value = $this->options[ $field_id ]; | ||
|
||
printf( '<input type="text" id="%s" placeholder="PromptPay ID" name="%s" value="%s" />', | ||
$field_id, | ||
$field_name, | ||
$field_value | ||
); | ||
printf( '<br><span class="ppy-input-desc">e.g. 1234567891234, 0841234567</span>' ); | ||
} | ||
|
||
/** ================================================================ backend: plugin | ||
*/ | ||
|
||
/** | ||
* @param string[] $links | ||
* @param string $plugin_file | ||
* | ||
* @return array | ||
*/ | ||
public function plugin_action_links( $links = [], $plugin_file = '' ) { | ||
$plugin_link = array(); | ||
if ( $plugin_file === PPY_BASE_FILE ) { | ||
$plugin_link[] = sprintf( '<a href="%s">%s</a>', | ||
admin_url( 'options-general.php?page=' . $this->menu_page ), | ||
'Settings' | ||
); | ||
} | ||
|
||
return array_merge( $links, $plugin_link ); | ||
} | ||
|
||
/** ================================================================ debug | ||
*/ | ||
|
||
/** | ||
* @param null $var | ||
* @param bool $is_die | ||
* | ||
* @return bool | ||
*/ | ||
private function dd( $var = null, $is_die = true ) { | ||
if ( ! $this->is_debug ) { | ||
return false; | ||
} else { | ||
echo '<pre>'; | ||
print_r( $var ); | ||
echo '</pre>'; | ||
|
||
if ( $is_die ) { | ||
die(); | ||
} | ||
} | ||
} | ||
|
||
private function da( $var = null, $is_die = false ) { | ||
$this->dd( $var, $is_die ); | ||
} | ||
|
||
private function dump( $is_die = false ) { | ||
$this->da( $this->options, $is_die ); | ||
} | ||
|
||
private function reset() { | ||
update_option( $this->option_field_name, array() ); | ||
} | ||
|
||
/** ================================================================ frontend | ||
*/ | ||
|
||
public function enqueue_scripts() { | ||
wp_enqueue_style( 'ppy-main-style', plugins_url( 'css/main.css', __FILE__ ) ); | ||
wp_enqueue_script( 'ppy-main-script', plugins_url( 'js/main.min.js', __FILE__ ), array( 'jquery' ) ); | ||
} | ||
} | ||
|
||
$prompt_pay = new PromptPay(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
=== PromptPay === | ||
|
||
Contributors: jojoee | ||
Donate link: | ||
Tags: payment, PromptPay, qrcode | ||
Requires at least: 3.0.1 | ||
Tested up to: 4.8.1 | ||
Stable tag: 4.3 | ||
License: GPLv2 or later | ||
License URI: http://www.gnu.org/licenses/gpl-2.0.html | ||
|
||
== Description == | ||
|
||
PromptPay integration for WordPress | ||
|
||
Features: | ||
|
||
* Shortcode | ||
|
||
Compatible with all browsers: | ||
|
||
* [Google Chrome](https://www.google.com/chrome/) 19+ | ||
* [Mozilla Firefox](https://www.mozilla.org/firefox/) 3.6+ | ||
* [Safari](http://www.apple.com/safari/) 3+ | ||
* [Internet Explorer](https://www.microsoft.com/en-us/download/internet-explorer.aspx) 9+ | ||
* [Opera](http://www.opera.com/) 10+ | ||
|
||
== Installation == | ||
|
||
1. Install the plugin via admin plguins screen or download and upload this plugin into `wp-content/plugins` directory | ||
2. Activate the plugin through the **Plugins** menu in WordPress | ||
3. Setup plugin via `Settings > PromptPay` | ||
|
||
== Frequently Asked Questions == | ||
|
||
= How to use it = | ||
activate the plugin on your plugin dashboard (`/wp-admin/plugins.php`) | ||
|
||
== Screenshots == | ||
|
||
1. Shortcode (screenshot-1.jpg) | ||
|
||
== Upgrade Notice == | ||
|
||
Not available | ||
|
||
== Changelog == | ||
|
||
= 1.0.0 (07 Sep 2016) = | ||
* First release | ||
|
||
== Notes == | ||
|
||
* [WordPress Coding Standards](https://codex.wordpress.org/WordPress_Coding_Standards) | ||
* 2 spaces for indent | ||
* [Repository on Github](https://github.com/woodpeckerr/promptpay) | ||
|
||
= Thank you = | ||
* [WordPress Plugin readme.txt Validator](https://wordpress.org/plugins/about/validator/) | ||
* [Autoprefixer CSS online](https://autoprefixer.github.io/) | ||
* [PHP code syntax check](https://www.piliapp.com/php-syntax-check/) | ||
* [dtinth/promptpay-qr](https://github.com/dtinth/promptpay-qr) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.