A plugin adds the setting fields of its payment method with the app_filter_payment_method_settings filter. Each field is an array with a name, a text (label) and a type. These fields show in Settings > Payment methods when the admin edits the payment method.
Field types
| Type | What it does |
| text | A normal text box. It is required. Add "required" => false to make it optional. |
| secret | For API keys, access tokens and other secrets. It is a password box, and the saved value is never shown in the form. It is optional. If the admin leaves it blank, the saved value is kept. Add "required" => true to make it required while nothing is saved yet. |
| boolean | A checkbox. The saved value is 1 or 0. |
| readonly | Shows the value only. It can't be changed. |
| regenerative_key_url | A webhook link with a random key. Set initial_url too. The admin can make a new key. |
Example
app_hooks()->add_filter('app_filter_payment_method_settings', function ($settings) {
$settings["my_gateway"] = array(
array("name" => "pay_button_text", "text" => app_lang("pay_button_text"), "type" => "text", "default" => "My Gateway"),
array("name" => "api_key", "text" => "API key", "type" => "secret", "required" => true, "help_text" => "Find it in your account settings."),
array("name" => "sandbox", "text" => "Sandbox", "type" => "boolean", "default" => "0"),
);
return $settings;
});
Notes
- help_text is shown as plain text in a tooltip. HTML tags in it are not rendered.
- Read the saved values the same way as before, for example with get_oneline_payment_method("my_gateway"), get_one_with_settings($id) or $this->payment_method in a gateway. Secret values come back as plain text, ready to use.
- Secret values are saved encrypted with the app encryption key. A value saved before this change is plain text in the database. It still works, and it is encrypted the next time the admin saves the payment method.
- Don't read the settings column of the payment_methods table yourself, because secret values in it are encrypted. Use the functions above.
- If the app encryption key is changed, the saved secrets can't be read any more. They come back empty, and the admin needs to enter them again.
- Special characters in keys are kept. Spaces at the start and end are removed.
- For your own plugin settings, you can use encrypt_secret_value($value) before you save a secret and decrypt_secret_value($saved_value) when you read it. decrypt_secret_value() returns a value that isn't encrypted as it is.
- The Stripe secret key, PayPal client secret and Paytm secret key now use the secret type.