Skip to content

Commit

Permalink
Merge pull request #61 from razorpay/support-offsite-redirect
Browse files Browse the repository at this point in the history
PO-166 added support for offsite redirect
  • Loading branch information
abdulwahidsharief authored Aug 13, 2024
2 parents e64b0a5 + 05298fa commit 1fa9ba4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions frontend/checkout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ jQuery(document).ready(function($){
$('.modal-container').addClass('shown');
}

if (typeof displayRzpModal !== 'undefined') {
showModal(displayRzpModal);
}

function hideModal() {
$('html, body').css('overflow', '');
$('.modal-container').removeClass('shown');
Expand Down Expand Up @@ -122,7 +126,9 @@ jQuery(document).ready(function($){
data: form_data,
type: 'POST',
success: function(response){
showModal(response);
modalScript = response.replace(/<\/?script.*?>/gi, '');
eval(modalScript);
showModal(displayRzpModal);
}
});
};
Expand All @@ -135,7 +141,7 @@ jQuery(document).ready(function($){
}
};

order.callback_url = "#redirectUrl#?rzp_QP_form_submit=1";
order.callback_url = location.protocol + '//' + location.host + location.pathname + "?rzp_QP_form_submit=1";
// After order is created, open checkout
openCheckout(order);
}
Expand Down
6 changes: 5 additions & 1 deletion razorpay-quick-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function dummy()

function wordpressRazorpayInit()
{
header('Set-Cookie: ' . session_name() . '=' . session_id() . '; HttpOnly; SameSite=None; Secure; HttpOnly;');
add_action('admin_enqueue_scripts', 'enqueueScripts' );//admin-page
add_action('wp_enqueue_scripts', 'enqueueScripts' );//front-end
add_action('login_enqueue_scripts', 'enqueueScripts' );//login page
Expand Down Expand Up @@ -298,6 +299,9 @@ function wpCheckRazorpayResponse()
$this->message = 'Thank you for shopping with us. However, the payment failed.\n' . $error ;
}

// Appending script tags to handle if output is not returned to ajax response
$this->message = "<script>var displayRzpModal = '" . $this->message . "';</script>";

echo ($this->message);
}
session_write_close();
Expand Down Expand Up @@ -325,7 +329,7 @@ function getCurrencyObject()

protected function getPostAttributes()
{
if (isset($_REQUEST['rzp_QP_form_submit']))
if (isset($_REQUEST['rzp_QP_form_submit']) and isset($_REQUEST['razorpay_payment_id']))
{
return array(
'razorpay_payment_id' => sanitize_text_field($_POST['razorpay_payment_id']),
Expand Down

0 comments on commit 1fa9ba4

Please sign in to comment.