內容簡介
這個外掛可以啟用您的應用程式和 WooCommerce 訂單之間的數位積分使用連接。它可用於檢查一份訂單中剩餘的積分,或是使用積分。
使用方式
在付款的頁面上,重定向至您的應用程式鏈接,攜帶訂單鍵。
假設訂單鍵為wc_order_xQhmRjJ7,您的應用程式 URL 為https://app.EXAMPLE.com/refill,您的 WordPress URL 為https://EXAMPLE.com/
在該訂單的感謝頁面上,顯示一個按鈕<a href="https://app.EXAMPLE.com/refill?order_key=wc_order_xQhmRjJ7">返回app.EXAMPLE</a>。
在 https://app.EXAMPLE.com/refill 中,使用帶有 $_POST[ 'num' ] = 'max' 的 https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7 調用,假設在返回的 JSON 中消費積分為 42 分。
將 42 積分添加到相應用戶帳戶中。
REST APIs
1) 顯示餘額:
方法:GET
URL:https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7
返回:{"_res":"ok", "order_id":45, "status":"completed", "balance":"142"}
// 注意:只有狀態為completed的訂單可以消費積分。
2) 消費 100 積分:
方法: POST
URL:https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7
數據:[ 'num' => 100 ]
返回:{"_res":"ok", "order_id":45, "consumed":"100", "balance":"42"}
3) 消費所有積分:
方法:POST
URL:https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7
數據:[ 'num' => 'max' ]
返回:{"_res":"ok", "order_id":45, "consumed":"42", "balance":"0"}
對於所有錯誤,將返回 {“_res”:”err”,"_msg":"error_msg_tag 或 內容”}
訂單狀態
如果一個訂單僅包含產品詳細信息中具有有效積分的項目,那麼一旦該訂單付款,狀態將自動更改為completed,而不是processing。
之所以這樣做是因為某些未付款網關(銀行電匯,支票,貨到付款)會在下單時狀態為processing,而未付款。因此,我們不能使用processing來檢測訂單是否已付款。
為了使未付款網關的訂單中的積分可用,請更新訂單狀態為completed。
REST API中的錯誤消息標籤
錯誤代碼:wrong_hash
描述:訂單鍵不匹配任何訂單。
錯誤代碼:wrong_status
描述:訂單不是處理中/已完成狀態,可能未付款?
錯誤代碼:lack_of_param
描述:需要指定要消費的金額。可以是數字或固定的字符串max。
錯誤代碼:lack_of_bal
描述:這個訂單中剩餘的積分不足。
外掛標籤
開發者團隊
原文外掛簡介
This plugin will enable the connection between your app and WooCommerce orders for digital credits usage. It can be used to check the remaining credits in one order, or consume them.
Usage
Redirect to your app link on order paid page, carring on the order key.
Let’s assume the order_key=wc_order_xQhmRjJ7, your app URL is https://app.EXAMPLE.com/refill, your WordPress URL is https://EXAMPLE.com/
On the order Thank You page, show a button Go back to app.EXAMPLE.
In https://app.EXAMPLE.com/refill, call https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7 with $_POST[ 'num' ] = 'max', assume the consumed credits is 42 in returned JSON.
Add 42 credits into the corresponding user account.
REST APIs
1) Show balance:
Method: GET
URL: https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7
Return: {"_res":"ok", "order_id":45, "status":"completed", "balance":"142"}
// NOTE: only the order with status=completed can be consumed credits.
2) Consume 100 credits:
Method: POST
URL: https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7
Data: [ 'num' => 100 ]
Return: {"_res":"ok", "order_id":45, "consumed":"100", "balance":"42"}
3) Consume all credits:
Method: POST
URL: https://EXAMPLE.com/wp-json/dotix/v1/order/wc_order_xQhmRjJ7
Data: [ 'num' => 'max' ]
Return: {"_res":"ok", "order_id":45, "consumed":"42", "balance":"0"}
For all errors, will return {“_res”:”err”, “_msg”:”error_msg_tag or content”}
Order Status
If an order contains only items that have valid credit in product detail, once the order is paid, the status will change to completed automatically instead of processing.
The reason to do this is because some unpaid getways (Bank Wire, Cheque, Cash on delivery) will have status processing once the order is placed while not paid. Thus we can’t use processing to detect if the order is paid or not.
To make the credits in the orders with the unpaid gateways available, please update the order status to completed.
Error Message Tag In REST API
Error code: wrong_hash
Description: The order key doesn’t match any order.
Error code: wrong_status
Description: The order isn’t in processing/completed status, maybe not paid yet?
Error code: lack_of_param
Description: Need to specify the ammount to consume. Either numeric or a fixed string max.
Error code: lack_of_bal
Description: Not enough balance left in this order.
