From 011ac5b8916991a88a454ad174f41488867e3195 Mon Sep 17 00:00:00 2001 From: Wan Zulkarnain Date: Mon, 15 May 2023 11:04:57 +0800 Subject: [PATCH] Option to whitelist specific payment method --- changelog.txt | 17 ++++++++++++++++ chip-for-fluent-forms.php | 4 ++-- includes/admin/form-settings.php | 32 ++++++++++++++++++++++++++++++ includes/admin/global-settings.php | 31 +++++++++++++++++++++++++++++ includes/class-purchase.php | 32 ++++++++++++++++++++++++++++-- readme.txt | 21 ++++---------------- 6 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 changelog.txt diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..b0b5612 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,17 @@ +*** Changelog *** + += 1.0.4 - 2023-02-24 = +* Fixed - Issue with payment when using with coupon code. + += 1.0.3 - 2023-02-17 = +* Changed - Reference will be autogenerated. + += 1.0.2 - 2023-02-14 = +* Changed - Reference value now using form title instead of transaction id. +* Changed - Platform value now set to fluentforms instead of API. + += 1.0.1 - 2023-01-10 = +* Fixed - Error when new forms created using global configuration. + += 1.0.0 - 2022-12-02 = +* New - Intial Release \ No newline at end of file diff --git a/chip-for-fluent-forms.php b/chip-for-fluent-forms.php index 93ff3cd..52a4ee9 100644 --- a/chip-for-fluent-forms.php +++ b/chip-for-fluent-forms.php @@ -4,7 +4,7 @@ * Plugin Name: CHIP for Fluent Forms * Plugin URI: https://wordpress.org/plugins/chip-for-fluent-forms/ * Description: CHIP - Better Payment & Business Solutions - * Version: 1.0.6 + * Version: 1.0.7 * Author: Chip In Sdn Bhd * Author URI: http://www.chip-in.asia * @@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. -define('FF_CHIP_MODULE_VERSION', 'v1.0.6'); +define('FF_CHIP_MODULE_VERSION', 'v1.0.7'); class Chip_Fluent_Forms { diff --git a/includes/admin/form-settings.php b/includes/admin/form-settings.php index 5586d26..629d25e 100644 --- a/includes/admin/form-settings.php +++ b/includes/admin/form-settings.php @@ -70,6 +70,38 @@ function ff_chip_form_fields( $form ){ 'dependency' => array( ['due-strict-' . $form->id, '==', 'true'], ['form-customize-' . $form->id, '==', 'true'] ), 'validate' => 'csf_validate_numeric', ), + array( + 'id' => 'payment-method-whitelist-' . $form->id, + 'type' => 'switcher', + 'title' => __( 'Payment Method Whitelist', 'chip-for-fluent-forms' ), + 'desc' => __( 'To allow whitelisting a payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable payment method whitelisting.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['form-customize-' . $form->id, '==', 'true'] ), + ), + array( + 'id' => 'payment-method-fpx-' . $form->id, + 'type' => 'switcher', + 'title' => __( 'Enable FPX', 'chip-for-fluent-forms' ), + 'desc' => __( 'To enable FPX payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable FPX payment method.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['payment-method-whitelist-' . $form->id, '==', 'true'] ), + ), + array( + 'id' => 'payment-method-fpxb2b1-' . $form->id, + 'type' => 'switcher', + 'title' => __( 'Enable FPX B2B1', 'chip-for-fluent-forms' ), + 'desc' => __( 'To enable FPX B2B1 payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable FPX B2B1 payment method.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['payment-method-whitelist-' . $form->id, '==', 'true'] ), + ), + array( + 'id' => 'payment-method-card-' . $form->id, + 'type' => 'switcher', + 'title' => __( 'Enable Card', 'chip-for-fluent-forms' ), + 'desc' => __( 'To enable Card payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable Card payment method.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['payment-method-whitelist-' . $form->id, '==', 'true'] ), + ), array( 'type' => 'subheading', 'content' => __( 'Refund Synchronization', 'chip-for-fluent-forms' ), diff --git a/includes/admin/global-settings.php b/includes/admin/global-settings.php index 1797720..92d3f98 100644 --- a/includes/admin/global-settings.php +++ b/includes/admin/global-settings.php @@ -82,6 +82,37 @@ 'dependency' => array( ['due-strict', '==', 'true'] ), 'validate' => 'csf_validate_numeric', ), + array( + 'id' => 'payment-method-whitelist', + 'type' => 'switcher', + 'title' => __( 'Payment Method Whitelist', 'chip-for-fluent-forms' ), + 'desc' => __( 'To allow whitelisting a payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable payment method whitelisting.', 'chip-for-fluent-forms' ), + ), + array( + 'id' => 'payment-method-fpx', + 'type' => 'switcher', + 'title' => __( 'Enable FPX', 'chip-for-fluent-forms' ), + 'desc' => __( 'To enable FPX payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable FPX payment method.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['payment-method-whitelist', '==', 'true'] ), + ), + array( + 'id' => 'payment-method-fpxb2b1', + 'type' => 'switcher', + 'title' => __( 'Enable FPX B2B1', 'chip-for-fluent-forms' ), + 'desc' => __( 'To enable FPX B2B1 payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable FPX B2B1 payment method.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['payment-method-whitelist', '==', 'true'] ), + ), + array( + 'id' => 'payment-method-card', + 'type' => 'switcher', + 'title' => __( 'Enable Card', 'chip-for-fluent-forms' ), + 'desc' => __( 'To enable Card payment method.', 'chip-for-fluent-forms' ), + 'help' => __( 'Whether to enable Card payment method.', 'chip-for-fluent-forms' ), + 'dependency' => array( ['payment-method-whitelist', '==', 'true'] ), + ), ); $refund_global_fields = array( diff --git a/includes/class-purchase.php b/includes/class-purchase.php index aa2033c..fe8dc3f 100644 --- a/includes/class-purchase.php +++ b/includes/class-purchase.php @@ -81,7 +81,7 @@ private function create_purchase( $transaction, $submission, $form, $methodSetti 'submission_id' => $submission->id ), site_url('index.php')); - $params = apply_filters( 'ff_chip_create_purchase_params', array( + $params = array( 'success_callback' => $success_callback, 'success_redirect' => $success_redirect, 'failure_redirect' => $failure_redirect, @@ -106,7 +106,30 @@ private function create_purchase( $transaction, $submission, $form, $methodSetti 'quantity' => '1', ]), ), - ), $transaction, $submission, $form); + ); + + if ( $option['payment_whitelist'] ) { + $params['payment_method_whitelist'] = array(); + + if ( $option['payment_method_fpx'] ) { + $params['payment_method_whitelist'][] = 'fpx'; + } + + if ( $option['payment_method_fpxb2b1'] ) { + $params['payment_method_whitelist'][] = 'fpx_b2b1'; + } + + if ( $option['payment_method_card'] ) { + $params['payment_method_whitelist'][] = 'visa'; + $params['payment_method_whitelist'][] = 'mastercard'; + } + + if ( empty( $params['payment_method_whitelist']) ) { + unset( $params['payment_method_whitelist'] ); + } + } + + $params = apply_filters( 'ff_chip_create_purchase_params', $params, $transaction, $submission, $form); $chip = Chip_Fluent_Forms_API::get_instance( $option['secret_key'], $option['brand_id'] ); $payment = $chip->create_payment($params); @@ -194,6 +217,11 @@ private function get_settings( $form_id ) { 'due_strict' => empty( $options['due-strict' . $postfix] ) ? false : $options['due-strict' . $postfix], 'due_time' => $options['due-strict-timing' . $postfix], 'refund' => empty( $options['refund' . $postfix] ) ? false : $options['refund' . $postfix], + + 'payment_whitelist' => empty( $options['payment-method-whitelist' . $postfix] ) ? false : $options['payment-method-whitelist' . $postfix], + 'payment_method_fpx' => empty( $options['payment-method-fpx' . $postfix] ) ? false : $options['payment-method-fpx' . $postfix], + 'payment_method_fpxb2b1' => empty( $options['payment-method-fpxb2b1' . $postfix] ) ? false : $options['payment-method-fpxb2b1' . $postfix], + 'payment_method_card' => empty( $options['payment-method-card' . $postfix] ) ? false : $options['payment-method-card' . $postfix], ); } diff --git a/readme.txt b/readme.txt index 93dc004..e92a6dc 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: chipasia, wanzulnet Tags: chip Requires at least: 4.7 Tested up to: 6.2 -Stable tag: 1.0.6 +Stable tag: 1.0.7 Requires PHP: 7.1 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -27,28 +27,15 @@ This plugin will enable your Fluent Forms site to be integrated with CHIP as per == Changelog == += 1.0.7 - 2023-05-15 = +* Added - Option to whitelist specific payment method. + = 1.0.6 - 2023-05-10 = * Added - Add execution for processFormSubmissionData to ensure compatibility with Google Sheet = 1.0.5 - 2023-04-29 = * Added - Add filter "ff_chip_create_purchase_params", "ff_chip_handle_paid_data" and action "ff_chip_after_purchase_create" -= 1.0.4 - 2023-02-24 = -* Fixed - Issue with payment when using with coupon code. - -= 1.0.3 - 2023-02-17 = -* Changed - Reference will be autogenerated. - -= 1.0.2 - 2023-02-14 = -* Changed - Reference value now using form title instead of transaction id. -* Changed - Platform value now set to fluentforms instead of API. - -= 1.0.1 - 2023-01-10 = -* Fixed - Error when new forms created using global configuration. - -= 1.0.0 - 2022-12-02 = -* New - Intial Release - == Installation == = Minimum Requirements =