REST API
The Payment Page plugin employs several classes to manage its REST API functionality. Each class is responsible for specific functionalities related to the plugin's operation.
1. RestAPI\Administration
Purpose: Manages administrative functionalities of the Payment Page plugin, including settings and configurations.
Expected Methods:
register_routes()
:Functionality: Registers API endpoints related to the admin settings.
Example Endpoints:
GET /wp-json/payment-page/v1/settings
Description: Retrieves the current settings of the Payment Page.
Response:
POST /wp-json/payment-page/v1/settings
Description: Updates the plugin settings.
Request Body:
Response:
DELETE /wp-json/payment-page/v1/settings
Description: Resets settings to default.
Response:
2. RestAPI\Payment
Purpose: Handles payment-related functionalities, including processing transactions and managing payment history.
Expected Methods:
register_routes()
:Functionality: Registers endpoints for managing payment processes.
Example Endpoints:
POST /wp-json/payment-page/v1/payment/process
Description: Processes a new payment.
Request Body:
Response:
GET /wp-json/payment-page/v1/payment/status
Description: Retrieves the status of a specific payment using its transaction ID.
Request Query:
?transaction_id=abc123
Response:
GET /wp-json/payment-page/v1/payment/history
Description: Retrieves a list of past payments.
Response:
3. RestAPI\PaymentGateway
Purpose: Interfaces with various payment gateways, allowing users to configure and manage gateway settings.
Expected Methods:
register_routes()
:Functionality: Registers API endpoints for interacting with different payment gateways.
Example Endpoints:
GET /wp-json/payment-page/v1/gateway/list
Description: Lists all available payment gateways.
Response:
POST /wp-json/payment-page/v1/gateway/configure
Description: Configures a selected payment gateway.
Request Body:
Response:
DELETE /wp-json/payment-page/v1/gateway/:gateway
Description: Deletes a configured payment gateway.
Response:
4. RestAPI\Plugin
Purpose: Manages plugin-level functionalities, including activation, deactivation, and updates.
Expected Methods:
register_routes()
:Functionality: Registers endpoints that provide information about the plugin.
Example Endpoints:
GET /wp-json/payment-page/v1/plugin/info
Description: Retrieves information about the plugin.
Response:
POST /wp-json/payment-page/v1/plugin/update
Description: Handles updates for the plugin.
Request Body:
Response:
GET /wp-json/payment-page/v1/plugin/status
Description: Checks the status of the plugin.
Response:
5. RestAPI\Stripe
Purpose: Specifically manages Stripe integration for processing payments.
Expected Methods:
register_routes()
:Functionality: Registers endpoints for handling Stripe payments and configurations.
Example Endpoints:
POST /wp-json/payment-page/v1/stripe/payment
Description: Initiates a payment through Stripe.
Request Body:
Response:
GET /wp-json/payment-page/v1/stripe/webhook
Description: Handles Stripe webhooks for payment confirmations.
Request Body: Automatically handled by Stripe.
Response:
GET /wp-json/payment-page/v1/stripe/config
Description: Retrieves the current Stripe configuration.
Response:
6. RestAPI\Tagging
Purpose: Manages tagging and categorization of payments or payment forms.
Expected Methods:
**`register_routes
()`**: - Functionality: Registers endpoints for managing tags.
7. RestAPI\Webhook
Purpose: Handles incoming webhooks from payment processors to keep track of transaction statuses.
Expected Methods:
register_routes()
:Functionality: Registers webhook endpoints for processing notifications from payment gateways.
Example Endpoints:
POST /wp-json/payment-page/v1/webhook/receive
Description: Receives and processes webhook notifications.
Request Body:
Response:
GET /wp-json/payment-page/v1/webhook/status
Description: Checks the current webhook status configuration.
Response:
How to Utilize register_rest_route()
register_rest_route()
Each of the register_routes()
methods in the classes above typically employs the register_rest_route()
function to define the endpoints. This function is vital for creating a custom REST API in WordPress.
Basic Syntax:
Parameters:
Namespace: The first parameter (e.g.,
'payment-page/v1'
) specifies the namespace for the REST API, which helps in organizing routes.Route: The second parameter specifies the endpoint (e.g.,
'/settings'
).Arguments: The third parameter is an associative array that defines:
methods
: Allowed HTTP methods (GET, POST, etc.).callback
: The function that processes the request.permission_callback
: A function to validate whether the user has permission to access the endpoint.
Constants
The plugin defines several constants that are utilized throughout the codebase, allowing developers to reference them easily. These constants are defined in definitions.php
:
PAYMENT_PAGE_NAME
: The name of the payment page plugin.PAYMENT_PAGE_ALIAS
: A short alias for the payment page, used in various settings.PAYMENT_PAGE_PREFIX
: A prefix used in the plugin's identifiers, useful for namespacing custom functionality.PAYMENT_PAGE_REST_API_PREFIX
: The prefix used for REST API routes.PAYMENT_PAGE_ADMIN_CAP
: The capability required for accessing admin settings.PAYMENT_PAGE_VERSION
: The current version of the plugin.PAYMENT_PAGE_TABLE_STRIPE_CUSTOMERS
: The database table name for storing Stripe customer records.
Example Usage of Constants
This detailed documentation provides an extensive overview and actionable examples for developers working with the Payment Page plugin. If you have any additional requests or need further modifications, feel free to contact support.
Last updated