Platform adapters
The PlatformAdapter class and its request objects.
Namespace PayLexer\Integration. Each method calls the function in the last column and throws Exception where the function would return a WP_Error.
For a complete working adapter, with registration, a checkout and on_event(), see the Platform adapters guide.
PlatformAdapter
PlatformAdapter (abstract). Set the properties $id, $name (both required), $by, $icon, $plugin, $plugin_url, $addon_icon, $description and $supports.
Set the logo URLs in a constructor, since plugins_url() can't appear in a property default.
Methods
| Method | Returns | Same as |
|---|---|---|
id() | string | |
is_enabled() | bool | paylexer_is_platform_enabled() |
gateways( array $filters = [] ) | array | paylexer_get_gateways() |
currencies() | array | paylexer_get_currencies() |
create_checkout( CheckoutRequest $request ) | array | paylexer_create_checkout() |
create_subscription( SubscriptionRequest $request ) | array | paylexer_create_subscription() |
update_subscription( string $subscription_id, string $action ) | array | paylexer_cancel_subscription(), _pause_, _resume_ ($action: cancel, pause, resume) |
refund( string $order_reference, ?float $amount = null, string $reason = '' ) | array | paylexer_refund() |
get_payment_status( string $order_reference ) | array | paylexer_get_payment_status() |
get_subscription_status( string $subscription_id ) | array | paylexer_get_subscription_status() |
get_orders( array $args = [] ) | array | paylexer_get_orders() |
render_order_details( string $order_reference, bool $with_heading = true, array $known = [] ) | prints HTML | paylexer_render_order_details() |
on_event( WebhookEvent $event ) | void | Override it. paylexer_platform_{id}_webhook |
Request objects
Build them with named arguments. Their fields are the keys the matching function takes, and empty strings fall back to the same defaults.
| Class | Required | Optional |
|---|---|---|
Customer | email | first_name, last_name, phone, address |
LineItem | name, unit_amount | quantity (1), id |
CheckoutRequest | gateway, amount, currency, customer, return_url | cancel_url, reference, description, items, metadata, test_mode, merchant_name, theme_color, order_url |
SubscriptionRequest | gateway, amount, currency, interval, customer, return_url | interval_count, cancel_url, reference, product_name, plan_name, trial_days, billing_cycles, sign_up_fee, items, metadata, test_mode, order_url, product_id (shown as the SKU) |
Webhooks and errors
Webhook objects: see WebhookEvent.
Exception: get_error_code() returns one of the error codes; getMessage() the message.