Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created March 15, 2016 08:22
Show Gist options
  • Save remcotolsma/65618c525c5ce1476ea1 to your computer and use it in GitHub Desktop.
Save remcotolsma/65618c525c5ce1476ea1 to your computer and use it in GitHub Desktop.
Pronamic iDEAL payment status redirect URL
<?php
// ...
// @see https://github.com/pronamic/wp-pronamic-ideal/blob/3.9.0/classes/Pronamic/WP/Pay/Plugin.php#L232
$url = home_url( '/' );
$url = apply_filters( 'pronamic_payment_status_redirect_url', $url, $payment );
$url = apply_filters( 'pronamic_payment_status_redirect_url_' . $payment->source, $url, $payment );
// ...
function status_redirect_url_to_pages( $url, $payment ) {
switch ( $payment->status ) {
case Pronamic_WP_Pay_Statuses::CANCELLED :
$page_id = pronamic_pay_get_page_id( 'cancel' );
break;
case Pronamic_WP_Pay_Statuses::EXPIRED :
$page_id = pronamic_pay_get_page_id( 'expired' );
break;
case Pronamic_WP_Pay_Statuses::FAILURE :
$page_id = pronamic_pay_get_page_id( 'error' );
break;
case Pronamic_WP_Pay_Statuses::OPEN :
$page_id = pronamic_pay_get_page_id( 'unknown' );
break;
case Pronamic_WP_Pay_Statuses::SUCCESS :
$page_id = pronamic_pay_get_page_id( 'completed' );
break;
default:
$page_id = pronamic_pay_get_page_id( 'unknown' );
break;
}
if ( ! empty( $page_id ) ) {
$page_url = get_permalink( $page_id );
if ( false !== $page_url ) {
$url = $page_url;
}
}
return $url;
}
add_filter( 'pronamic_payment_status_redirect_url', array( $this, 'status_redirect_url_to_pages' ), 5, 2 );
// ...
function woocommerce_status_redirect_url( $url, $payment ) {
$source_id = $payment->get_source_id();
$order = new WC_Order( (int) $source_id );
$gateway = new Pronamic_WP_Pay_Extensions_WooCommerce_IDealGateway();
switch ( $status ) {
case Pronamic_WP_Pay_Statuses::CANCELLED :
$url = $order->get_cancel_order_url();
/*
* The WooCommerce developers changed the `get_cancel_order_url` function in version 2.1.0.
* In version 2.1.0 the WooCommerce plugin uses the `wp_nonce_url` function. This WordPress
* function uses the WordPress `esc_html` function. The `esc_html` function converts specials
* characters to HTML entities. This is causing redirecting issues, so we decode these back
* with the `wp_specialchars_decode` function.
*
* @see https://github.com/WordPress/WordPress/blob/4.1/wp-includes/functions.php#L1325-L1338
* @see https://github.com/WordPress/WordPress/blob/4.1/wp-includes/formatting.php#L3144-L3167
* @see https://github.com/WordPress/WordPress/blob/4.1/wp-includes/formatting.php#L568-L647
*
* @see https://github.com/woothemes/woocommerce/blob/v2.1.0/includes/class-wc-order.php#L1112
*
* @see https://github.com/woothemes/woocommerce/blob/v2.0.20/classes/class-wc-order.php#L1115
* @see https://github.com/woothemes/woocommerce/blob/v2.0.0/woocommerce.php#L1693-L1703
*
* @see https://github.com/woothemes/woocommerce/blob/v1.6.6/classes/class-wc-order.php#L1013
* @see https://github.com/woothemes/woocommerce/blob/v1.6.6/woocommerce.php#L1630
*/
$url = wp_specialchars_decode( $url );
break;
case Pronamic_WP_Pay_Statuses::EXPIRED :
case Pronamic_WP_Pay_Statuses::FAILURE :
$url = $order->get_checkout_payment_url();
break;
case Pronamic_WP_Pay_Statuses::SUCCESS :
default :
$url = $gateway->get_return_url( $order );
break;
}
return $url;
}
add_filter( 'pronamic_payment_status_redirect_url_woocommerce', array( $this, 'status_redirect_url_to_pages' ), 10, 2 );
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment