Skip to content

Commit

Permalink
Use JS URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Mar 7, 2019
1 parent ef0a628 commit 79532fe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ public function payment_redirect( Payment $payment ) {
'pronamic-pay-adyen-checkout',
'pronamicPayAdyenCheckout',
array(
'paymentSession' => $payment_session,
'configObject' => array(
'paymentReturnUrl' => $payment->get_return_url(),
'paymentSession' => $payment_session,
'configObject' => array(
'context' => ( self::MODE_TEST === $payment->get_mode() ? 'test' : 'live' ),
),
)
Expand Down
38 changes: 32 additions & 6 deletions views/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,46 @@
</body>

<script type="text/javascript">
// Initiate the Adyen Checkout form.
<?php

/**
* Initiate the Adyen Checkout form.
*
* @link https://docs.adyen.com/developers/checkout/web-sdk
*/

?>
var checkout = chckt.checkout(
pronamicPayAdyenCheckout.paymentSession,
'#pronamic-pay-checkout',
pronamicPayAdyenCheckout.configObject
);

// Redirect once payment completes.
chckt.hooks.beforeComplete = function ( node, paymentData ) {
if ( "undefined" !== paymentData.payload ) {
window.location.href = "<?php echo esc_url_raw( $payment->get_return_url() ); ?>&payload=" + encodeURIComponent( paymentData.payload );
<?php

/**
* Redirect once payment completes.
*
* @link https://docs.adyen.com/developers/checkout/web-sdk/customization/logic#beforecomplete
* @link https://developer.mozilla.org/en-US/docs/Web/API/URL
* @link https://caniuse.com/#search=URL
* @link https://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript
* @link https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage
*/

return false;
?>
chckt.hooks.beforeComplete = function( node, paymentData ) {
if ( ! paymentData.payload ) {
return;
}

var url = new URL( pronamicPayAdyenCheckout.paymentReturnUrl );

url.searchParams.append( 'payload', paymentData.payload );

window.location.replace( url );

return false;
};
</script>
</html>

0 comments on commit 79532fe

Please sign in to comment.