| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\Classes; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Repeater; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Transitional copy for Better Payment Pro <= 1.4.3; delete when ProCompatibility::MIN_PRO_VERSION >= 1.4.4. |
| 14 |
* Pro copy: better-payment-pro/includes/Admin/Elementor/PaymentFormControls.php. Slug: elementor_payment_form_pro_controls. |
| 15 |
* |
| 16 |
* The Payment Form widget controls only Pro layouts 4, 5 and 6 use, layout 6's |
| 17 |
* "WooCommerce / FluentCart is not installed" notices, and the payment-type |
| 18 |
* condition of the widget's PayPal, Paystack and amount-list controls. |
| 19 |
* |
| 20 |
* `Admin\Elementor\Better_Payment_Widget` calls each method only while |
| 21 |
* lite_copy_applies() is true: an active Pro that does not declare the slug. A free |
| 22 |
* install never registers these controls (a Pro layout shows only its upgrade |
| 23 |
* banner there), and a current Pro registers its own copy on the |
| 24 |
* `better_payment/elementor/editor/pro_layout_*` actions fired at the same spots. |
| 25 |
* |
| 26 |
* Control ids must never change: saved Elementor data, PaymentRequestGuard and the |
| 27 |
* payment handlers read them. Elementor keeps a saved value whose control is not |
| 28 |
* registered, so a site that loses Pro keeps its configuration. Pro's |
| 29 |
* PaymentFormControlsParityTest fails when the two copies drift. |
| 30 |
* |
| 31 |
* @since 2.4.0 |
| 32 |
*/ |
| 33 |
final class ProPaymentFormControls { |
| 34 |
|
| 35 |
/** |
| 36 |
* Feature slug Pro declares once it registers these controls itself. |
| 37 |
*/ |
| 38 |
const FEATURE = 'elementor_payment_form_pro_controls'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Whether Lite registers its copy of the controls. |
| 42 |
* |
| 43 |
* @return bool |
| 44 |
*/ |
| 45 |
public static function lite_copy_applies(): bool { |
| 46 |
return ProCompatibility::lite_copy_applies( self::FEATURE ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Payment Settings: payment type, recurring / split / mixed prices and the Stripe webhook (layouts 4 and 5). |
| 51 |
* |
| 52 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 53 |
*/ |
| 54 |
public static function payment_controls( $widget ) { |
| 55 |
$widget->add_control( |
| 56 |
'better_payment_form_payment_type', |
| 57 |
[ |
| 58 |
'label' => esc_html__( 'Payment Type', 'better-payment' ), |
| 59 |
'description' => esc_html__( 'Recurring and Split Payment is available for Stripe only at the moment!', 'better-payment' ), |
| 60 |
'type' => Controls_Manager::SELECT, |
| 61 |
'default' => 'one-time', |
| 62 |
'options' => [ |
| 63 |
'one-time' => 'One Time', |
| 64 |
'recurring' => 'Recurring', |
| 65 |
'mixed' => 'One Time + Recurring (Both)', |
| 66 |
'split-payment' => 'Split Payment', |
| 67 |
], |
| 68 |
'condition' => [ |
| 69 |
'better_payment_form_layout!' => ['layout-1', 'layout-2', 'layout-3', 'layout-6-pro'], |
| 70 |
], |
| 71 |
] |
| 72 |
); |
| 73 |
|
| 74 |
$widget->add_control( |
| 75 |
'better_payment_form_recurring_price_id', |
| 76 |
[ |
| 77 |
'label' => esc_html__( 'Default Price ID', 'better-payment' ), |
| 78 |
'type' => Controls_Manager::TEXT, |
| 79 |
'description' => sprintf( |
| 80 |
__( '<p>Create a product from Stripe dashboard and <a href="%1$s" target="_blank">get the (default) price id.</a></p>', 'better-payment' ), |
| 81 |
esc_url('//betterpayment.co/docs/retrieve-price-id-for-recurring-payments/'), |
| 82 |
), |
| 83 |
'placeholder' => 'price_G0FvDp6vZvdwRZ', |
| 84 |
'label_block' => true, |
| 85 |
'ai' => [ |
| 86 |
'active' => false, |
| 87 |
], |
| 88 |
'condition' => [ |
| 89 |
'better_payment_form_payment_type' => [ 'recurring', 'split-payment' ], |
| 90 |
'better_payment_form_layout!' => ['layout-1', 'layout-2', 'layout-3', 'layout-6-pro'], |
| 91 |
], |
| 92 |
'separator' => 'before', |
| 93 |
] |
| 94 |
); |
| 95 |
|
| 96 |
$repeater_split_payment = new Repeater(); |
| 97 |
|
| 98 |
$repeater_split_payment->add_control( |
| 99 |
'better_payment_split_installment_name', |
| 100 |
[ |
| 101 |
'label' => esc_html__( 'Installment Name', 'better-payment' ), |
| 102 |
'type' => Controls_Manager::TEXT, |
| 103 |
'placeholder' => 'Installment Name', |
| 104 |
'label_block' => true, |
| 105 |
'ai' => [ |
| 106 |
'active' => false, |
| 107 |
], |
| 108 |
] |
| 109 |
); |
| 110 |
|
| 111 |
$repeater_split_payment->add_control( |
| 112 |
'better_payment_split_installment_price_id', |
| 113 |
[ |
| 114 |
'label' => esc_html__( 'Price ID', 'better-payment' ), |
| 115 |
'type' => Controls_Manager::TEXT, |
| 116 |
'placeholder' => 'price_G0FvDp6vZvdwRZ', |
| 117 |
'label_block' => true, |
| 118 |
'ai' => [ |
| 119 |
'active' => false, |
| 120 |
], |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$repeater_split_payment->add_control( |
| 125 |
'better_payment_split_installment_iteration', |
| 126 |
[ |
| 127 |
'label' => esc_html__( 'Iterations', 'better-payment' ), |
| 128 |
'type' => Controls_Manager::NUMBER, |
| 129 |
'min' => 1, |
| 130 |
'max' => 36, |
| 131 |
] |
| 132 |
); |
| 133 |
|
| 134 |
$widget->add_control( |
| 135 |
'better_payment_split_installment_price_ids_note', |
| 136 |
[ |
| 137 |
'type' => Controls_Manager::RAW_HTML, |
| 138 |
'raw' => sprintf( |
| 139 |
__( '<p>Now add more prices to the product from Stripe dashboard and <a href="%1$s" target="_blank">get the price id for each installment.</a></p>', 'better-payment' ), |
| 140 |
esc_url('//betterpayment.co/docs/configure-split-payment-into-subscriptions/'), |
| 141 |
), |
| 142 |
'content_classes' => 'elementor-control-alert elementor-panel-alert elementor-panel-alert-info', |
| 143 |
'ai' => [ |
| 144 |
'active' => false, |
| 145 |
], |
| 146 |
'condition' => [ |
| 147 |
'better_payment_form_payment_type' => 'split-payment', |
| 148 |
'better_payment_form_layout!' => ['layout-1', 'layout-2', 'layout-3', 'layout-6-pro'], |
| 149 |
], |
| 150 |
] |
| 151 |
); |
| 152 |
|
| 153 |
$widget->add_control( |
| 154 |
'better_payment_split_installment_price_ids', |
| 155 |
[ |
| 156 |
'label' => esc_html__( 'Installments', 'better-payment' ), |
| 157 |
'type' => Controls_Manager::REPEATER, |
| 158 |
'separator' => 'after', |
| 159 |
'default' => [ |
| 160 |
[ |
| 161 |
'better_payment_split_installment_name' => '3 Months', |
| 162 |
'better_payment_split_installment_price_id' => '', |
| 163 |
'better_payment_split_installment_iteration' => 3, |
| 164 |
], |
| 165 |
[ |
| 166 |
'better_payment_split_installment_name' => '6 Months', |
| 167 |
'better_payment_split_installment_price_id' => '', |
| 168 |
'better_payment_split_installment_iteration' => 6, |
| 169 |
], |
| 170 |
[ |
| 171 |
'better_payment_split_installment_name' => '9 Months', |
| 172 |
'better_payment_split_installment_price_id' => '', |
| 173 |
'better_payment_split_installment_iteration' => 9, |
| 174 |
], |
| 175 |
[ |
| 176 |
'better_payment_split_installment_name' => '12 Months', |
| 177 |
'better_payment_split_installment_price_id' => '', |
| 178 |
'better_payment_split_installment_iteration' => 12, |
| 179 |
], |
| 180 |
], |
| 181 |
'fields' => $repeater_split_payment->get_controls(), |
| 182 |
'title_field' => '<i class="{{ better_payment_split_installment_name }}" aria-hidden="true"></i> {{{ better_payment_split_installment_name }}}', |
| 183 |
'condition' => [ |
| 184 |
'better_payment_form_payment_type' => 'split-payment', |
| 185 |
'better_payment_form_layout!' => ['layout-1', 'layout-2', 'layout-3', 'layout-6-pro'], |
| 186 |
], |
| 187 |
] |
| 188 |
); |
| 189 |
|
| 190 |
$repeater_recurring_payment = new Repeater(); |
| 191 |
|
| 192 |
$repeater_recurring_payment->add_control( |
| 193 |
'better_payment_recurring_name', |
| 194 |
[ |
| 195 |
'label' => esc_html__( 'Interval Name', 'better-payment' ), |
| 196 |
'type' => Controls_Manager::TEXT, |
| 197 |
'placeholder' => 'Interval Name', |
| 198 |
'label_block' => true, |
| 199 |
'ai' => [ |
| 200 |
'active' => false, |
| 201 |
], |
| 202 |
] |
| 203 |
); |
| 204 |
|
| 205 |
$repeater_recurring_payment->add_control( |
| 206 |
'better_payment_recurring_price_id', |
| 207 |
[ |
| 208 |
'label' => esc_html__( 'Price ID', 'better-payment' ), |
| 209 |
'type' => Controls_Manager::TEXT, |
| 210 |
'placeholder' => 'price_G0FvDp6vZvdwRZ', |
| 211 |
'label_block' => true, |
| 212 |
'ai' => [ |
| 213 |
'active' => false, |
| 214 |
], |
| 215 |
] |
| 216 |
); |
| 217 |
|
| 218 |
$widget->add_control( |
| 219 |
'better_payment_recurring_price_ids', |
| 220 |
[ |
| 221 |
'label' => esc_html__( 'Intervals', 'better-payment' ), |
| 222 |
'type' => Controls_Manager::REPEATER, |
| 223 |
'separator' => 'after', |
| 224 |
'default' => [ |
| 225 |
[ |
| 226 |
'better_payment_recurring_name' => 'Monthly', |
| 227 |
'better_payment_recurring_price_id' => '', |
| 228 |
], |
| 229 |
[ |
| 230 |
'better_payment_recurring_name' => 'Yearly', |
| 231 |
'better_payment_recurring_price_id' => '', |
| 232 |
], |
| 233 |
], |
| 234 |
'fields' => $repeater_recurring_payment->get_controls(), |
| 235 |
'title_field' => '<i class="{{ better_payment_recurring_name }}" aria-hidden="true"></i> {{{ better_payment_recurring_name }}}', |
| 236 |
'condition' => [ |
| 237 |
'better_payment_form_payment_type' => 'recurring', |
| 238 |
'better_payment_form_layout' => 'layout-5-pro', |
| 239 |
], |
| 240 |
] |
| 241 |
); |
| 242 |
|
| 243 |
$widget->add_control( |
| 244 |
'better_payment_one_time_recurring_product_id', |
| 245 |
[ |
| 246 |
'label' => esc_html__( 'Product ID', 'better-payment' ), |
| 247 |
'type' => Controls_Manager::TEXT, |
| 248 |
'placeholder' => 'prod_G0FvDp6vZvdwRZ', |
| 249 |
'label_block' => true, |
| 250 |
'ai' => [ |
| 251 |
'active' => false, |
| 252 |
], |
| 253 |
'condition' => [ |
| 254 |
'better_payment_form_payment_type' => 'mixed', |
| 255 |
'better_payment_form_layout' => ['layout-4-pro', 'layout-5-pro'], |
| 256 |
] |
| 257 |
] |
| 258 |
); |
| 259 |
|
| 260 |
$repeater_mixed_payment = new Repeater(); |
| 261 |
|
| 262 |
$repeater_mixed_payment->add_control( |
| 263 |
'better_payment_mixed_interval_type', |
| 264 |
[ |
| 265 |
'label' => esc_html__( 'Interval Type', 'better-payment' ), |
| 266 |
'type' => Controls_Manager::SELECT, |
| 267 |
'default' => 'day', |
| 268 |
'options' => [ |
| 269 |
'day' => 'Day', |
| 270 |
'week' => 'Week', |
| 271 |
'month' => 'Month', |
| 272 |
'year' => 'Year', |
| 273 |
], |
| 274 |
] |
| 275 |
); |
| 276 |
|
| 277 |
$repeater_mixed_payment->add_control( |
| 278 |
'better_payment_mixed_name', |
| 279 |
[ |
| 280 |
'label' => esc_html__( 'Interval Name', 'better-payment' ), |
| 281 |
'type' => Controls_Manager::TEXT, |
| 282 |
'placeholder' => 'Interval Name', |
| 283 |
'label_block' => true, |
| 284 |
'ai' => [ |
| 285 |
'active' => false, |
| 286 |
], |
| 287 |
] |
| 288 |
); |
| 289 |
|
| 290 |
$repeater_mixed_payment->add_control( |
| 291 |
'better_payment_mixed_interval_day', |
| 292 |
[ |
| 293 |
'label' => esc_html__( 'Interval', 'better-payment' ), |
| 294 |
'type' => Controls_Manager::NUMBER, |
| 295 |
'min' => 1, |
| 296 |
'max' => 1095, |
| 297 |
'condition' => [ |
| 298 |
'better_payment_mixed_interval_type' => ['day'], |
| 299 |
], |
| 300 |
] |
| 301 |
); |
| 302 |
|
| 303 |
$repeater_mixed_payment->add_control( |
| 304 |
'better_payment_mixed_interval_month', |
| 305 |
[ |
| 306 |
'label' => esc_html__( 'Interval', 'better-payment' ), |
| 307 |
'type' => Controls_Manager::NUMBER, |
| 308 |
'min' => 1, |
| 309 |
'max' => 36, |
| 310 |
'condition' => [ |
| 311 |
'better_payment_mixed_interval_type' => ['month'], |
| 312 |
], |
| 313 |
] |
| 314 |
); |
| 315 |
|
| 316 |
$repeater_mixed_payment->add_control( |
| 317 |
'better_payment_mixed_interval_week', |
| 318 |
[ |
| 319 |
'label' => esc_html__( 'Interval', 'better-payment' ), |
| 320 |
'type' => Controls_Manager::NUMBER, |
| 321 |
'min' => 1, |
| 322 |
'max' => 156, |
| 323 |
'condition' => [ |
| 324 |
'better_payment_mixed_interval_type' => ['week'], |
| 325 |
], |
| 326 |
] |
| 327 |
); |
| 328 |
|
| 329 |
$repeater_mixed_payment->add_control( |
| 330 |
'better_payment_mixed_interval_year', |
| 331 |
[ |
| 332 |
'label' => esc_html__( 'Interval', 'better-payment' ), |
| 333 |
'type' => Controls_Manager::NUMBER, |
| 334 |
'min' => 1, |
| 335 |
'max' => 3, |
| 336 |
'condition' => [ |
| 337 |
'better_payment_mixed_interval_type' => ['year'], |
| 338 |
], |
| 339 |
] |
| 340 |
); |
| 341 |
|
| 342 |
$repeater_mixed_payment->add_control( |
| 343 |
'better_payment_mixed_installment_options_note1', |
| 344 |
[ |
| 345 |
'type' => Controls_Manager::RAW_HTML, |
| 346 |
'raw' => sprintf( |
| 347 |
__( '<p>Maximum interval: 3 years or equivalent.</p>', 'better-payment' ), |
| 348 |
), |
| 349 |
'content_classes' => 'elementor-control-alert elementor-panel-alert elementor-panel-alert-info', |
| 350 |
] |
| 351 |
); |
| 352 |
|
| 353 |
$widget->add_control( |
| 354 |
'better_payment_mixed_installment_options', |
| 355 |
[ |
| 356 |
'label' => esc_html__( 'Mixed Intervals', 'better-payment' ), |
| 357 |
'type' => Controls_Manager::REPEATER, |
| 358 |
'separator' => 'after', |
| 359 |
'default' => [ |
| 360 |
[ |
| 361 |
'better_payment_mixed_name' => 'Monthly', |
| 362 |
'better_payment_mixed_interval_month' => 1, |
| 363 |
'better_payment_mixed_interval_type' => 'month', |
| 364 |
], |
| 365 |
[ |
| 366 |
'better_payment_mixed_name' => 'Daily', |
| 367 |
'better_payment_mixed_interval_day' => 1, |
| 368 |
'better_payment_mixed_interval_type' => 'day', |
| 369 |
], |
| 370 |
[ |
| 371 |
'better_payment_mixed_name' => 'Weekly', |
| 372 |
'better_payment_mixed_interval_week' => 1, |
| 373 |
'better_payment_mixed_interval_type' => 'week', |
| 374 |
], |
| 375 |
[ |
| 376 |
'better_payment_mixed_name' => 'Yearly', |
| 377 |
'better_payment_mixed_interval_year' => 1, |
| 378 |
'better_payment_mixed_interval_type' => 'year', |
| 379 |
], |
| 380 |
[ |
| 381 |
'better_payment_mixed_name' => 'Every 3 Months', |
| 382 |
'better_payment_mixed_interval_month' => 3, |
| 383 |
'better_payment_mixed_interval_type' => 'month', |
| 384 |
], |
| 385 |
[ |
| 386 |
'better_payment_mixed_name' => 'Every 6 Months', |
| 387 |
'better_payment_mixed_interval_month' => 6, |
| 388 |
'better_payment_mixed_interval_type' => 'month', |
| 389 |
], |
| 390 |
], |
| 391 |
'fields' => $repeater_mixed_payment->get_controls(), |
| 392 |
'title_field' => '<i class="{{ better_payment_mixed_name }}" aria-hidden="true"></i> {{{ better_payment_mixed_name }}}', |
| 393 |
'condition' => [ |
| 394 |
'better_payment_form_payment_type' => 'mixed', |
| 395 |
'better_payment_form_layout' => ['layout-4-pro', 'layout-5-pro'], |
| 396 |
], |
| 397 |
] |
| 398 |
); |
| 399 |
|
| 400 |
$widget->add_control( |
| 401 |
'better_payment_form_recurring_webhook_stripe_secret', |
| 402 |
[ |
| 403 |
'label' => esc_html__( 'Webhook Secret', 'better-payment' ), |
| 404 |
'type' => Controls_Manager::TEXT, |
| 405 |
'description' => sprintf( |
| 406 |
__( '<p>Create a webhook endpoint from Stripe dashboard and <a href="%1$s" target="_blank">get the webhook secret.</a></p>', 'better-payment' ), |
| 407 |
esc_url('//betterpayment.co/docs/add-webhook-endpoint-recurring-better-payment/'), |
| 408 |
), |
| 409 |
'placeholder' => 'whsec_...', |
| 410 |
'label_block' => true, |
| 411 |
'ai' => [ |
| 412 |
'active' => false, |
| 413 |
], |
| 414 |
'condition' => [ |
| 415 |
'better_payment_form_payment_type' => [ 'recurring', 'split-payment' ], |
| 416 |
'better_payment_form_layout!' => ['layout-1', 'layout-2', 'layout-3', 'layout-6-pro'], |
| 417 |
], |
| 418 |
] |
| 419 |
); |
| 420 |
|
| 421 |
$widget->add_control( |
| 422 |
'better_payment_form_recurring_webhook_stripe', |
| 423 |
[ |
| 424 |
'type' => Controls_Manager::RAW_HTML, |
| 425 |
'raw' => sprintf( |
| 426 |
__( '<p><a href="%1$s" target="_blank">Your webhook endpoint url »</a><br>%2$s</p>', 'better-payment' ), |
| 427 |
esc_url('//wpdeveloper.com/docs-category/better-payment/'), |
| 428 |
esc_url_raw( get_permalink( get_the_ID() ) . '?webhook-stripe=1' ) |
| 429 |
), |
| 430 |
'content_classes' => 'elementor-control-alert elementor-panel-alert elementor-panel-alert-info', |
| 431 |
'ai' => [ |
| 432 |
'active' => false, |
| 433 |
], |
| 434 |
'condition' => [ |
| 435 |
'better_payment_form_payment_type' => [ 'recurring', 'split-payment' ], |
| 436 |
'better_payment_form_layout!' => ['layout-1', 'layout-2', 'layout-3', 'layout-6-pro'], |
| 437 |
], |
| 438 |
] |
| 439 |
); |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Payment Settings: layout 6's eCommerce platform and product pickers. |
| 444 |
* |
| 445 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 446 |
*/ |
| 447 |
public static function product_controls( $widget ) { |
| 448 |
$widget->add_control( 'better_payment_form_layout_6_woocommerce_notice', [ |
| 449 |
'type' => Controls_Manager::RAW_HTML, |
| 450 |
'raw' => sprintf( __( '<a href="%1$s" target="_blank"><strong>WooCommerce</strong></a> is not installed/activated on your site. Please install and activate <a href="%1$s" target="_blank"><strong>WooCommerce</strong></a> first.', 'better-payment' ), esc_url('plugin-install.php?s=woocommerce&tab=search&type=term') ), |
| 451 |
'content_classes' => 'better-payment-warning', |
| 452 |
'conditions' => [ |
| 453 |
'relation' => 'and', |
| 454 |
'terms' => [ |
| 455 |
[ |
| 456 |
'name' => 'better_payment_form_layout', |
| 457 |
'value' => 'layout-6-pro' . ( ! class_exists('woocommerce') ? '' : 'exist' ), |
| 458 |
], |
| 459 |
[ |
| 460 |
'relation' => 'or', |
| 461 |
'terms' => [ |
| 462 |
[ |
| 463 |
'name' => 'better_payment_form_payment_source', |
| 464 |
'value' => 'woocommerce', |
| 465 |
], |
| 466 |
[ |
| 467 |
'name' => 'better_payment_form_layout_6_ecommerce_platform', |
| 468 |
'value' => '', |
| 469 |
], |
| 470 |
[ |
| 471 |
'name' => 'better_payment_form_layout_6_ecommerce_platform', |
| 472 |
'value' => 'woocommerce', |
| 473 |
], |
| 474 |
], |
| 475 |
], |
| 476 |
], |
| 477 |
], |
| 478 |
] ); |
| 479 |
|
| 480 |
$widget->add_control( |
| 481 |
'better_payment_form_layout_6_ecommerce_platform', |
| 482 |
[ |
| 483 |
'label' => esc_html__( 'eCommerce Platform', 'better-payment' ), |
| 484 |
'type' => Controls_Manager::SELECT, |
| 485 |
'default' => 'woocommerce', |
| 486 |
'options' => [ |
| 487 |
'woocommerce' => 'WooCommerce', |
| 488 |
'fluentcart' => 'FluentCart', |
| 489 |
], |
| 490 |
'condition' => [ |
| 491 |
'better_payment_form_layout' => ['layout-6-pro'], |
| 492 |
], |
| 493 |
] |
| 494 |
); |
| 495 |
|
| 496 |
$widget->add_control('better_payment_form_woocommerce_product_ids', [ |
| 497 |
'label' => esc_html__('Select Products', 'better-payment'), |
| 498 |
'type' => 'better-payment-select2', |
| 499 |
'label_block' => true, |
| 500 |
'multiple' => true, |
| 501 |
'source_name' => 'post_type', |
| 502 |
'source_type' => 'product', |
| 503 |
'placeholder' => __( ' ', 'better-payment' ), |
| 504 |
'condition' => [ |
| 505 |
'better_payment_form_layout' => ['layout-6-pro'], |
| 506 |
'better_payment_form_layout_6_ecommerce_platform' => 'woocommerce', |
| 507 |
], |
| 508 |
]); |
| 509 |
|
| 510 |
$widget->add_control('better_payment_form_fluentcart_product_ids', [ |
| 511 |
'label' => esc_html__('Select Products', 'better-payment'), |
| 512 |
'type' => 'better-payment-select2', |
| 513 |
'label_block' => true, |
| 514 |
'multiple' => true, |
| 515 |
'source_name' => 'post_type', |
| 516 |
'source_type' => 'fluent-products', |
| 517 |
'placeholder' => __( ' ', 'better-payment' ), |
| 518 |
'condition' => [ |
| 519 |
'better_payment_form_layout' => ['layout-6-pro'], |
| 520 |
'better_payment_form_layout_6_ecommerce_platform' => 'fluentcart', |
| 521 |
], |
| 522 |
]); |
| 523 |
|
| 524 |
$widget->add_control( 'better_payment_form_layout_6_fluentcart_notice', [ |
| 525 |
'type' => Controls_Manager::RAW_HTML, |
| 526 |
'raw' => sprintf( __( '<a href="%1$s" target="_blank"><strong>FluentCart</strong></a> is not installed/activated on your site. Please install and activate <a href="%1$s" target="_blank"><strong>FluentCart</strong></a> first.', 'better-payment' ), esc_url('plugin-install.php?s=fluentcart&tab=search&type=term') ), |
| 527 |
'content_classes' => 'better-payment-warning', |
| 528 |
'conditions' => [ |
| 529 |
'relation' => 'and', |
| 530 |
'terms' => [ |
| 531 |
[ |
| 532 |
'name' => 'better_payment_form_layout', |
| 533 |
'value' => 'layout-6-pro', |
| 534 |
], |
| 535 |
[ |
| 536 |
'name' => 'better_payment_form_layout_6_ecommerce_platform', |
| 537 |
'value' => 'fluentcart' . ( ! function_exists('fluentCart') ? '' : 'exist' ), |
| 538 |
], |
| 539 |
], |
| 540 |
], |
| 541 |
] ); |
| 542 |
} |
| 543 |
|
| 544 |
/** |
| 545 |
* Form Settings: the form-field repeaters of layouts 4, 5 and 6. |
| 546 |
* |
| 547 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 548 |
* @param \Elementor\Repeater $form_fields_repeater The shared form-field repeater. |
| 549 |
*/ |
| 550 |
public static function form_fields_controls( $widget, $form_fields_repeater ) { |
| 551 |
$form_fields_first_name_layout_4_5_6 = [ |
| 552 |
'better_payment_field_name_heading' => esc_html__( 'First name', 'better-payment' ), |
| 553 |
'better_payment_field_name_placeholder' => esc_html__( 'First name', 'better-payment' ), |
| 554 |
'better_payment_field_type' => 'text', |
| 555 |
'better_payment_primary_field_type' => 'primary_first_name', |
| 556 |
'better_payment_field_name_show' => 'yes', |
| 557 |
'better_payment_field_name_required' => 'no', |
| 558 |
'better_payment_field_name_display_inline' => 'inline-block', |
| 559 |
'better_payment_field_name_display_inline_width' => [ |
| 560 |
'size' => '48', |
| 561 |
'unit' => '%', |
| 562 |
], |
| 563 |
]; |
| 564 |
|
| 565 |
$form_fields_last_name_layout_4_5_6 = [ |
| 566 |
'better_payment_field_name_heading' => esc_html__( 'Last name', 'better-payment' ), |
| 567 |
'better_payment_field_name_placeholder' => esc_html__( 'Last name', 'better-payment' ), |
| 568 |
'better_payment_field_type' => 'text', |
| 569 |
'better_payment_primary_field_type' => 'primary_last_name', |
| 570 |
'better_payment_field_name_show' => 'yes', |
| 571 |
'better_payment_field_name_required' => 'no', |
| 572 |
'better_payment_field_name_display_inline' => 'inline-block', |
| 573 |
'better_payment_field_name_display_inline_width' => [ |
| 574 |
'size' => '48', |
| 575 |
'unit' => '%', |
| 576 |
], |
| 577 |
]; |
| 578 |
|
| 579 |
$form_field_email_layout_4_5_6 = [ |
| 580 |
'better_payment_field_name_heading' => esc_html__( 'Email', 'better-payment' ), |
| 581 |
'better_payment_field_name_placeholder' => esc_html__( 'Enter your email', 'better-payment' ), |
| 582 |
'better_payment_field_type' => 'email', |
| 583 |
'better_payment_primary_field_type' => 'primary_email', |
| 584 |
'better_payment_field_name_show' => 'yes', |
| 585 |
'better_payment_field_name_required' => 'yes', |
| 586 |
]; |
| 587 |
|
| 588 |
$form_field_payment_amount_layout_4_5_6 = [ |
| 589 |
'better_payment_field_name_heading' => esc_html__( 'Amount', 'better-payment' ), |
| 590 |
'better_payment_field_name_placeholder' => esc_html__( 'Other amount', 'better-payment' ), |
| 591 |
'better_payment_field_type' => 'number', |
| 592 |
'better_payment_primary_field_type' => 'primary_payment_amount', |
| 593 |
'better_payment_field_name_show' => 'yes', |
| 594 |
'better_payment_field_name_required' => 'yes', |
| 595 |
]; |
| 596 |
|
| 597 |
$form_field_payment_amount_layout_4_5_6_desc = [ |
| 598 |
'better_payment_field_name_heading' => esc_html__( 'Amount to pay', 'better-payment' ), |
| 599 |
'better_payment_field_name_placeholder' => esc_html__( 'Other amount', 'better-payment' ), |
| 600 |
'better_payment_field_type' => 'number', |
| 601 |
'better_payment_primary_field_type' => 'primary_payment_amount', |
| 602 |
'better_payment_field_name_show' => 'yes', |
| 603 |
'better_payment_field_name_required' => 'yes', |
| 604 |
]; |
| 605 |
|
| 606 |
$form_fields_defaults_layout_4_5_6 = [ |
| 607 |
$form_fields_first_name_layout_4_5_6, |
| 608 |
$form_fields_last_name_layout_4_5_6, |
| 609 |
$form_field_email_layout_4_5_6, |
| 610 |
$form_field_payment_amount_layout_4_5_6, |
| 611 |
]; |
| 612 |
|
| 613 |
$form_fields_defaults_layout_4_5_6_desc = [ |
| 614 |
$form_field_payment_amount_layout_4_5_6_desc, |
| 615 |
$form_fields_first_name_layout_4_5_6, |
| 616 |
$form_fields_last_name_layout_4_5_6, |
| 617 |
$form_field_email_layout_4_5_6, |
| 618 |
]; |
| 619 |
|
| 620 |
$form_fields_defaults_layout_4_5_6_woo = [ |
| 621 |
$form_fields_first_name_layout_4_5_6, |
| 622 |
$form_fields_last_name_layout_4_5_6, |
| 623 |
$form_field_email_layout_4_5_6, |
| 624 |
]; |
| 625 |
|
| 626 |
$widget->add_control( |
| 627 |
'better_payment_form_fields_layout_4_5_6', |
| 628 |
[ |
| 629 |
'label' => esc_html__( 'Form Fields', 'better-payment' ), |
| 630 |
'type' => \Elementor\Controls_Manager::REPEATER, |
| 631 |
'fields' => $form_fields_repeater->get_controls(), |
| 632 |
'default' => $form_fields_defaults_layout_4_5_6, |
| 633 |
'title_field' => '{{{ better_payment_field_name_heading }}}', |
| 634 |
'condition' => [ |
| 635 |
'better_payment_form_layout' => ['layout-4-pro'], |
| 636 |
], |
| 637 |
] |
| 638 |
); |
| 639 |
|
| 640 |
$widget->add_control( |
| 641 |
'better_payment_form_fields_layout_4_5_6_desc', |
| 642 |
[ |
| 643 |
'label' => esc_html__( 'Form Fields', 'better-payment' ), |
| 644 |
'type' => \Elementor\Controls_Manager::REPEATER, |
| 645 |
'fields' => $form_fields_repeater->get_controls(), |
| 646 |
'default' => $form_fields_defaults_layout_4_5_6_desc, |
| 647 |
'title_field' => '{{{ better_payment_field_name_heading }}}', |
| 648 |
'condition' => [ |
| 649 |
'better_payment_form_layout' => ['layout-5-pro'], |
| 650 |
], |
| 651 |
] |
| 652 |
); |
| 653 |
|
| 654 |
$widget->add_control( |
| 655 |
'better_payment_form_fields_layout_4_5_6_woo', |
| 656 |
[ |
| 657 |
'label' => esc_html__( 'Form Fields', 'better-payment' ), |
| 658 |
'type' => \Elementor\Controls_Manager::REPEATER, |
| 659 |
'fields' => $form_fields_repeater->get_controls(), |
| 660 |
'default' => $form_fields_defaults_layout_4_5_6_woo, |
| 661 |
'title_field' => '{{{ better_payment_field_name_heading }}}', |
| 662 |
'condition' => [ |
| 663 |
'better_payment_form_layout' => ['layout-6-pro'], |
| 664 |
], |
| 665 |
] |
| 666 |
); |
| 667 |
} |
| 668 |
|
| 669 |
/** |
| 670 |
* Amount list: the "Show Amount List" switcher of layouts 4, 5 and 6. |
| 671 |
* |
| 672 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 673 |
*/ |
| 674 |
public static function amount_list_toggle_control( $widget ) { |
| 675 |
$widget->add_control( |
| 676 |
'better_payment_show_amount_list_layout_4_5_6', |
| 677 |
[ |
| 678 |
'label' => __( 'Show Amount List', 'better-payment' ), |
| 679 |
'type' => Controls_Manager::SWITCHER, |
| 680 |
'label_on' => __( 'Yes', 'better-payment' ), |
| 681 |
'label_off' => __( 'No', 'better-payment' ), |
| 682 |
'return_value' => 'yes', |
| 683 |
'default' => 'yes', |
| 684 |
'condition' => [ |
| 685 |
'better_payment_form_layout' => ['layout-4-pro', 'layout-5-pro', 'layout-6-pro'], |
| 686 |
'better_payment_form_payment_type!' => [ 'recurring', 'split-payment' ], |
| 687 |
], |
| 688 |
] |
| 689 |
); |
| 690 |
} |
| 691 |
|
| 692 |
/** |
| 693 |
* Amount list: the amounts of layouts 4, 5 and 6. |
| 694 |
* |
| 695 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 696 |
* @param \Elementor\Repeater $repeater The amount repeater. |
| 697 |
*/ |
| 698 |
public static function amount_list_control( $widget, $repeater ) { |
| 699 |
$widget->add_control( |
| 700 |
'better_payment_amount_layout_4_5_6', |
| 701 |
[ |
| 702 |
'label' => esc_html__( 'Amount List', 'better-payment' ), |
| 703 |
'type' => Controls_Manager::REPEATER, |
| 704 |
'default' => [ |
| 705 |
[ |
| 706 |
'better_payment_amount_val' => 10 |
| 707 |
], |
| 708 |
[ |
| 709 |
'better_payment_amount_val' => 30 |
| 710 |
], |
| 711 |
[ |
| 712 |
'better_payment_amount_val' => 50 |
| 713 |
], |
| 714 |
[ |
| 715 |
'better_payment_amount_val' => 100 |
| 716 |
], |
| 717 |
[ |
| 718 |
'better_payment_amount_val' => 500 |
| 719 |
], |
| 720 |
], |
| 721 |
'fields' => $repeater->get_controls(), |
| 722 |
'title_field' => '<i class="{{ better_payment_amount_val }}" aria-hidden="true"></i> {{{ better_payment_amount_val }}}', |
| 723 |
'condition' => [ |
| 724 |
'better_payment_show_amount_list_layout_4_5_6' => 'yes', |
| 725 |
'better_payment_form_payment_type!' => [ 'recurring', 'split-payment' ], |
| 726 |
'better_payment_form_layout' => ['layout-4-pro', 'layout-5-pro', 'layout-6-pro'], |
| 727 |
], |
| 728 |
] |
| 729 |
); |
| 730 |
} |
| 731 |
|
| 732 |
/** |
| 733 |
* Form Custom Text: the form title and sub-title of layouts 4, 5 and 6. |
| 734 |
* |
| 735 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 736 |
*/ |
| 737 |
public static function form_title_controls( $widget ) { |
| 738 |
$widget->add_control( |
| 739 |
'better_payment_form_form_title_text', |
| 740 |
[ |
| 741 |
'label' => esc_html__( 'Form Title', 'better-payment' ), |
| 742 |
'type' => Controls_Manager::TEXT, |
| 743 |
'label_block' => true, |
| 744 |
'ai' => [ |
| 745 |
'active' => false, |
| 746 |
], |
| 747 |
'condition' => [ |
| 748 |
'better_payment_form_layout' => ['layout-4-pro', 'layout-5-pro', 'layout-6-pro'], |
| 749 |
], |
| 750 |
] |
| 751 |
); |
| 752 |
|
| 753 |
$widget->add_control( |
| 754 |
'better_payment_form_form_sub_title_text', |
| 755 |
[ |
| 756 |
'label' => esc_html__( 'Form Sub-Title', 'better-payment' ), |
| 757 |
'type' => Controls_Manager::TEXT, |
| 758 |
'label_block' => true, |
| 759 |
'ai' => [ |
| 760 |
'active' => false, |
| 761 |
], |
| 762 |
'condition' => [ |
| 763 |
'better_payment_form_layout' => ['layout-5-pro'], |
| 764 |
], |
| 765 |
] |
| 766 |
); |
| 767 |
} |
| 768 |
|
| 769 |
/** |
| 770 |
* The payment-type condition Pro adds to three of Lite's own controls. |
| 771 |
* |
| 772 |
* PayPal and Paystack cannot take a recurring or split payment, and the amount |
| 773 |
* list does not apply to one, so those controls hide once either is chosen. |
| 774 |
* Lite asks for it on `better_payment/elementor/editor/pro_layout_control_condition` |
| 775 |
* rather than hardcoding it: the condition names `better_payment_form_payment_type`, |
| 776 |
* which only exists while Pro's controls are registered, and Elementor hides — |
| 777 |
* and nulls when rendering — a control whose condition names a missing control. |
| 778 |
* |
| 779 |
* @param mixed $condition The control's condition. |
| 780 |
* @param string $control_id The control id. |
| 781 |
* @return array |
| 782 |
*/ |
| 783 |
public static function control_condition( $condition, $control_id = '' ) { |
| 784 |
$condition = is_array( $condition ) ? $condition : []; |
| 785 |
|
| 786 |
if ( in_array( $control_id, [ 'better_payment_form_paypal_enable', 'better_payment_form_paystack_enable', 'better_payment_amount' ], true ) ) { |
| 787 |
$condition['better_payment_form_payment_type!'] = [ 'recurring', 'split-payment' ]; |
| 788 |
} |
| 789 |
|
| 790 |
return $condition; |
| 791 |
} |
| 792 |
} |
| 793 |
|