Skip to content

Instantly share code, notes, and snippets.

@vulieumang
Created October 17, 2024 15:05
Show Gist options
  • Save vulieumang/ae5c705329a33c964f96f74262fc4746 to your computer and use it in GitHub Desktop.
Save vulieumang/ae5c705329a33c964f96f74262fc4746 to your computer and use it in GitHub Desktop.
ff_custom_payment
<?php
use FluentFormPro\Payments\PaymentMethods\BasePaymentMethod;
class MyCustomPaymentMethod extends BasePaymentMethod
{
public function __construct()
{
parent::__construct('myCustomPaymentKey');
}
public function init()
{
add_filter('fluentform/payment_method_settings_validation_' . $this->key, array($this, 'validateSettings'), 10, 2);
add_filter('fluentform/transaction_data_' . $this->key, array($this, 'modifyTransaction'), 10, 1);
add_filter(
'fluentform/available_payment_methods',
[$this, 'pushPaymentMethodToForm']
);
}
public function pushPaymentMethodToForm($methods)
{
$methods[$this->key] = [
'title' => __('CustomPayment Method', 'fluentformpro'),
'enabled' => 'yes',
'method_value' => $this->key,
'settings' => [
'option_label' => [
'type' => 'text',
'template' => 'inputText',
'value' => 'Pay with MyCustomPaymentMethod ',
'label' => 'Method Label'
]
]
];
return $methods;
}
public function validateSettings($errors, $settings)
{
if(!($settings['test_api_key']) && !($settings['live_api_key'])) {
$errors['test_api_key'] = __('API Key is required', 'fluentformpro');
}
return $errors;
}
public function modifyTransaction($transaction)
{
return $transaction;
}
public function getGlobalFields()
{
return [
'label' => 'MyCustom Payment Settings',
'fields' => [
[
'settings_key' => 'is_active',
'type' => 'yes-no-checkbox',
'label' => 'Status',
'checkbox_label' => 'Enable MyCustom Payment Payment Method'
],
[
'settings_key' => 'payment_mode',
'type' => 'input-radio',
'label' => 'Payment Mode',
'options' => [
'test' => 'Test Mode',
'live' => 'Live Mode'
],
'info_help' => 'Select the payment mode. for testing purposes you should select Test Mode otherwise select Live mode.',
'check_status' => 'yes'
],
[
'settings_key' => 'test_api_key',
'type' => 'input-text',
'data_type' => 'password',
'placeholder' => 'Test API Key',
'label' => 'Test API Key',
'inline_help' => 'Provide your test api key for your test payments',
'check_status' => 'yes'
],
[
'settings_key' => 'live_api_key',
'type' => 'input-text',
'data_type' => 'password',
'label' => 'Live API Key',
'placeholder' => 'Live API Key',
'inline_help' => 'Provide your live api key for your live payments',
'check_status' => 'yes'
]
]
];
}
public function getGlobalSettings()
{
return get_option('fluentform_payment_settings_'.$this->key, []);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment