728x90

michaelopatskyi commented on 17 Jan 2017  

Notice: WC_Shortcode_Checkout->output was called with an argument that is deprecated since version 2.1! "order" is no longer used to pass an order ID. Use the order-pay or order-received endpoint instead. in /var/www/dev/tofa/wp-includes/functions.php on line 3975
Order Number: 46 Date: January 16, 2017 Total: $47.40 Payment Method: Tarjeta de crédito o débito
Realiza la compra presionando Pagar
Si deseas cambiar de medio de pago presiona Cancelar

Wordpress Plugin

@marti1125 marti1125 added the question label on 17 Jan 2017

@michaelopatskyi

michaelopatskyi commented on 19 Jan 2017  

thank You for an answer


728x90

Wordpress 4.6.3
WooCommerce 2.6.8

I'm trying to add a custom payment system. I have read the documentation ( https://docs.woocommerce.com/document/payment-gateway-api/ ) and do everything as it says. I have created a plugin, class and all the necessary options. The problem arises in function process_payment -- there is no redirect, but Error processing checkout.

function process_payment( $order_id ) {
    global $woocommerce;
    $order = new WC_Order( $order_id );
    $order->update_status('on-hold', __( 'Awaiting cheque payment', 'woocommerce' ));
    $order->reduce_order_stock();
    $woocommerce->cart->empty_cart();

    /*
    * API-function of my bank
    * It sends the details of the order to the bank by CURL.
    * If the data are processed, return URL of Payment page at bank's website.
    * It works correctly.
    */
    $deal = $this->bank_do_deal( $order_id );

    if ( $deal['success'] === true ) {
        $redirect = $deal['url']; // example: https://mybank.com/payment/...
    } else {
        wc_add_notice( 'Payment error: ' . $deal['error'], 'error' );
        return;
    }

    return array(
        'result' => 'success',
        'redirect' => $redirect // ???
    );
}

On Checkaut Page of my site, after submitting the form, I get the following:
checkout_err

What am I doing wrong?

@wep6ak

wep6ak commented on 6 Feb 2017

Perhaps your variable $redirect does not contain a URL string, but contains an array [0] => '...url...'
Try to refer to the zero element of the variable $redirect[0] , or to equate it to a string type (string)$redirect.

@mikejolley
Owner

mikejolley commented on 6 Feb 2017

Redirect should be a string yes, not an array.

@mikejolley mikejolley closed this on 6 Feb 2017


728x90

The WooCommerce API allows plugins make a callback to a special URL that will then load the specified class (if it exists) and run an action. This is also useful for gateways that are not initialized.

You can view the WC_API class in our docs.

Callback URL

To trigger the WooCommerce API, you need to use a special URL. Before WooCommerce 2.0, you could use:

http://yoursite.com/?wc-api=CALLBACK

In WooCommerce 2.0+,  you can still use that or use our endpoint:

http://yoursite.com/wc-api/CALLBACK/

When this URL is called, WooCommerce:

  1. Initializes the CALLBACK class, if it exists
  2. Triggers an action based on the callback: woocommerce_api_callback. Note: CALLBACK will be sanitized and lower case.
  3. Exit WordPress.

Hooking into the callback

Add an action to hook into the callback hook. For example:

add_action( 'woocommerce_api_callback', 'callback_handler' );

WooCommerce will exit after that action, but you can still redirect the user elsewhere from your handler if you wish.

728x90

add_query_arg()

Retrieves a modified URL query string.


Description Description

You can rebuild the URL and append query variables to the URL query by using this function. There are two ways to use this function; either a single key and value, or an associative array.

Using a single key and value:

add_query_arg( 'key', 'value', 'http://example.com' );

Using an associative array:

add_query_arg( array(
    'key1' => 'value1',
    'key2' => 'value2',
), 'http://example.com' );

Omitting the URL from either use results in the current URL being used (the value of $_SERVER['REQUEST_URI']).

Values are expected to be encoded appropriately with urlencode() or rawurlencode().

Setting any query variable’s value to boolean false removes the key (see remove_query_arg()).

Important: The return value of add_query_arg() is not escaped by default. Output should be late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting (XSS) attacks.


Parameters Parameters

$key

(string|array) (Required) Either a query variable key, or an associative array of query variables.

