I have process_ipn
method that runs on init
action hook. Looks like it is fired after PayPal returns to merchant. Under this method, I could find out the payment status such as completed
, pending
, failed
from PayPal. And, save it to the database.
update_user_meta( $user_id, 'status', 'completed' );
I am redirecting back to login page from PayPal's return to merchant with added user_id
and form_id
in return url. I used the login_message
filter to override message depending upon payment status.
add_filter( 'login_message', array( $this,'custom_login_message' ) );
public function custom_login_message() {
$return = base64_decode ( $_GET['wdb_return'] );
$return = explode( '&', $return );
$return = explode( '=', $return[1] );
$user_id = isset( $return[1] ) ? $return[1] : -1;
if( 'completed' === get_user_meta( $user_id, 'status', true ) ) {
return print_notice( __( 'Payment Completed. Now login.','wdp' ) );
} else {
return print_notice( __( 'Payment Failed','wdp' ) );
}
}
The return to merchant will return to login page. The problem the status is updated too late after the login page appears. So, Payment Failed
appears if I click on return to merchant instantly after payment. If I waited a few minutes after payment and then return to merchant, It's okay.
Note that $user_id
is grabbed from return url from PayPal and is valid.
What could be the solution?
Thanks!