Skip to content

Commit

Permalink
Merge pull request #137 from pooliestudios/paypal-redirect-fix
Browse files Browse the repository at this point in the history
paypal redirect fix
  • Loading branch information
janteuber authored Apr 25, 2023
2 parents 8a3ad74 + 0c04431 commit 90541c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Payone/Gateway/RedirectGatewayBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function process_redirect( $order_id, $transaction_class ) {
$order->save_meta_data();
$order->save();

if ( WC()->session ) {
WC()->session->set( 'order_key', $order->get_order_key() );
}

// Perform the redirect if we need to
if ( $response->is_redirect() ) {
return [
Expand Down
14 changes: 13 additions & 1 deletion src/Payone/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,23 @@ private function process_callback_after_redirect() {
$gateway = self::get_gateway_for_order( $order );

$logged_in_user_id = wp_get_current_user()->ID;
$session_order_key = null;
if ( WC()->session ) {
$session_order_key = WC()->session->get( 'order_key' );
}

$redirect_allowed = false;
if ( $logged_in_user_id ) {
$order_user = $order->get_user();
if ( $order_user && $order->get_user()->ID === $logged_in_user_id ) {
return $gateway->process_payment( $order_id );
$redirect_allowed = true;
}
} elseif ( $session_order_key && $session_order_key === $order->get_order_key() ) {
$redirect_allowed = true;
}

if ( $redirect_allowed ) {
return $gateway->process_payment( $order_id );
}

wp_redirect( wc_get_checkout_url() );
Expand Down

0 comments on commit 90541c7

Please sign in to comment.