$value

(string) (Optional) Either a query variable value, or a URL to act upon.

$url

(string) (Optional) A URL to act upon.


Top ↑

Return Return

(string) New URL query string (unescaped).


Top ↑

Source Source

File: wp-includes/functions.php

776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
function add_query_arg() {
    $args = func_get_args();
    if ( is_array( $args[0] ) ) {
        if ( count( $args ) < 2 || false === $args[1] )
            $uri = $_SERVER['REQUEST_URI'];
        else
            $uri = $args[1];
    } else {
        if ( count( $args ) < 3 || false === $args[2] )
            $uri = $_SERVER['REQUEST_URI'];
        else
            $uri = $args[2];
    }
 
    if ( $frag = strstr( $uri, '#' ) )
        $uri = substr( $uri, 0, -strlen( $frag ) );
    else
        $frag = '';
 
    if ( 0 === stripos( $uri, 'http://' ) ) {
        $protocol = 'http://';
        $uri = substr( $uri, 7 );
    } elseif ( 0 === stripos( $uri, 'https://' ) ) {
        $protocol = 'https://';
        $uri = substr( $uri, 8 );
    } else {
        $protocol = '';
    }
 
    if ( strpos( $uri, '?' ) !== false ) {
        list( $base, $query ) = explode( '?', $uri, 2 );
        $base .= '?';
    } elseif ( $protocol || strpos( $uri, '=' ) === false ) {
        $base = $uri . '?';
        $query = '';
    } else {
        $base = '';
        $query = $uri;
    }
 
    wp_parse_str( $query, $qs );
    $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
    if ( is_array( $args[0] ) ) {
        foreach ( $args[0] as $k => $v ) {
            $qs[ $k ] = $v;
        }
    } else {
        $qs[ $args[0] ] = $args[1];
    }
 
    foreach ( $qs as $k => $v ) {
        if ( $v === false )
            unset( $qs[$k] );
    }
 
    $ret = build_query( $qs );
    $ret = trim( $ret, '?' );
    $ret = preg_replace( '#=(&|$)#', '$1', $ret );
    $ret = $protocol . $base . $ret . $frag;
    $ret = rtrim( $ret, '?' );
    return $ret;
}

Top ↑

Changelog Changelog

Changelog
VersionDescription
1.5.0Introduced.

Top ↑

More Information More Information

Usage Usage

1
2
3
4
5
6
7
8
9
10
11
12
// Parameters as separate arguments
add_query_arg( $param1, $param2, $old_query_or_uri );
 
// Parameters as array of key => value pairs
add_query_arg(
    array(
        'key1' => 'value1',
        'key2' => 'value2',
        ...
    ),
    $old_query_or_uri
);


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by Codex — 

    Assuming we’re at the WordPress URL “http://blog.example.com/client/?s=word”… Note the use of esc_url() before outputting the link. This is necessary because this function does not escape URLs and if output without escaping, would make the page vulnerable to XSS scripting.

    1
    2
    3
    4
    5
    6
    // This would output '/client/?s=word&foo=bar'
    echo esc_url( add_query_arg( 'foo', 'bar' ) );
     
    // This would output '/client/?s=word&foo=bar&baz=tiny'
    $arr_params = array( 'foo' => 'bar', 'baz' => 'tiny' );
    echo esc_url( add_query_arg( $arr_params ) );
  2. Skip to note content
    Contributed by Codex — 

    Since get_permalink() returns a full URL, you could use that when you want to add variables to a post’s page.

    1
    2
    3
    4
    5
    /*
     * This would output whatever the URL to post ID 9 is, with 'hello=there'
     * appended with either ? or &, depending on what's needed.
     */
    echo esc_url( add_query_arg( 'hello', 'there', get_permalink( 9 ) ) );
  3. Skip to note content
    Contributed by Codex — 

    More often than not you’ll probably find yourself creating URLs using the following method within the page you’re currently on. In these cases you can use the URL you want to affect as the last parameter. The use of esc_url() is not required here, because the value is known to be safe.

    1
    2
    echo esc_url( add_query_arg( 'hello', 'world', 'http://blog.example.com/2009/04/16/' ) );

You must log in before being able to contribute a note or feedback.


+ Recent posts