class-evf-builder-fields.php
4 weeks ago
class-evf-builder-integrations.php
4 weeks ago
class-evf-builder-page.php
2 months ago
class-evf-builder-payments.php
4 weeks ago
class-evf-builder-settings.php
3 months ago
class-evf-builder-payments.php
151 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Builder Payments |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @since |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( ! class_exists( 'EVF_Builder_Payments' ) ) { |
| 12 | /** |
| 13 | * EVF_Builder_Payments class. |
| 14 | */ |
| 15 | class EVF_Builder_Payments extends EVF_Builder_Page { |
| 16 | |
| 17 | /** |
| 18 | * Constructor. |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | $this->id = 'payments'; |
| 22 | $this->label = __( 'Payments', 'everest-forms-pro' ); |
| 23 | $this->sidebar = true; |
| 24 | |
| 25 | parent::__construct(); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Add this page to builder tabs. |
| 30 | * |
| 31 | * Hides the Payments tab on new forms in the free version — no payment |
| 32 | * gateways are available yet so showing it just adds noise. |
| 33 | * |
| 34 | * @param array $pages Builder pages. |
| 35 | * @return array |
| 36 | */ |
| 37 | public function add_builder_page( $pages ) { |
| 38 | return $pages; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Outputs the builder sidebar. |
| 43 | */ |
| 44 | public function output_sidebar() { |
| 45 | $payments = apply_filters( 'everest_forms_available_payments', array() ); |
| 46 | |
| 47 | if ( ! defined( 'EFP_PLUGIN_FILE' ) ) { |
| 48 | $payments = $this->get_free_payments_catalog(); |
| 49 | } |
| 50 | |
| 51 | if ( ! empty( $payments ) ) { |
| 52 | foreach ( $payments as $payment ) { |
| 53 | if ( ! defined( 'EFP_PLUGIN_FILE' ) ) { |
| 54 | $video_id = isset( $payment['video_id'] ) ? $payment['video_id'] : ( isset( $payment['vedio_id'] ) ? $payment['vedio_id'] : '' ); |
| 55 | echo '<a href="#" class="integration-name evf-panel-tab evf-payments-panel everest-forms-panel-sidebar-section everest-forms-panel-sidebar-section-' . esc_attr( $payment['id'] ) . ' upgrade-addons-settings" data-section="' . esc_attr( $payment['id'] ) . '" data-name="' . esc_attr( $payment['name'] ) . '" data-links="' . esc_attr( $video_id ) . '">'; |
| 56 | echo '<div style="display: flex; align-items: center; gap: 12px;">'; |
| 57 | if ( ! empty( $payment['icon'] ) ) { |
| 58 | echo '<figure class="logo"><img src="' . esc_url( $payment['icon'] ) . '"></figure>'; |
| 59 | } |
| 60 | echo '<span>' . esc_html( $payment['name'] ) . '</span>'; |
| 61 | echo '</div>'; |
| 62 | echo '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 18 18"><rect width="16.889" height="16.889" x=".444" y=".444" fill="#ff8c39" stroke="#ff8c39" stroke-width=".889" rx="2.222"/><path fill="#efefef" d="m8.89 4.444 2.666 7.111H6.223z"/><path fill="#fff" fill-rule="evenodd" d="m4.445 6.222.635 5.333h7.619l.635-5.333-4.445 3.666zm8.254 5.841h-7.62v1.27h7.62z" clip-rule="evenodd"/></svg>'; |
| 63 | echo '</a>'; |
| 64 | } else { |
| 65 | $this->add_sidebar_tab( $payment['name'], $payment['id'], $payment['icon'], $this->id ); |
| 66 | do_action( 'everest_forms_payment_connections_' . $payment['id'], $payment ); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get free payments catalog from extensions JSON. |
| 74 | * |
| 75 | * @return array |
| 76 | */ |
| 77 | private function get_free_payments_catalog() { |
| 78 | $catalog = array(); |
| 79 | $file = dirname( EVF_PLUGIN_FILE ) . '/assets/extensions-json/sections/all_extensions.json'; |
| 80 | |
| 81 | if ( file_exists( $file ) ) { |
| 82 | $content = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 83 | $data = json_decode( $content, true ); |
| 84 | |
| 85 | if ( isset( $data['products'] ) && is_array( $data['products'] ) ) { |
| 86 | $data['features'] = isset( $data['features'] ) && is_array( $data['features'] ) ? $data['features'] : array(); |
| 87 | $items = array_merge( $data['products'], $data['features'] ); |
| 88 | |
| 89 | foreach ( $items as $item ) { |
| 90 | $category = isset( $item['category'] ) ? $item['category'] : ''; |
| 91 | if ( 'Payment Gateways' !== $category ) { |
| 92 | continue; |
| 93 | } |
| 94 | |
| 95 | $slug = isset( $item['slug'] ) ? $item['slug'] : ''; |
| 96 | $id = str_replace( 'everest-forms-', '', $slug ); |
| 97 | $name = isset( $item['name'] ) ? $item['name'] : ''; |
| 98 | $name = str_replace( 'Everest Forms - ', '', $name ); |
| 99 | $name = str_replace( 'Everest Forms- ', '', $name ); |
| 100 | $name = str_replace( 'Everest Forms-', '', $name ); |
| 101 | $name = str_replace( 'Everest Forms ', '', $name ); |
| 102 | $name = trim( $name ); |
| 103 | |
| 104 | $image = isset( $item['image'] ) ? $item['image'] : ''; |
| 105 | $icon = ! empty( $image ) ? plugins_url( 'assets/' . ltrim( $image, '/' ), EVF_PLUGIN_FILE ) : ''; |
| 106 | |
| 107 | $catalog[ $id ] = array( |
| 108 | 'id' => $id, |
| 109 | 'name' => $name, |
| 110 | 'icon' => $icon, |
| 111 | 'video_id' => isset( $item['demo_video_url'] ) ? $item['demo_video_url'] : '', |
| 112 | ); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return array_values( $catalog ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Outputs the builder content. |
| 122 | */ |
| 123 | public function output_content() { |
| 124 | $payment_settings = apply_filters( 'everest_forms_available_payments', array() ); |
| 125 | |
| 126 | if ( empty( $payment_settings ) ) { |
| 127 | $upgrade_url = apply_filters( |
| 128 | 'everest_forms_upgrade_url', |
| 129 | 'https://everestforms.net/upgrade/?utm_medium=evf-form-builder&utm_source=evf-free&utm_campaign=builder-pro-field-popup&utm_content=Upgrade%20to%20Pro' |
| 130 | ); |
| 131 | |
| 132 | echo '<div class="evf-panel-content-section evf-payment-setting-content evf-panel-content-section-info evf-builder-get-started">'; |
| 133 | echo '<h3>' . esc_html__( 'Get Started with Payments', 'everest-forms-pro' ) . '</h3>'; |
| 134 | echo '<p>' . esc_html__( 'Payments are available in the Pro plan. Upgrade to install and connect them.', 'everest-forms-pro' ) . '</p>'; |
| 135 | echo '<div class="evf-builder-get-started-steps" style="display: flex; gap: 20px;">'; |
| 136 | echo '<span class="step" style="display: flex; align-items: center; gap: 10px; width: fit-content;"><span style="width: 26px; height: 26px; display: inline-block; background-color: #E1E1E1; border-radius: 4px; text-align: center; line-height: 24px;">1</span>' . esc_html__( 'Upgrade', 'everest-forms-pro' ) . '</span>'; |
| 137 | echo '<span class="step" style="display: flex; align-items: center; gap: 10px; width: fit-content;"><span style="width: 26px; height: 26px; display: inline-block; background-color: #E1E1E1; border-radius: 4px; text-align: center; line-height: 24px;">2</span>' . esc_html__( 'Activate add-on', 'everest-forms-pro' ) . '</span>'; |
| 138 | echo '<span class="step" style="display: flex; align-items: center; gap: 10px; width: fit-content;"><span style="width: 26px; height: 26px; display: inline-block; background-color: #E1E1E1; border-radius: 4px; text-align: center; line-height: 24px;">3</span>' . esc_html__( 'Connect', 'everest-forms-pro' ) . '</span>'; |
| 139 | echo '</div>'; |
| 140 | echo '<p style="margin-top: 40px;"><a class="everest-forms-btn everest-forms-btn-primary" style="display:inline-flex;align-items:center;gap:8px;" target="_blank" rel="noopener noreferrer" href="' . esc_url( $upgrade_url ) . '">' . esc_html__( 'Upgrade to Pro', 'everest-forms-pro' ) . '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14" width="14" height="14" aria-hidden="true" focusable="false"><path fill="#efefef" d="m7 1.167 3.5 9.333h-7z"/><path fill="#fff" fill-rule="evenodd" d="M12 12.834H2v-1.667h10zm0-2.334H2l-.833-7L7 8.312 12.833 3.5z" clip-rule="evenodd"/></svg></a></p>'; |
| 141 | echo '</div>'; |
| 142 | } else { |
| 143 | do_action( 'everest_forms_payments_panel_content', $this->form ); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return new EVF_Builder_Payments(); |
| 149 | |
| 150 | } |
| 151 |