get_gateway()->get_id(); // payment form description add_action( "wc_{$gateway_id}_payment_form_start", array( $this, 'render_payment_form_description' ), 15 ); // saved payment methods add_action( "wc_{$gateway_id}_payment_form_start", array( $this, 'render_saved_payment_methods' ), 20 ); // fieldset start add_action( "wc_{$gateway_id}_payment_form_start", array( $this, 'render_fieldset_start' ), 30 ); // payment fields add_action( "wc_{$gateway_id}_payment_form", array( $this, 'render_payment_fields' ), 0 ); // fieldset end add_action( "wc_{$gateway_id}_payment_form_end", array( $this, 'render_fieldset_end' ), 5 ); } /** * Renders any additional billing information we need for processing on pages other than checkout * e.g. pay page, add payment method page * * @since 2.1.0 */ public function render_supplementary_billing_info() { $billing_data = array(); $billing_data_source = null; if ( is_checkout_pay_page() ) { if ( $order = wc_get_order( $this->get_gateway()->get_checkout_pay_page_order_id() ) ) { $billing_data_source = $order; } } elseif ( WC()->customer && ! is_checkout() ) { $billing_data_source = WC()->customer; } if ( $billing_data_source ) { $billing_data = array( 'billing_postcode' => $billing_data_source->get_billing_postcode() ); // 3d secure requires the full billing info $billing_data = array_merge( $billing_data, array( 'billing_first_name' => $billing_data_source->get_billing_first_name(), 'billing_last_name' => $billing_data_source->get_billing_last_name(), 'billing_email' => $billing_data_source->get_billing_email(), 'billing_country' => $billing_data_source->get_billing_country(), 'billing_address_1' => $billing_data_source->get_billing_address_1(), 'billing_address_2' => $billing_data_source->get_billing_address_2(), 'billing_state' => $billing_data_source->get_billing_state(), 'billing_city' => $billing_data_source->get_billing_city(), 'billing_phone' => $billing_data_source->get_billing_phone(), ) ); } foreach ( $billing_data as $key => $value ) { echo ''; } echo ''; } /** * Renders the payment fields. * * @since 2.0.0 */ public function render_payment_fields() { $fields = array( 'card-type', 'last-four', 'exp-month', 'exp-year', 'payment-nonce', 'payment-postcode', ); $fields[] = 'buyer-verification-token'; foreach ( $fields as $field_id ) { echo ''; } echo '
'; $this->render_supplementary_billing_info(); } /** * Gets the credit card fields. * * Overridden to add special iframe classes. * * @since 2.0.0 * * @return array */ protected function get_credit_card_fields() { $fields = parent::get_credit_card_fields(); // Square JS requires a postal code field for the form, but this is pre-filled and hidden $fields['card-postal-code'] = array( 'id' => 'wc-' . $this->get_gateway()->get_id_dasherized() . '-postal-code', 'label' => __( 'Postal code', 'woocommerce-square' ), 'class' => array( 'form-row-wide' ), 'required' => true, 'input_class' => array( 'js-sv-wc-payment-gateway-credit-card-form-input', 'js-sv-wc-payment-gateway-credit-card-form-postal-code' ), ); foreach ( array( 'card-number', 'card-expiry', 'card-csc', 'card-postal-code' ) as $field_key ) { if ( isset( $fields[ $field_key ] ) ) { // parent div classes - contains both the label and hosted field container div $fields[ $field_key ]['class'] = array_merge( $fields[ $field_key ]['class'], array( "wc-{$this->get_gateway()->get_id_dasherized()}-{$field_key}-parent", "wc-{$this->get_gateway()->get_id_dasherized()}-hosted-field-parent" ) ); // hosted field container classes - contains the iframe element $fields[ $field_key ]['input_class'] = array_merge( $fields[ $field_key ]['input_class'], array( "wc-{$this->get_gateway()->get_id_dasherized()}-hosted-field-{$field_key}", "wc-{$this->get_gateway()->get_id_dasherized()}-hosted-field" ) ); } } return $fields; } /** * Renders a payment form field. * * @since 2.0.0 * * @param array $field field to render */ public function render_payment_field( $field ) { ?>