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


+ Recent posts