Token Expiry Notifier — Developer Reference

This page covers the action hooks, filter hooks, and REST API endpoints available to developers who want to extend or integrate with Token Expiry Notifier.


Action hooks

↑ Back to top

saai_ten4wc_token_expiry_check_completed

↑ Back to top

Fires after the daily token expiry check finishes processing. Use this to add custom logging, trigger integrations, or send alerts.

add_action( 'saai_ten4wc_token_expiry_check_completed', function( int $count ): void {
    // $count = number of expiring tokens found this run
    if ( $count > 0 ) {
        // Example: log to a custom monitoring service
        error_log( sprintf( 'Token expiry check completed: %d tokens queued for notification.', $count ) );
    }
} );

Filter hooks

↑ Back to top

saai_ten4wc_history_customer_url

↑ Back to top

Filters the URL used for the customer link in the Notification History table. By default, links to the WooCommerce customer profile. Override this to point to your CRM, helpdesk, or custom customer management page.

Parameters:

ParameterTypeDescription
$urlstringThe default customer profile URL
$user_idintWordPress user ID
add_filter( 'saai_ten4wc_history_customer_url', function( string $url, int $user_id ): string {
    // Example: link to WooCommerce Analytics customer profile
    return admin_url( 'admin.php?page=wc-admin&path=/customers/' . $user_id );
}, 10, 2 );

REST API

↑ Back to top

All endpoints require the manage_woocommerce capability. Requests must include a valid WordPress nonce in the X-WP-Nonce header (provided automatically by wp.apiFetch).

Base URL: /wp-json/saai-ten4wc/v1/


GET /settings

↑ Back to top

Retrieve the current plugin settings.

Response:

{
  "enabled": true,
  "notification_timing": "before_month",
  "notification_day_of_month": 10,
  "notification_time": "03:00",
  "reminder_days_after": 3,
  "email_subject": "Your payment method is expiring soon : {site_name}",
  "email_template": "...",
  "history_retention_enabled": false,
  "history_retention_months": 3,
  "show_order_postbox": false,
  "show_subscription_postbox": false
}

POST /settings

↑ Back to top

Update plugin settings. Send only the fields you want to change.

Request body:

{
  "enabled": true,
  "notification_timing": "both",
  "notification_day_of_month": 5,
  "reminder_days_after": 5
}

Response: The full updated settings object (same schema as GET).


GET /history

↑ Back to top

Retrieve the notification history log.

Query parameters:

ParameterTypeDefaultDescription
pageint1Page number
per_pageint20Records per page
user_idintFilter by WordPress user ID

Response:

{
  "items": [
    {
      "id": 42,
      "user_id": 7,
      "token_id": 3,
      "card_last4": "4242",
      "expiry_month": "06",
      "expiry_year": "2026",
      "sent_at": "2026-05-10 03:14:22",
      "email_sent_to": "jane@example.com",
      "reminder_sent_at": null
    }
  ],
  "total": 142,
  "pages": 8
}

POST /test-email

↑ Back to top

Send a test notification email to the WordPress admin email address using sample card data.

Request body: (none required)

Response:

{ "success": true, "message": "Test email sent to admin@example.com" }

POST /manual-check

↑ Back to top

Trigger an immediate token expiry check, bypassing the configured notification day restriction.

Request body: (none required)

Response:

{ "success": true, "queued": 12 }

queued is the number of individual notification emails added to the Action Scheduler queue.


GET /template-tags

↑ Back to top

Returns the list of available email template tags.

Response:

[
  { "tag": "{customer_name}", "description": "Customer display name" },
  { "tag": "{card_type}", "description": "Card brand (Visa, Mastercard, etc.)" },
  ...
]

GET /statistics

↑ Back to top

Returns aggregate notification statistics.

Response:

{
  "total_sent": 842,
  "total_reminders_sent": 134,
  "oldest_record": "2025-11-01 03:10:00"
}

GET /expiry-summary

↑ Back to top

Returns the count of tokens expiring in the current and next calendar month.

Response:

{
  "current_month": {
    "year_month": "2026-06",
    "count": 18
  },
  "next_month": {
    "year_month": "2026-07",
    "count": 7
  }
}

Action Scheduler actions

↑ Back to top

The plugin registers two custom actions with Action Scheduler (bundled with WooCommerce):

Action hookGroupDescription
saai_ten4wc_token_expiry_checksaai-ten4wcDaily check — finds expiring tokens and queues notifications
saai_ten4wc_send_notificationsaai-ten4wcPer-token — sends one notification email and records the result

You can monitor these under WooCommerce → Status → Scheduled Actions. Filter by group saai-ten4wc to see only this plugin’s actions.


Database tables

↑ Back to top

The plugin creates two tables on activation using dbDelta.

{prefix}saai_ten4wc_notifications

↑ Back to top

Stores the history of sent notifications. Used for duplicate prevention and reminder tracking.

ColumnTypeDescription
idbigint unsignedAuto-increment primary key
user_idbigint unsignedWordPress user ID
token_idbigint unsignedWooCommerce payment token ID
card_last4varchar(4)Last 4 digits (snapshot at send time)
expiry_monthvarchar(2)Card expiry month (MM)
expiry_yearvarchar(4)Card expiry year (YYYY)
sent_atdatetimeWhen the notification was sent
email_sent_tovarchar(100)Recipient email address
reminder_sent_atdatetimeWhen the reminder was sent (NULL if not sent)

{prefix}saai_ten4wc_queue

↑ Back to top

Internal processing queue used during batch notification dispatch.

ColumnTypeDescription
idbigint unsignedAuto-increment primary key
user_idbigint unsignedWordPress user ID
token_idbigint unsignedWooCommerce payment token ID
statusvarchar(20)pending, processing, completed, failed
created_atdatetimeRecord creation time
processed_atdatetimeProcessing completion time
attemptsintNumber of processing attempts
error_messagetextError details (if failed)

Both tables are removed on plugin uninstall via uninstall.php.


Plugin constants

↑ Back to top
ConstantValueDescription
SAAI_TEN4WC_VERSION0.9.14Plugin version
SAAI_TEN4WC_OPTION_KEYsaai_ten4wc_settingsWordPress option key for settings
SAAI_TEN4WC_AS_CHECK_ACTIONsaai_ten4wc_token_expiry_checkDaily check AS action name
SAAI_TEN4WC_AS_SEND_ACTIONsaai_ten4wc_send_notificationPer-notification AS action name
SAAI_TEN4WC_AS_GROUPsaai-ten4wcAction Scheduler group name
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.