/** * Multipurpose tag used to generate a payment method selection menu for one or more payment options * * @api `shopp('checkout.payoptions')` * @since 1.2 * * @param string $result The output * @param array $options The options * - **default**: The default payment option to auto-select for the shopper * - **exclude**: Exclude a payment option from the menu * - **type**: `menu` (menu,list,hidden) Type of payment options selector to generate * - **mode**: (loop) Change the behavior to loop the payment options for use with `shopp('checkout.payoption')` * - **logos**: A space-separated list of payment logo classes to include * - **autocomplete**: (on, off) Specifies whether an `<input>` element should have autocomplete enabled * - **accesskey**: Specifies a shortcut key to activate/focus an element. Linux/Windows: `[Alt]`+`accesskey`, Mac: `[Ctrl]``[Opt]`+`accesskey` * - **alt**: Specifies an alternate text for images (only for type="image") * - **checked**: Specifies that an `<input>` element should be pre-selected when the page loads (for type="checkbox" or type="radio") * - **class**: The class attribute specifies one or more class-names for an element * - **disabled**: Specifies that an `<input>` element should be disabled * - **format**: Specifies special field formatting class names for JS validation * - **minlength**: Sets a minimum length for the field enforced by JS validation * - **maxlength**: Specifies the maximum number of characters allowed in an `<input>` element * - **placeholder**: Specifies a short hint that describes the expected value of an `<input>` element * - **readonly**: Specifies that an input field is read-only * - **required**: Adds a class that specified an input field must be filled out before submitting the form, enforced by JS * - **size**: Specifies the width, in characters, of an `<input>` element * - **src**: Specifies the URL of the image to use as a submit button (only for type="image") * - **tabindex**: Specifies the tabbing order of an element * - **cols**: Specifies the visible width of a `<textarea>` * - **rows**: Specifies the visible number of lines in a `<textarea>` * - **title**: Specifies extra information about an element * - **value**: Specifies the value of an `<input>` element * @param ShoppOrder $O The working object * @return void **/ public static function payoptions($result, $options, $O) { $select_attrs = array('title', 'class', 'disabled', 'required', 'size', 'tabindex', 'accesskey'); if ($O->Cart->orderisfree()) { return false; } $Payments = $O->Payments; $payment_methods = apply_filters('shopp_payment_methods', $Payments->count()); if ($payment_methods <= 1) { return false; } // Skip if only one gateway is active $defaults = array('default' => null, 'exclude' => false, 'type' => 'menu', 'mode' => false, 'logos' => false); $options = array_merge($defaults, $options); extract($options, EXTR_SKIP); unset($options['type']); if ($mode === 'loop') { if (!isset($O->_pay_loop)) { $Payments->rewind(); $O->_pay_loop = true; } else { $Payments->next(); } if (false !== $Payments->current()) { return true; } else { unset($O->_pay_loop); return false; } } $excludes = array_map('sanitize_title_with_dashes', explode(',', $exclude)); $payoptions = $Payments->keys(); $payoptions = array_diff($payoptions, $excludes); if (!$Payments->userset()) { $Payments->selected($default); } $SelectedPayment = $Payments->selected(); $output = ''; switch ($type) { case "list": $output .= '<span><ul>'; if ($logos) { // Add payment logos $logos = explode(' ', strtolower($logos)); $logoclasses = array('shoppui-cards'); foreach ($logos as $ls) { if (in_array($ls, array('icon', 'small', 'big', 'huge', 'shadow'))) { $logoclasses[] = $ls; } } $logoclasses = join(' ', $logoclasses); } foreach ($payoptions as $value) { if (in_array($value, $excludes)) { continue; } $Payoption = $Payments->get($value); $options['value'] = $value; $options['checked'] = $SelectedPayment->slug == $Payoption->slug ? true : false; if (false === $options['checked']) { unset($options['checked']); } $label = $Payoption->label; if ($logos) { $label = ' <span class="' . esc_attr($logoclasses) . '">'; if (empty($Payoption->cards)) { $label .= '<span class="shoppui-' . esc_attr($Payoption->slug) . '">' . esc_html($Payoption->label) . '</span> '; } else { foreach ($Payoption->cards as $card) { $label .= '<span class="shoppui-' . esc_attr($card) . '">' . esc_html($card) . '</span>'; } } $label .= '</span>'; } $output .= '<li><label><input type="radio" name="paymethod" ' . Shopp::inputattrs($options) . ' /> ' . $label . '</label></li>'; } $output .= '</ul></span>'; break; case "hidden": if (!isset($options['value']) && $default) { $options['value'] = $O->paymethod; } $output .= '<input type="hidden" name="paymethod"' . Shopp::inputattrs($options) . ' />'; break; default: $output .= '<select name="paymethod" ' . Shopp::inputattrs($options, $select_attrs) . '>'; foreach ($payoptions as $value) { if (in_array($value, $excludes)) { continue; } $Payoption = $Payments->get($value); $selected = $SelectedPayment->slug == $Payoption->slug ? ' selected="selected"' : ''; $output .= '<option value="' . $value . '"' . $selected . '>' . $Payoption->label . '</option>'; } $output .= '</select>'; break; } return $output; }
/** * @deprecated Use Shopp::inputattrs() **/ function inputattrs($options, $allowed = array()) { return Shopp::inputattrs($options, $allowed); }