Skip to content

Commit

Permalink
Compatibility with GooglePay and Paypal - one click wallet payment me…
Browse files Browse the repository at this point in the history
…thods, handled in the oneClickConfirmTriggered event (#6)
  • Loading branch information
vsrivatsa-edinburgh authored Feb 29, 2024
1 parent 5da136c commit c2af4a8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
4 changes: 2 additions & 2 deletions hyperswitch-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Hyperswitch checkout plugin for WooCommerce
* Author: Hyperswitch
* Author URI: https://hyperswitch.io/
* Version: 1.4.0
* Version: 1.5.0
* License: GPLv2 or later
*
* WC requires at least: 4.0.0
Expand All @@ -32,7 +32,7 @@
exit; // Exit if accessed directly
}

define('HYPERSWITCH_CHECKOUT_PLUGIN_VERSION', '1.4.0');
define('HYPERSWITCH_CHECKOUT_PLUGIN_VERSION', '1.5.0');
define('HYPERSWITCH_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));

require_once __DIR__ . '/includes/hyperswitch-webhook.php';
Expand Down
70 changes: 44 additions & 26 deletions js/hyperswitch-hyperservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,25 @@ function renderHyperswitchSDK(client_secret, return_url) {
layout: layout1,
wallets: {
walletReturnUrl: hyperswitchReturnUrl,
style: style,
style,
},
sdkHandleConfirmPayment: false,
disableSaveCards: disableSaveCards,
disableSaveCards,
branding: "never",
showCardFormByDefault: showCardFormByDefault,
showCardFormByDefault,
sdkHandleOneClickConfirmPayment: false,
};
hyperswitchUnifiedCheckout = hyperswitchWidgets.create(
"payment",
hyperswitchUnifiedCheckoutOptions
);
hyperswitchUnifiedCheckout.mount("#unified-checkout");
hyperswitchUnifiedCheckout.on("oneClickConfirmTriggered", function (event) {
handleHyperswitchAjax(true);
});
}

function handleHyperswitchAjax() {
function handleHyperswitchAjax(isOneClickPaymentMethod = false) {
jQuery(".woocommerce-error").remove();
jQuery(".payment_method_hyperswitch_checkout").block(
hyperswitchLoaderCustomSettings
Expand Down Expand Up @@ -250,11 +254,12 @@ function handleHyperswitchAjax() {
url: "/wp-admin/admin-ajax.php",
data: payment_intent_data,
success: function (_msg2) {
hyperswitchPaymentHandleSubmit();
hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, true);
},
});
}
} else {
hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, false);
jQuery(".payment_method_hyperswitch_checkout").unblock();
jQuery(".woocommerce").prepend(msg.messages);
jQuery([document.documentElement, document.body]).animate(
Expand Down Expand Up @@ -284,34 +289,47 @@ document.addEventListener("DOMContentLoaded", () => {
});
});

async function hyperswitchPaymentHandleSubmit() {
const { error } = await hyper.confirmPayment({
widgets: hyperswitchWidgets,
confirmParams: {
return_url: hyperswitchReturnUrl,
},
redirect: "if_required",
});
if (error) {
if (error.type) {
if (error.type == "validation_error") {
jQuery([document.documentElement, document.body]).animate(
{
scrollTop: jQuery(
".payment_box.payment_method_hyperswitch_checkout"
).offset().top,
async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) {
if (result || isOneClickPaymentMethod) {
if (!isOneClickPaymentMethod && result) {
const { error } = await hyper.confirmPayment({
confirmParams: {
return_url: hyperswitchReturnUrl,
},
redirect: "if_required",
});
} else {
const { error } = await hyper.confirmOneClickPayment(
{
confirmParams: {
return_url: hyperswitchReturnUrl,
},
500
);
redirect: "if_required",
},
result
);
}
if (error) {
if (error.type) {
if (error.type == "validation_error") {
jQuery([document.documentElement, document.body]).animate(
{
scrollTop: jQuery(
".payment_box.payment_method_hyperswitch_checkout"
).offset().top,
},
500
);
} else {
location.href = hyperswitchReturnUrl;
}
} else {
location.href = hyperswitchReturnUrl;
}
jQuery(".payment_method_hyperswitch_checkout").unblock();
} else {
location.href = hyperswitchReturnUrl;
}
jQuery(".payment_method_hyperswitch_checkout").unblock();
} else {
location.href = hyperswitchReturnUrl;
}
}

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: hyperswitch, vrishabjuspay
Tags: woocommerce, hyperswitch, payment, ecommerce, e-commerce, checkout
Requires at least: 4.0
Tested up to: 6.4.3
Stable tag: 1.4.0
Stable tag: 1.5.0
Requires PHP: 7.0
WC requires at least: 4.0.0
WC tested up to: 8.6.1
Expand Down

0 comments on commit c2af4a8

Please sign in to comment.