Skip to content

Commit

Permalink
1. Declaring HPOS compatibility (#5)
Browse files Browse the repository at this point in the history
2. Renamed Classes and payment method to hyperswitch-checkout (as per slug)
3. Moved logs endpoint to hyperswitch.io domain
  • Loading branch information
vsrivatsa-edinburgh authored Feb 21, 2024
1 parent 6d4d37b commit 5da136c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
6 changes: 3 additions & 3 deletions css/hyperswitch.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ form#payment-form {
margin-bottom: 10px;
}

label[for="payment_method_hyperswitch_payment"] {
label[for="payment_method_hyperswitch_checkout"] {
display: none;
}

.payment_box.payment_method_hyperswitch_payment * {
.payment_box.payment_method_hyperswitch_checkout * {
transition: all 0.5s ease;
}

Expand All @@ -35,7 +35,7 @@ label[for="payment_method_hyperswitch_payment"] {
}
}

#payment ul li.wc_payment_method.payment_method_hyperswitch_payment label img {
#payment ul li.wc_payment_method.payment_method_hyperswitch_checkout label img {
max-width: 2em;
max-height: 1.5em;
}
44 changes: 30 additions & 14 deletions hyperswitch-payment.php → hyperswitch-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* Plugin URI: https://hyperswitch.io/
* Description: Hyperswitch checkout plugin for WooCommerce
* Author: Hyperswitch
* Author URI: https://juspay.in
* Version: 1.3.0
* Author URI: https://hyperswitch.io/
* Version: 1.4.0
* License: GPLv2 or later
*
* WC requires at least: 4.0.0
* WC tested up to: 8.0.2
* WC tested up to: 8.6.1
*
* Copyright (c) 2023 Hyperswitch
*
Expand All @@ -32,7 +32,7 @@
exit; // Exit if accessed directly
}

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

require_once __DIR__ . '/includes/hyperswitch-webhook.php';
Expand All @@ -41,6 +41,7 @@
add_action('admin_post_nopriv_hyperswitch_wc_webhook', 'hyperswitch_webhook_init', 10);
add_action('wp_ajax_nopriv_hyperswitch_create_or_update_payment_intent', 'hyperswitch_create_or_update_payment_intent', 5);
add_action('wp_ajax_hyperswitch_create_or_update_payment_intent', 'hyperswitch_create_or_update_payment_intent', 5);
add_action('before_woocommerce_init', 'hyperswitch_declare_compatibility', 5);

function hyperswitch_init_payment_class()
{
Expand All @@ -49,13 +50,13 @@ function hyperswitch_init_payment_class()
return;
}

class Hyperswitch_Payment extends WC_Payment_Gateway
class Hyperswitch_Checkout extends WC_Payment_Gateway
{

public function __construct()
{
$this->enabled = $this->get_option('enabled');
$this->id = 'hyperswitch_payment';
$this->id = 'hyperswitch_checkout';
$this->method_title = __('Hyperswitch');
$this->method_description = __('Allow customers to securely pay via Hyperswitch', 'hyperswitch-checkout');

Expand Down Expand Up @@ -93,6 +94,7 @@ public function __construct()
$this->notify_url = home_url('/wc-api/wc_hyperswitch');

add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'plugin_action_links']);

if ($this->enabled == 'yes') {
add_action('woocommerce_api_wc_hyperswitch', array($this, 'check_hyperswitch_response'));
Expand All @@ -118,7 +120,6 @@ public function __construct()
);
wp_localize_script('hyperswitch-hyperservice', 'clientdata', $client_data);
wp_enqueue_script('hyperswitch-hyperservice');

add_action("woocommerce_receipt_" . $this->id, array($this, 'receipt_page'));
add_action('woocommerce_order_actions', array($this, 'hyperswitch_add_manual_actions'));
add_action('woocommerce_order_action_wc_manual_capture_action', array($this, 'hyperswitch_process_manual_capture_action'));
Expand All @@ -128,12 +129,20 @@ public function __construct()
}
}

function plugin_action_links($links)
{
$plugin_links = [
'<a href="admin.php?page=wc-settings&tab=checkout&section=hyperswitch_checkout">' . esc_html__('Settings', 'hyperswitch-checkout') . '</a>',
];
return array_merge($plugin_links, $links);
}

