コード例 #1
0
    /**
     * Template function to render the "My Cards" section
     *
     * @since 2.0
     */
    function woocommerce_braintree_my_cards($gateway)
    {
        global $wc_braintree;
        if (!$gateway->is_available()) {
            return;
        }
        // process payment method actions
        if (!empty($_GET['braintree-cc-token']) && !empty($_GET['braintree-action']) && !empty($_GET['_wpnonce'])) {
            // security check
            if (false === wp_verify_nonce($_GET['_wpnonce'], 'braintree-security')) {
                wp_die(__('There was an error with your request, please try again.', WC_Braintree::TEXT_DOMAIN));
            }
            $braintree_cc_token = sanitize_text_field($_GET['braintree-cc-token']);
            // handle deletion
            if ('delete' === $_GET['braintree-action']) {
                $gateway->delete_saved_card($braintree_cc_token);
            }
            // handle default change
            if ('set-default' === $_GET['braintree-action']) {
                $gateway->set_default_saved_card($braintree_cc_token);
            }
        }
        // get available saved payment methods
        $cards = $gateway->get_saved_cards(get_current_user_id());
        SV_WC_Plugin_Compatibility::wc_get_template('myaccount/braintree-my-cards.php', array('cards' => $cards, 'gateway' => $gateway), '', $wc_braintree->get_plugin_path() . '/templates/');
        // Add confirm javascript when deleting cards
        ob_start();
        ?>
			$( 'a.braintree-delete-saved-card' ).click( function ( e ) {
				if ( ! confirm( '<?php 
        _e('Are you sure you want to delete this card?', WC_Braintree::TEXT_DOMAIN);
        ?>
' ) ) {
					e.preventDefault();
				}
			} );
		<?php 
        SV_WC_Plugin_Compatibility::wc_enqueue_js(ob_get_clean());
    }
コード例 #2
0
        /**
         * Render the javascript to handle the notice "dismiss" functionality
         *
         * @since 2.0
         */
        public function render_admin_dismissible_notice_js()
        {
            // if a notice was rendered, add the javascript code to handle the notice dismiss action
            if (!$this->dismissible_notice_rendered) {
                return;
            }
            ob_start();
            ?>
		// hide notice
		$( 'a.js-wc-plugin-framework-<?php 
            echo $this->get_id();
            ?>
-message-dismiss' ).click( function() {

			$.get(
				ajaxurl,
				{
					action: 'wc_plugin_framework_<?php 
            echo $this->get_id();
            ?>
_dismiss_message',
					messageid: $( this ).data( 'message-id' )
				}
			);

			$( this ).closest( 'div.error' ).fadeOut();

			return false;
		} );
		<?php 
            $javascript = ob_get_clean();
            SV_WC_Plugin_Compatibility::wc_enqueue_js($javascript);
        }
コード例 #3
0
        /**
         * Render the admin settings javascript which will live-update the sample
         * order number for improved feedback when configuring
         *
         * @since 1.3
         */
        public function admin_settings_js()
        {
            // our options are on the general tab
            if (isset($_REQUEST['tab']) && $_REQUEST['tab'] != 'general') {
                return;
            }
            ob_start();
            ?>
		var free_order_number_start = <?php 
            echo $this->get_free_order_number_start();
            ?>
;
		$('#woocommerce_order_number_skip_free_orders').change(function() {
			if ( ! $( this ).is( ':checked' ) ) {
				$( '#woocommerce_free_order_number_prefix' ).closest( 'tr' ).hide();
			} else {
				$( '#woocommerce_free_order_number_prefix' ).closest( 'tr' ).show();
			}
		}).change();

		$( '#woocommerce_free_order_number_prefix' ).on( 'keyup change input', function() {
			$( '#sample_free_order_number' ).text( formatOrderNumber( free_order_number_start, $( this ).val() ) );
		} );

		$('#woocommerce_order_number_start, #woocommerce_order_number_prefix, #woocommerce_order_number_suffix').on('keyup change input',
			function() {
				$( '#sample_order_number' ).text( formatOrderNumber( $( '#woocommerce_order_number_start' ).val(), $( '#woocommerce_order_number_prefix' ).val(), $( '#woocommerce_order_number_suffix' ).val() ) );
			}
		);
		function formatOrderNumber( orderNumber, orderNumberPrefix, orderNumberSuffix ) {

			orderNumberPrefix = ( typeof orderNumberPrefix === "undefined" ) ? "" : orderNumberPrefix;
			orderNumberSuffix = ( typeof orderNumberSuffix === "undefined" ) ? "" : orderNumberSuffix;

			var formatted = orderNumberPrefix + orderNumber + orderNumberSuffix;

			var d = new Date();
			if ( formatted.indexOf( '{D}' )    > -1) formatted = formatted.replace( '{D}',    d.getDate() );
			if ( formatted.indexOf( '{DD}' )   > -1) formatted = formatted.replace( '{DD}',   leftPad( d.getDate().toString(), 2, '0' ) );
			if ( formatted.indexOf( '{M}' )    > -1) formatted = formatted.replace( '{M}',    d.getMonth() + 1 );
			if ( formatted.indexOf( '{MM}' )   > -1) formatted = formatted.replace( '{MM}',   leftPad( ( d.getMonth() + 1 ).toString(), 2, '0' ) );
			if ( formatted.indexOf( '{YY}' )   > -1) formatted = formatted.replace( '{YY}',   ( d.getFullYear() ).toString().substr( 2 ) );
			if ( formatted.indexOf( '{YYYY}' ) > -1) formatted = formatted.replace( '{YYYY}', d.getFullYear() );
			if ( formatted.indexOf( '{H}' )  > -1) formatted = formatted.replace( '{H}',  d.getHours() );
			if ( formatted.indexOf( '{HH}' ) > -1) formatted = formatted.replace( '{HH}', leftPad( d.getHours().toString(), 2, '0' ) );
			if ( formatted.indexOf( '{N}' )  > -1) formatted = formatted.replace( '{N}',  d.getMinutes() );
			if ( formatted.indexOf( '{S}' )  > -1) formatted = formatted.replace( '{S}',  d.getSeconds() );

			return formatted;
		}
		function leftPad( value, count, char ) {
			while ( value.length < count ) {
				value = char + value;
			}
			return value;
		}
		<?php 
            $javascript = ob_get_clean();
            SV_WC_Plugin_Compatibility::wc_enqueue_js($javascript);
        }
