Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit 609f150

Browse files
committed
Merge branch 'dev-1.1.1' into 'master'
update 1.1.1 See merge request iamapinan/woocommerce-line-notify!15
2 parents 62124ef + e224c2a commit 609f150

17 files changed

+1256
-598
lines changed

CHANGELOG

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
v1.1.0
2+
- Change admin ui
3+
- Change class name duplicate.
4+
- Multi language support.
5+
- API
6+
- Add postcode shortcode.
7+
- Direct method
8+
- Debug option.
9+
- Dynamic fields
10+
- Dashboard widget
11+
- Can use without Woocommerce
12+
113
v1.0.9
214
- Update meta
315
v1.0.8

README.md

Lines changed: 124 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22
Send woocommerce order notification to Line notify API.
33
You can customize message pattern and notify to your chat room or your chat group in your pattern.
44

5-
### [Download here](https://wordpress.org/plugins/woo-line-notify)
5+
---
6+
![Woocommerce Line Notify icon](src/image/download_button.png)
7+
[https://wordpress.org/plugins/woo-line-notify](https://wordpress.org/plugins/woo-line-notify)
68

7-
## Available short code for implement message pattern.
9+
### Features
10+
1. Add line token.
11+
2. Message pattern with order short code supported.
12+
3. Send notify to line group or user.
13+
4. Send notify when have order activity.
14+
5. Multi language support.
15+
6. API to send message with basic authen security for developer.
16+
7. Static method to send message for developer.
17+
8. Debug mode option.
18+
9. Dynamic fields to unlock your need.
19+
10. Dashboard widget.
20+
11. Can use without Woocommerce.
21+
22+
### Short code.
823
```
924
[order_status]
1025
[order_id]
@@ -18,21 +33,102 @@ You can customize message pattern and notify to your chat room or your chat grou
1833
[order_note]
1934
[order_province]
2035
[order_url]
21-
[products] //List of product in order.
36+
[order_postcode]
37+
[products] <-- List of product in order.
38+
```
39+
40+
### Dynamic shortcode
41+
```
42+
[shipping *]
43+
[billing *]
44+
[customer *]
45+
[order *]
46+
[meta *]
47+
```
48+
49+
### Short code
50+
#### Customer Fields
51+
```
52+
first_name [custoemr first_name]
53+
last_name [custoemr last_name]
54+
email [custoemr email]
55+
phone [custoemr phone]
56+
```
57+
58+
#### Shipping fields
59+
```
60+
company [shipping company]
61+
address_1 [shipping address_1]
62+
address_2 [shipping address_2]
63+
city [shipping city]
64+
state [shipping state]
65+
postcode [shipping postcode]
66+
country [shipping country]
67+
address_index [shipping address_index]
2268
```
2369

24-
## Features
25-
- Add line token.
26-
- Message pattern with order short code supported.
27-
- Send notify to line group or user.
28-
- Send notify when have order activity.
29-
- Add logo or image banner to notification.
30-
- Only support Thai language for this version .
70+
#### Billing fields
71+
```
72+
company [billing company]
73+
address_1 [billing address_1]
74+
address_2 [billing address_2]
75+
city [billing city]
76+
state [billing state]
77+
postcode [billing postcode]
78+
country [billing country]
79+
email [billing email]
80+
phone [billing phone]
81+
address_index [billing address_index]
82+
```
83+
#### Order fields
84+
```
85+
order_key [order order_key]
86+
customer_user [order customer_user]
87+
payment_method [order payment_method]
88+
payment_method_title [order payment_method_title]
89+
transaction_id [order transaction_id]
90+
customer_ip_address [order customer_ip_address]
91+
customer_user_agent [order customer_user_agent]
92+
created_via [order created_via]
93+
date_completed [order date_completed]
94+
completed_date [order completed_date]
95+
date_paid [order date_paid]
96+
paid_date [order paid_date]
97+
cart_hash [order cart_hash]
98+
order_currency [order order_currency]
99+
cart_discount [order cart_discount]
100+
cart_discount_tax [order cart_discount_tax]
101+
order_shipping [order order_shipping]
102+
ordertax [order ordertax]
103+
order_tax [order order_tax]
104+
order_total [order order_total]
105+
order_version [order order_version]
106+
prices_include_tax [order prices_include_tax]
107+
download_permissions_granted [order download_permissions_granted]
108+
recorded_sales [order recorded_sales]
109+
recorded_coupon_usage_counts [order recorded_coupon_usage_counts]
110+
order_stock_reduced [order order_stock_reduced]
111+
edit_lock [order edit_lock]
112+
edit_last [order edit_last]
113+
```
114+
#### Meta
115+
Just use `[meta your_meta_name]` to take custom order meta by `get_post_meta()` function.
31116

32-
## Benefits.
33-
1. Send a notification to your self.
34-
2. Send a notifycation to your group.
35-
3. Can send text, image and line sticker to the notification message.
117+
### API for Developer
118+
To send message via static method just put your message to the method like below.
119+
```
120+
WooLineNotify::Send_Line_Notify( 'Some message to send' );
121+
```
122+
123+
### REST API
124+
- URL: `domain/wp-json/woo-line-notify/v1/notify`
125+
- METHOD: `POST`
126+
- PARAMETERS: `message <Your message to send> `
127+
- Authentication: `Basic Authen`
128+
- USERNAME/PASSWORD: `<API Key>:<API_Key>`
129+
130+
#### For example.
131+
Send post request to `http://localhost/wp-json/woo-line-notify/v1/notify` you must be send parameter `message` by form/data and add Authenticate to header with value `Basic base64_encode( some_api_key_from_api_option:some_api_key_from_api_option )`
36132

37133
## How to install
38134
1. Upload the entire wc_linenotify folder to the /wp-content/plugins/ directory.
@@ -53,9 +149,6 @@ Privacy Policy rules of Line Messaging [https://terms.line.me/line_rules?lang=en
53149
## Roadmap
54150
- Message pattern for selected status.
55151
- Multiple token id support for message broadcast.
56-
- Message broadcast to line group.
57-
- Add line sticker.
58-
- Attach event url.
59152

60153
## Contibute guidelines
61154
Thank you for your suggestion and support to the project. I very happy to help and give the thing I can do to the world. If you can help me to develop this plugin or join as a team members please follow below. I'll add your name to contributor members if you've joined.
@@ -66,6 +159,20 @@ Thank you for your suggestion and support to the project. I very happy to help a
66159
5. Create pull request with update details to developer.
67160
6. Waiting for approved.
68161

162+
### Changelog
163+
#### version 1.1.0
164+
- Change admin ui
165+
- Change class name duplicate.
166+
- Multi language support.
167+
- API
168+
- Add postcode shortcode.
169+
- Direct method
170+
- Debug option.
171+
- Dynamic fields
172+
- Dashboard widget
173+
- Can use without Woocommerce
174+
---
175+
69176
### Welcome to the opensource world.
70177

71178
### [Wiki](https://git.iotech.co.th/iamapinan/woocommerce-line-notify/wikis), [Issue](https://git.iotech.co.th/iamapinan/woocommerce-line-notify/issues)

inc/Extras.php renamed to inc/Actions.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Package: woo-line-notify
44
* (c) Apinan Woratrakun (iOTech Enterprise Co.,Ltd.) <apinan@iotech.co.th>
55
*/
6+
// namespace WooLineNotify\Extras;
67
if ( ! defined( 'ABSPATH' ) ) exit;
7-
class Extras {
8+
class Actions {
89
/**
910
* Change woocommerce state name to Thailand state.
1011
*/
11-
public static function thai_states( $states ) {
12+
public function thai_states( $states ) {
1213
$states_set = array(
1314
'TH-81' => 'กระบี่',
1415
'TH-10' => 'กรุงเทพมหานคร',
@@ -90,4 +91,50 @@ public static function thai_states( $states ) {
9091
);
9192
return $states_set[$states];
9293
}
94+
95+
/**
96+
* Send notify action.
97+
*/
98+
public function send_notify($msg, $source = 'local') {
99+
// Get plugin options
100+
$get_option = get_option( '_option_notify' );
101+
$get_debug = get_option( '_option_debug' );
102+
$counter = get_option('wln_source_' . $source);
103+
$endpoint = get_option('wln-api-endpoint');
104+
// Header setup
105+
$headers = array(
106+
'Authorization' => 'Bearer '. $get_option['token'],
107+
);
108+
// Request prepare
109+
$args = array(
110+
'method' => 'POST',
111+
'timeout' => 45,
112+
'httpversion' => '1.0',
113+
'headers' => $headers,
114+
'body' => array(
115+
'message' => $msg
116+
),
117+
);
118+
119+
// Post to line notify server.
120+
$response = wp_remote_post( $endpoint, $args );
121+
$status = wp_remote_retrieve_response_code($response);
122+
123+
update_option('wln_source_' . $source, $counter+1);
124+
125+
if( isset( $get_debug['debug'] ) ) {
126+
// Loging output
127+
$log = "Status: ". wp_remote_retrieve_response_code($response) ."\nMessage: " . $msg . "\n" . "Response: " . str_replace('\\', '', json_encode($response));
128+
$this->wln_debug_log( $log );
129+
}
130+
131+
return $response;
132+
}
133+
134+
public function wln_debug_log( $logs ) {
135+
if( is_writable( WOO_LINE_NOTIFY_PATH .'logs/debug.log' ) ) {
136+
file_put_contents( WOO_LINE_NOTIFY_PATH .'logs/debug.log', $logs . "\n\nDatetime: " . date('d/m/Y H:i') );
137+
}
138+
}
139+
93140
}

0 commit comments

Comments
 (0)