function hyperswitch_thankyou($esc_html__)
{
$order_id = wc_get_order_id_by_order_key($_GET['key']);
$order = wc_get_order($order_id);
$payment_method = $order->get_payment_method();
if ($payment_method == 'hyperswitch_payment') {
if ($payment_method == 'hyperswitch_checkout') {
$payment_id = $order->get_transaction_id();
$paymentResponse = $this->retrieve_payment_intent($payment_id);
$status = $paymentResponse['status'];
Expand Down Expand Up @@ -177,7 +186,7 @@ function place_order_custom_button($button_html)
echo
'<div onclick="' .
'const paymentMethod = new URLSearchParams(jQuery(\'form.checkout\').serialize()).get(\'payment_method\');' .
'if (paymentMethod == \'hyperswitch_payment\') {' .
'if (paymentMethod == \'hyperswitch_checkout\') {' .
'event.preventDefault();' .
'handleHyperswitchAjax();' .
'}' .
Expand Down Expand Up @@ -702,13 +711,13 @@ public function post_log($event_name, $value = null, $payment_id = null)

switch ($this->environment) {
case "sandbox":
$url = "https://sandbox.juspay.io/godel/analytics";
$url = "https://sandbox.hyperswitch.io/logs/sdk";
break;
case "production":
$url = "https://api.hyperswitch.io/sdk-logs";
$url = "https://api.hyperswitch.io/logs/sdk";
break;
default:
$url = "https://sandbox.juspay.io/godel/analytics";
$url = "https://sandbox.hyperswitch.io/logs/sdk";
break;
}

Expand Down Expand Up @@ -899,7 +908,7 @@ public function check_hyperswitch_response()

function hyperswitch_add_payment_class($gateways)
{
$gateways[] = 'Hyperswitch_Payment';
$gateways[] = 'Hyperswitch_Checkout';
return $gateways;
}

Expand All @@ -924,7 +933,7 @@ function hyperswitch_create_or_update_payment_intent()
)
);
} else {
$hyperswitch = new Hyperswitch_Payment();
$hyperswitch = new Hyperswitch_Checkout();
$order_id = $_POST['order_id'];
$client_secret = $_POST['client_secret'];
if (!isset($client_secret)) {
Expand Down Expand Up @@ -956,4 +965,11 @@ function hyperswitch_create_or_update_payment_intent()
);
}
}
}

function hyperswitch_declare_compatibility()
{
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
}
4 changes: 2 additions & 2 deletions includes/hyperswitch-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
if (!defined('ABSPATH'))
exit; // Exit if accessed directly

require_once __DIR__ . '/../hyperswitch-payment.php';
require_once __DIR__ . '/../hyperswitch-checkout.php';