コード例 #4
0
        /**
         * Generates the POST pay form.  Some inline javascript will attempt to
         * auto-submit this pay form, so as to make the checkout process as
         * seamless as possile
         *
         * @since 2.1
         * @param int $order_id the order identifier
         * @return string payment page POST form
         */
        public function generate_pay_form($order_id)
        {
            // setup the order object
            $order = $this->get_order($order_id);
            $request_params = $this->get_hosted_pay_page_params($order);
            // standardized request data, for logging purposes
            $request = array('method' => 'POST', 'uri' => $this->get_hosted_pay_page_url($order), 'body' => json_encode($request_params));
            // log the request
            $this->log_hosted_pay_page_request($request);
            // attempt to automatically submit the form and bring them to the payza paymen site
            SV_WC_Plugin_Compatibility::wc_enqueue_js('
			$( "body" ).block( {
					message: "<img src=\\"' . esc_url(SV_WC_Plugin_Compatibility::WC()->plugin_url()) . '/assets/images/ajax-loader.gif\\" alt=\\"Redirecting&hellip;\\" style=\\"float:left; margin-right: 10px;\\" />' . __('Thank you for your order. We are now redirecting you to complete payment.', $this->text_domain) . '",
					overlayCSS: {
						background: "#fff",
						opacity: 0.6
					},
					css: {
						padding:         20,
						textAlign:       "center",
						color:           "#555",
						border:          "3px solid #aaa",
						backgroundColor: "#fff",
						cursor:          "wait",
						lineHeight:      "32px"
					}
				} );

			$( "#submit_' . $this->get_id() . '_payment_form" ).click();
		');
            $request_arg_fields = array();
            foreach ($request_params as $key => $value) {
                $request_arg_fields[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
            }
            return '<form action="' . esc_url($this->get_hosted_pay_page_url($order)) . '" method="post">' . implode('', $request_arg_fields) . '<input type="submit" class="button-alt" id="submit_' . $this->get_id() . '_payment_form" value="' . __('Pay Now', $this->text_domain) . '" />' . '<a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . __('Cancel Order', $this->text_domain) . '</a>' . '</form>';
        }
コード例 #5
0
        /**
         * Display settings page with some additional javascript for hiding conditional fields
         *
         * @since 1.0
         * @see WC_Settings_API::admin_options()
         */
        public function admin_options()
        {
            parent::admin_options();
            ?>
		<style type="text/css">.nowrap { white-space: nowrap; }</style>
		<?php 
            // if there's more than one environment include the environment settings switcher code
            if (count($this->get_environments()) > 1) {
                // add inline javascript
                ob_start();
                ?>
				$( '#woocommerce_<?php 
                echo $this->get_id();
                ?>
_environment' ).change( function() {

					// inherit settings from other gateway?
					var inheritSettings = $( '#woocommerce_<?php 
                echo $this->get_id();
                ?>
_inherit_settings' ).is( ':checked' );

					var environment = $( this ).val();

					// hide all environment-dependant fields
					$( '.environment-field' ).closest( 'tr' ).hide();

					// show the currently configured environment fields that are not also being hidden as any shared settings
					var $environmentFields = $( '.' + environment + '-field' );
					if ( inheritSettings ) {
						$environmentFields = $environmentFields.not( '.shared-settings-field' );
					}

					$environmentFields.not( '.hidden' ).closest( 'tr' ).show();

				} ).change();
			<?php 
                SV_WC_Plugin_Compatibility::wc_enqueue_js(ob_get_clean());
            }
            if (!empty($this->shared_settings)) {
                // add inline javascript to show/hide any shared settings fields as needed
                ob_start();
                ?>
				$( '#woocommerce_<?php 
                echo $this->get_id();
                ?>
_inherit_settings' ).change( function() {

					var enabled = $( this ).is( ':checked' );

					if ( enabled ) {
						$( '.shared-settings-field' ).closest( 'tr' ).hide();
					} else {
						// show the fields
						$( '.shared-settings-field' ).closest( 'tr' ).show();

						// hide any that may not be available for the currently selected environment
						$( '#woocommerce_<?php 
                echo $this->get_id();
                ?>
_environment' ).change();
					}

				} ).change();
			<?php 
                SV_WC_Plugin_Compatibility::wc_enqueue_js(ob_get_clean());
            }
        }