/** * Conditionally adds the payment token fields to the Admin User Edit * screen, if tokenization is enabled on the gateway, and the gateway * API does not support payment token retrieval (meaning the tokens * are stored only locally) * * @see SV_WC_Payment_Gateway_Admin_User_Edit_Handler::save_user_profile_tokenization_fields() * @param SV_WC_Payment_Gateway $gateway the gateway instance * @param WP_User $user user object for the current edit page */ protected function maybe_add_user_profile_tokenization_fields($gateway, $user) { // ensure that it supports tokenization, but doesn't have a "get tokens" request, meaning that the tokens are stored and accessed locally if ($gateway->tokenization_enabled() && !$gateway->get_api()->supports_get_tokenized_payment_methods()) { $environments = $gateway->get_environments(); foreach ($environments as $environment_id => $environment_name) { // get any payment tokens $payment_tokens = $gateway->get_payment_tokens($user->ID, array('environment_id' => $environment_id)); ?> <table class="form-table"> <tr> <th style="padding-bottom: 0;"><?php echo count($environments) > 1 ? sprintf(esc_html__('%s Payment Tokens', 'woocommerce-plugin-framework'), $environment_name) : esc_html__('Payment Tokens', 'woocommerce-plugin-framework'); ?> </th> <td style="padding-bottom: 0;"> <?php if (empty($payment_tokens)) { /* translators: Payment Token as in a specific entity used to make payments, such as a specific credit card, e-check account, bank account, etc. */ echo "<p>" . esc_html__('This customer has no saved payment tokens', 'woocommerce-plugin-framework') . "</p>"; } else { ?> <ul style="margin:0;"> <?php foreach ($payment_tokens as $token) { ?> <li> <?php echo esc_html($token->get_id()); ?> (<?php /* translators: %1$s - credit card type (mastercard, visa, ...), %2$s - last 4 numbers of the card, %3$s - card expiry date */ printf('%1$s ending in %2$s expiring %3$s', $token->get_type_full(), $token->get_last_four(), $token->get_exp_month() . '/' . $token->get_exp_year()); echo $token->is_default() ? ' <strong>' . esc_html__('Default card', 'woocommerce-plugin-framework') . '</strong>' : ''; ?> ) <a href="#" class="js-sv-wc-payment-token-delete" data-payment_token="<?php echo esc_attr($token->get_id()); ?> "><?php esc_html_e('Delete', 'woocommerce-plugin-framework'); ?> </a> </li> <?php } ?> </ul> <input type="hidden" class="js-sv-wc-payment-tokens-deleted" name="wc_<?php echo $gateway->get_id(); ?> _payment_tokens_deleted_<?php echo $environment_id; ?> " value="" /> <?php } ?> </td> </tr> <tr> <?php /* translators: Payment Token as in a specific entity used to make payments, such as a specific credit card, e-check account, bank account, etc. */ ?> <th style="padding-top: 0;"><?php esc_html_e('Add a Payment Token', 'woocommerce-plugin-framework'); ?> </th> <td style="padding-top: 0;"> <input type="text" name="wc_<?php echo $gateway->get_id(); ?> _payment_token_<?php echo $environment_id; ?> " placeholder="<?php esc_attr_e('Token', 'woocommerce-plugin-framework'); ?> " style="width:145px;" /> <?php if ($gateway->supports(SV_WC_Payment_Gateway::FEATURE_CARD_TYPES)) { ?> <select name="wc_<?php echo $gateway->get_id(); ?> _payment_token_type_<?php echo $environment_id; ?> "> <option value=""><?php esc_html_e('Card Type', 'woocommerce-plugin-framework'); ?> </option> <?php foreach ($gateway->get_card_types() as $card_type) { $card_type = strtolower($card_type); ?> <option value="<?php echo esc_attr($card_type); ?> "><?php echo esc_html(SV_WC_Payment_Gateway_Helper::payment_type_to_name($card_type)); ?> </option> <?php } ?> </select> <?php } ?> <input type="text" name="wc_<?php echo $gateway->get_id(); ?> _payment_token_last_four_<?php echo $environment_id; ?> " placeholder="<?php printf(esc_attr__('Last Four', 'woocommerce-plugin-framework'), substr(date('Y') + 1, -2)); ?> " style="width:75px;" /> <input type="text" name="wc_<?php echo $gateway->get_id(); ?> _payment_token_exp_date_<?php echo $environment_id; ?> " placeholder="<?php printf(esc_attr__('Expiry Date (01/%s)', 'woocommerce-plugin-framework'), date('Y') + 1); ?> " style="width:155px;" /> <br/> <span class="description"><?php echo apply_filters('wc_payment_gateway_' . $gateway->get_id() . '_user_profile_add_token_description', '', $gateway, $user); ?> </span> </td> </tr> </table> <?php } $this->maybe_add_user_profile_tokenization_fields_js(); } }
/** * Conditionally adds the payment token fields to the Admin User Edit * screen, if tokenization is enabled on the gateway, and the gateway * API does not support payment token retrieval (meaning the tokens * are stored only locally) * * @see SV_WC_Payment_Gateway_Admin_User_Edit_Handler::save_user_profile_tokenization_fields() * @param SV_WC_Payment_Gateway $gateway the gateway instance * @param WP_User $user user object for the current edit page */ protected function maybe_add_user_profile_tokenization_fields($gateway, $user) { // ensure that it supports tokenization, but doesn't have a "get tokens" request, meaning that the tokens are stored and accessed locally if ($gateway->tokenization_enabled() && !$gateway->get_api()->supports_get_tokenized_payment_methods()) { $environments = $gateway->get_environments(); foreach ($environments as $environment_id => $environment_name) { // get any payment tokens $payment_tokens = $gateway->get_payment_tokens($user->ID, null, $environment_id); ?> <table class="form-table"> <tr> <th style="padding-bottom:0px;"><?php echo count($environments) > 1 ? sprintf(__('%s Payment Tokens', $this->text_domain), $environment_name) : __('Payment Tokens', $this->text_domain); ?> </th> <td style="padding-bottom:0px;"> <?php if (empty($payment_tokens)) { echo "<p>" . __('This customer has no saved payment tokens', $this->text_domain) . "</p>"; } else { ?> <ul style="margin:0;"> <?php foreach ($payment_tokens as $token) { ?> <li> <?php echo $token->get_token(); ?> (<?php printf('%s ending in %s expiring %s', $token->get_type_full(), $token->get_last_four(), $token->get_exp_month() . '/' . $token->get_exp_year()); echo $token->is_default() ? ' <strong>' . __('Default card', $this->text_domain) . '</strong>' : ''; ?> ) <a href="#" class="js-sv-wc-payment-token-delete" data-payment_token="<?php echo $token->get_token(); ?> "><?php _e('Delete', $this->text_domain); ?> </a> </li> <?php } ?> </ul> <input type="hidden" class="js-sv-wc-payment-tokens-deleted" name="wc_<?php echo $gateway->get_id(); ?> _payment_tokens_deleted_<?php echo $environment_id; ?> " value="" /> <?php } ?> </td> </tr> <tr> <th style="padding-top:0px;"><?php _e('Add a Payment Token', $this->text_domain); ?> </th> <td style="padding-top:0px;"> <input type="text" name="wc_<?php echo $gateway->get_id(); ?> _payment_token_<?php echo $environment_id; ?> " placeholder="<?php esc_attr_e('Token', $this->text_domain); ?> " style="width:145px;" /> <?php if ($gateway->supports(SV_WC_Payment_Gateway::FEATURE_CARD_TYPES)) { ?> <select name="wc_<?php echo $gateway->get_id(); ?> _payment_token_type_<?php echo $environment_id; ?> "> <option value=""><?php _e("Card Type", $this->text_domain); ?> </option> <?php foreach ($gateway->get_card_types() as $card_type) { $card_type = strtolower($card_type); ?> <option value="<?php echo $card_type; ?> "><?php echo SV_WC_Payment_Gateway_Payment_Token::type_to_name($card_type); ?> </option> <?php } ?> </select> <?php } ?> <input type="text" name="wc_<?php echo $gateway->get_id(); ?> _payment_token_last_four_<?php echo $environment_id; ?> " placeholder="<?php printf(esc_attr__('Last Four', $this->text_domain), substr(date('Y') + 1, -2)); ?> " style="width:75px;" /> <input type="text" name="wc_<?php echo $gateway->get_id(); ?> _payment_token_exp_date_<?php echo $environment_id; ?> " placeholder="<?php printf(esc_attr__('Expiry Date (01/%s)', $this->text_domain), date('Y') + 1); ?> " style="width:155px;" /> <br/> <span class="description"><?php echo apply_filters('wc_payment_gateway_' . $gateway->get_id() . '_user_profile_add_token_description', '', $gateway, $user); ?> </span> </td> </tr> </table> <?php } $this->maybe_add_user_profile_tokenization_fields_js(); } }