class Hyperswitch_Webhook
{
Expand Down Expand Up @@ -40,7 +40,7 @@ class Hyperswitch_Webhook

public function __construct()
{
$this->hyperswitch = new Hyperswitch_Payment();
$this->hyperswitch = new Hyperswitch_Checkout();

}

Expand Down
26 changes: 13 additions & 13 deletions js/hyperswitch-hyperservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function renderHyperswitchSDK(client_secret, return_url) {
var i = 0;
setInterval(function () {
jQuery(
".wc_payment_method.payment_method_hyperswitch_payment label img"
".wc_payment_method.payment_method_hyperswitch_checkout label img"
)
.css("opacity", 0)
.attr(
Expand Down Expand Up @@ -211,7 +211,7 @@ function renderHyperswitchSDK(client_secret, return_url) {

function handleHyperswitchAjax() {
jQuery(".woocommerce-error").remove();
jQuery(".payment_method_hyperswitch_payment").block(
jQuery(".payment_method_hyperswitch_checkout").block(
hyperswitchLoaderCustomSettings
);
clientSecret = jQuery("#payment-form").data("client-secret");
Expand Down Expand Up @@ -255,7 +255,7 @@ function handleHyperswitchAjax() {
});
}
} else {
jQuery(".payment_method_hyperswitch_payment").unblock();
jQuery(".payment_method_hyperswitch_checkout").unblock();
jQuery(".woocommerce").prepend(msg.messages);
jQuery([document.documentElement, document.body]).animate(
{
Expand All @@ -275,7 +275,7 @@ document.addEventListener("DOMContentLoaded", () => {
).get("payment_method");
clientSecret = jQuery("#payment-form").data("client-secret");
// Ignore when other payment method selected, default behaviour is not affected
if (paymentMethod === "hyperswitch_payment" || clientSecret == null) {
if (paymentMethod === "hyperswitch_checkout" || clientSecret == null) {
let inputChangeId = event.target.id;
if (!hyperswitchUpdatePaymentIntentLock) {
updatePaymentIntent(inputChangeId);
Expand All @@ -298,7 +298,7 @@ async function hyperswitchPaymentHandleSubmit() {
jQuery([document.documentElement, document.body]).animate(
{
scrollTop: jQuery(
".payment_box.payment_method_hyperswitch_payment"
".payment_box.payment_method_hyperswitch_checkout"
).offset().top,
},
500
Expand All @@ -309,7 +309,7 @@ async function hyperswitchPaymentHandleSubmit() {
} else {
location.href = hyperswitchReturnUrl;
}
jQuery(".payment_method_hyperswitch_payment").unblock();
jQuery(".payment_method_hyperswitch_checkout").unblock();
} else {
location.href = hyperswitchReturnUrl;
}
Expand All @@ -318,7 +318,7 @@ async function hyperswitchPaymentHandleSubmit() {
function updatePaymentIntent(inputChangeId) {
if (!hyperswitchUpdatePaymentIntentLock) {
hyperswitchUpdatePaymentIntentLock = true;
jQuery(".payment_method_hyperswitch_payment").block(
jQuery(".payment_method_hyperswitch_checkout").block(
hyperswitchLoaderCustomSettings
);
var formData = jQuery("form.checkout").serialize();
Expand All @@ -344,27 +344,27 @@ function updatePaymentIntent(inputChangeId) {
clientSecret == null ||
(msg2.payment_sheet && forceIntentUpdate)
) {
jQuery(".payment_box.payment_method_hyperswitch_payment")
jQuery(".payment_box.payment_method_hyperswitch_checkout")
.html(msg2.payment_sheet)
.addClass("payment_sheet");
}
jQuery(".payment_method_hyperswitch_payment").unblock(
jQuery(".payment_method_hyperswitch_checkout").unblock(
hyperswitchLoaderCustomSettings
);
hyperswitchUpdatePaymentIntentLock = false;
jQuery(".woocommerce-error").remove();
hyperswitchLastUpdatedFormData = formData;
},
error: function (_error) {
jQuery(".payment_method_hyperswitch_payment").unblock(
jQuery(".payment_method_hyperswitch_checkout").unblock(
hyperswitchLoaderCustomSettings
);
hyperswitchUpdatePaymentIntentLock = false;
},
});
} else {
jQuery(".woocommerce-error").remove();
jQuery(".payment_method_hyperswitch_payment").unblock(
jQuery(".payment_method_hyperswitch_checkout").unblock(
hyperswitchLoaderCustomSettings
);
hyperswitchUpdatePaymentIntentLock = false;
Expand Down Expand Up @@ -434,8 +434,8 @@ function checkMultiplePaymentMethods() {
jQuery(".wc_payment_methods.payment_methods.methods .wc_payment_method")
.length > 1
) {
if (jQuery('label[for="payment_method_hyperswitch_payment"]').length) {
jQuery('label[for="payment_method_hyperswitch_payment"]').css({
if (jQuery('label[for="payment_method_hyperswitch_checkout"]').length) {
jQuery('label[for="payment_method_hyperswitch_checkout"]').css({
display: "inline",
});
}
Expand Down
10 changes: 5 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Contributors: hyperswitch, vrishabjuspay
Tags: woocommerce, hyperswitch, payment, ecommerce, e-commerce, checkout
Requires at least: 4.0
Tested up to: 6.4.2
Stable tag: 1.3.0
Tested up to: 6.4.3
Stable tag: 1.4.0
Requires PHP: 7.0
WC requires at least: 4.0.0
WC tested up to: 8.5.1
WC tested up to: 8.6.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -149,12 +149,12 @@ Different payment methods across Payment Processors can be enabled/disabled on t
Our plugin relies on the Hyperswitch hosted service to support its functionality. Specifically, we use the following endpoints for processing payments and logs as part of our internal monitoring process:

* Sandbox Environment *
https://sandbox.juspay.io/godel/analytics - We utilize this endpoint to collect logs for internal monitoring purposes. These logs play a crucial role in analyzing the performance of our plugin, identifying potential issues, and ensuring the overall reliability of our service. The data collected through this endpoint is used exclusively for internal monitoring and improvement purposes.
https://sandbox.hyperswitch.io/logs/sdk - We utilize this endpoint to collect logs for internal monitoring purposes. These logs play a crucial role in analyzing the performance of our plugin, identifying potential issues, and ensuring the overall reliability of our service. The data collected through this endpoint is used exclusively for internal monitoring and improvement purposes.
https://sandbox.hyperswitch.io - This endpoint is employed for securely processing payments. It ensures a seamless and efficient payment experience for our users. The use of this endpoint is exclusively dedicated to handling payment transactions and related processes.
https://beta.hyperswitch.io/v1/HyperLoader.js - This endpoint is utilized for loading the script required to inject the payment sheet. This process enables the seamless integration of the payment sheet into our plugin, contributing to a user-friendly and efficient payment interface.

* Production Environment *
https://api.hyperswitch.io/sdk-logs - We utilize this endpoint to collect logs for internal monitoring purposes. These logs play a crucial role in analyzing the performance of our plugin, identifying potential issues, and ensuring the overall reliability of our service. The data collected through this endpoint is used exclusively for internal monitoring and improvement purposes.
https://api.hyperswitch.io/logs/sdk - We utilize this endpoint to collect logs for internal monitoring purposes. These logs play a crucial role in analyzing the performance of our plugin, identifying potential issues, and ensuring the overall reliability of our service. The data collected through this endpoint is used exclusively for internal monitoring and improvement purposes.
https://api.hyperswitch.io - This endpoint is employed for securely processing payments. It ensures a seamless and efficient payment experience for our users. The use of this endpoint is exclusively dedicated to handling payment transactions and related processes.
https://checkout.hyperswitch.io/v0/HyperLoader.js - This endpoint is utilized for loading the script required to inject the payment sheet. This process enables the seamless integration of the payment sheet into our plugin, contributing to a user-friendly and efficient payment interface.

Expand Down

0 comments on commit 5da136c

Please sign in to comment.