assets
5 years ago
sections
6 years ago
views
6 years ago
Actions.php
6 years ago
Sequoia.php
5 years ago
optionConfig.php
5 years ago
Actions.php
310 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Views\Form\Templates\Sequoia; |
| 4 | |
| 5 | use Give_Donate_Form; |
| 6 | use Give\Helpers\Form\Template as FormTemplateUtils; |
| 7 | |
| 8 | /** |
| 9 | * Class Actions |
| 10 | * |
| 11 | * @since 2.7.0 |
| 12 | * @package Give\Views\Form\Templates\Sequoia |
| 13 | */ |
| 14 | class Actions { |
| 15 | |
| 16 | protected $templateOptions; |
| 17 | |
| 18 | /** |
| 19 | * Initialize |
| 20 | * |
| 21 | * @since 2.7.0 |
| 22 | */ |
| 23 | public function init() { |
| 24 | // Get Template options |
| 25 | $this->templateOptions = FormTemplateUtils::getOptions(); |
| 26 | |
| 27 | // Set zero number of decimal. |
| 28 | add_filter( 'give_get_currency_formatting_settings', [ $this, 'setupZeroNumberOfDecimalInCurrencyFormattingSetting' ], 1 ); |
| 29 | add_filter( 'give_get_option_number_decimals', [ $this, 'setupZeroNumberOfDecimal' ], 1 ); |
| 30 | |
| 31 | // Handle personal section html template. |
| 32 | add_action( 'wp_ajax_give_cancel_login', [ $this, 'cancelLoginAjaxHanleder' ], 9 ); |
| 33 | add_action( 'wp_ajax_nopriv_give_cancel_login', [ $this, 'cancelLoginAjaxHanleder' ], 9 ); |
| 34 | add_action( 'wp_ajax_nopriv_give_checkout_register', [ $this, 'cancelLoginAjaxHanleder' ], 9 ); |
| 35 | |
| 36 | // Handle common hooks. |
| 37 | add_action( 'give_donation_form', [ $this, 'loadCommonHooks' ], 9, 2 ); |
| 38 | |
| 39 | // Setup hooks. |
| 40 | add_action( 'give_pre_form_output', [ $this, 'loadHooks' ], 1, 3 ); |
| 41 | |
| 42 | // Setup Stripe font Styles |
| 43 | add_filter( 'give_stripe_get_element_font_styles', [ $this, 'setupStripeFontStyles' ], 1 ); |
| 44 | |
| 45 | // Setup Stripe base styles |
| 46 | add_filter( 'give_stripe_get_element_base_styles', [ $this, 'setupStripeBaseStyles' ], 1 ); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | /** Set Stripe base styles consistent with Sequoia form template |
| 51 | * |
| 52 | * As per design requirement, we want to format Stripe elements to use Montserrat, with the same styling options as other text inputs. |
| 53 | * |
| 54 | * @since 2.7.0 |
| 55 | * @param object $styles |
| 56 | * @return object |
| 57 | */ |
| 58 | public function setupStripeBaseStyles( $styles ) { |
| 59 | $styles = '{ |
| 60 | "fontFamily": "Montserrat", |
| 61 | "color": "#8d8e8e", |
| 62 | "fontWeight": 400, |
| 63 | "fontSize": "14px", |
| 64 | "::placeholder": { |
| 65 | "color": "#8d8e8e" |
| 66 | }, |
| 67 | ":-webkit-autofill": { |
| 68 | "color": "#e39f48" |
| 69 | } |
| 70 | }'; |
| 71 | return json_decode( $styles ); |
| 72 | } |
| 73 | |
| 74 | /** Set Stripe Font styles consistent with Sequoia form template |
| 75 | * |
| 76 | * As per design requirement, we want to format Stripe elements to use Montserrat, with the same styling options as other text inputs. |
| 77 | * |
| 78 | * @since 2.7.0 |
| 79 | * @param array $fontStyles |
| 80 | * @return array |
| 81 | */ |
| 82 | public function setupStripeFontStyles( $fontStyles ) { |
| 83 | return [ |
| 84 | 'cssSrc' => 'https://fonts.googleapis.com/css2?family=Montserrat&display=swap', |
| 85 | ]; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Set zero as number of decimals in currency formatting setting. |
| 90 | * |
| 91 | * As per design requirement we want to format donation amount with zero decimal whether or not number of decimal admin setting set to zero. |
| 92 | * |
| 93 | * @since 2.7.0 |
| 94 | * @param array $currencyFormattingSettings |
| 95 | * @return array |
| 96 | */ |
| 97 | public function setupZeroNumberOfDecimalInCurrencyFormattingSetting( $currencyFormattingSettings ) { |
| 98 | $currencyFormattingSettings['number_decimals'] = 0; |
| 99 | return $currencyFormattingSettings; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * Return zero as number of decimals setting value or currency formatting value. |
| 105 | * |
| 106 | * As per design requirement we want to format donation amount with zero decimal whether or not number of decimal admin setting set to zero. |
| 107 | * |
| 108 | * @since 2.7.0 |
| 109 | * @return int|array |
| 110 | */ |
| 111 | public function setupZeroNumberOfDecimal() { |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Handle cancel login and checkout register ajax request. |
| 117 | * |
| 118 | * @since 2.7.0 |
| 119 | * @return void |
| 120 | */ |
| 121 | public function cancelLoginAjaxHanleder() { |
| 122 | // add_action( 'give_donation_form_before_personal_info', [ $this, 'getIntroductionSectionTextSubSection' ] ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Setup common hooks |
| 127 | * |
| 128 | * @param int $formId |
| 129 | * @param array $args |
| 130 | */ |
| 131 | public function loadCommonHooks( $formId, $args ) { |
| 132 | remove_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' ); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Setup hooks |
| 137 | * |
| 138 | * @param int $formId |
| 139 | * @param array $args |
| 140 | * @param Give_Donate_Form $form |
| 141 | */ |
| 142 | public function loadHooks( $formId, $args, $form ) { |
| 143 | /** |
| 144 | * Add hooks |
| 145 | */ |
| 146 | add_action( 'give_pre_form', [ $this, 'getNavigator' ], 0, 3 ); |
| 147 | add_action( 'give_post_form', [ $this, 'getFooterSection' ], 99998, 0 ); |
| 148 | add_action( 'give_donation_form_top', [ $this, 'getIntroductionSection' ], 0, 3 ); |
| 149 | add_action( 'give_donation_form_top', [ $this, 'getStartWrapperHTMLForAmountSection' ], 0 ); |
| 150 | add_action( 'give_donation_form_top', [ $this, 'getCloseWrapperHTMLForAmountSection' ], 99998 ); |
| 151 | add_action( 'give_payment_mode_top', 'give_show_register_login_fields' ); |
| 152 | add_action( 'give_payment_mode_top', [ $this, 'getStartWrapperHTMLForPaymentSection' ], 0 ); |
| 153 | add_action( 'give_donation_form_after_submit', [ $this, 'getCloseWrapperHTMLForPaymentSection' ], 999 ); |
| 154 | |
| 155 | /** |
| 156 | * Remove actions |
| 157 | */ |
| 158 | // Remove goal. |
| 159 | remove_action( 'give_pre_form', 'give_show_goal_progress', 10 ); |
| 160 | |
| 161 | // Remove intermediate continue button which appear when display style set to other then onpage. |
| 162 | remove_action( 'give_after_donation_levels', 'give_display_checkout_button', 10 ); |
| 163 | |
| 164 | // Hide title. |
| 165 | add_filter( 'give_form_title', '__return_empty_string' ); |
| 166 | |
| 167 | // Append "Donate with " to gateway labels |
| 168 | add_filter( 'give_enabled_payment_gateways', [ $this, 'modifyGatewayLabels' ] ); |
| 169 | |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Add form navigator / header |
| 174 | * |
| 175 | * @since 2.7.0 |
| 176 | * |
| 177 | * @param $formId |
| 178 | * @param $args |
| 179 | * @param $form |
| 180 | */ |
| 181 | public function getNavigator( $formId, $args, $form ) { |
| 182 | include 'sections/form-navigator.php'; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Add introduction form section |
| 187 | * |
| 188 | * @since 2.7.0 |
| 189 | * |
| 190 | * @param $formId |
| 191 | * @param $args |
| 192 | * @param $form |
| 193 | */ |
| 194 | public function getIntroductionSection( $formId, $args, $form ) { |
| 195 | include 'sections/introduction.php'; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Add form footer |
| 200 | * |
| 201 | * @since 2.7.0 |
| 202 | */ |
| 203 | public function getFooterSection() { |
| 204 | include 'sections/footer.php'; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Add checkout button |
| 209 | * |
| 210 | * @since 2.7.0 |
| 211 | */ |
| 212 | public function getCheckoutButton() { |
| 213 | |
| 214 | $label = isset( $this->templateOptions['payment_information']['checkout_label'] ) ? $this->templateOptions['payment_information']['checkout_label'] : __( 'Donate Now', 'give' ); |
| 215 | |
| 216 | return sprintf( |
| 217 | '<div class="give-submit-button-wrap give-clearfix"> |
| 218 | <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase" value="%1$s" data-before-validation-label="Donate Now"> |
| 219 | <span class="give-loading-animation"></span> |
| 220 | </div>', |
| 221 | $label |
| 222 | ); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Add wrapper and introduction text to payment information section |
| 227 | * |
| 228 | * @since 2.7.0 |
| 229 | * |
| 230 | * @param int $formId |
| 231 | */ |
| 232 | public function getStartWrapperHTMLForPaymentSection( $formId ) { |
| 233 | $headline = isset( $this->templateOptions['payment_information']['headline'] ) ? $this->templateOptions['payment_information']['headline'] : __( "Who's giving today?", 'give' ); |
| 234 | $description = isset( $this->templateOptions['payment_information']['description'] ) ? $this->templateOptions['payment_information']['description'] : __( 'We’ll never share this information with anyone.', 'give' ); |
| 235 | |
| 236 | printf( |
| 237 | '<div class="give-section payment"><div class="heading">%1$s</div><div class="subheading">%2$s</div>', |
| 238 | $headline, |
| 239 | $description |
| 240 | ); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Close wrapper for payment information section |
| 245 | * |
| 246 | * @since 2.7.0 |
| 247 | */ |
| 248 | public function getCloseWrapperHTMLForPaymentSection() { |
| 249 | echo '</div>'; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Start choose amount section |
| 254 | * |
| 255 | * @since 2.7.0 |
| 256 | */ |
| 257 | public function getStartWrapperHTMLForAmountSection() { |
| 258 | $content = isset( $this->templateOptions['payment_amount']['content'] ) && !empty($this->templateOptions['payment_amount']['content']) ? $this->templateOptions['payment_amount']['content'] : sprintf( __( 'How much would you like to donate? As a contributor to %s we make sure your goes directly to supporting our cause. Thank you for your generosity!', 'give' ), get_bloginfo('sitename') ); |
| 259 | $label = ! empty( $this->templateOptions['introduction']['donate_label'] ) ? $this->templateOptions['introduction']['donate_label'] : __( 'Donate Now', 'give' ); |
| 260 | |
| 261 | printf( |
| 262 | '<button class="give-btn advance-btn">%1$s<i class="fas fa-chevron-right"></i></button></div>', |
| 263 | $label |
| 264 | ); |
| 265 | |
| 266 | if ( ! empty( $content ) ) { |
| 267 | printf( |
| 268 | '<div class="give-section choose-amount"><p class="content">%1$s</p>', |
| 269 | $content |
| 270 | ); |
| 271 | } else { |
| 272 | echo "<div class='give-section choose-amount'>"; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Close choose amount section |
| 278 | * |
| 279 | * @since 2.7.0 |
| 280 | */ |
| 281 | public function getCloseWrapperHTMLForAmountSection() { |
| 282 | $label = isset( $this->templateOptions['payment_amount']['next_label'] ) ? $this->templateOptions['payment_amount']['next_label'] : __( 'Continue', 'give' ); |
| 283 | |
| 284 | printf( |
| 285 | '<button class="give-btn advance-btn">%1$s<i class="fas fa-chevron-right"></i></button></div>', |
| 286 | $label |
| 287 | ); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Append gateway labels with "Donate with " |
| 292 | * |
| 293 | * Modify gateways array returned give_get_enabled_payment_gateways, before printing |
| 294 | * |
| 295 | * @param array $gateways Array of enabled gateways |
| 296 | * |
| 297 | * @return array $gateways Array of modified enabled gateways |
| 298 | */ |
| 299 | public function modifyGatewayLabels( array $gateways ) { |
| 300 | foreach ( $gateways as $key => $value ) { |
| 301 | $gateways[ $key ]['checkout_label'] = sprintf( |
| 302 | __( 'Donate with %1$s', 'give' ), |
| 303 | $gateways[ $key ]['checkout_label'] |
| 304 | ); |
| 305 | } |
| 306 | return $gateways; |
| 307 | } |
| 308 | |
| 309 | } |
| 310 |