From 933fbc7260de4fc763373e18b3bcb520c69abc3d Mon Sep 17 00:00:00 2001 From: whiteagle3k Date: Mon, 13 May 2024 12:06:08 +0100 Subject: [PATCH] Feat/profile id compatibility (#14) * card redirect * Fixes for sandbox * changed the deprecated function * Implements profile ID handling * Feat: profile_id setting for multiple busness profiles. --- assets/images/card_redirect.svg | 8 ++++++++ hyperswitch-checkout.php | 19 ++++++++++++++----- js/hyperswitch-hyperservice.js | 9 ++++++--- readme.txt | 2 +- 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 assets/images/card_redirect.svg diff --git a/assets/images/card_redirect.svg b/assets/images/card_redirect.svg new file mode 100644 index 0000000..896e8f4 --- /dev/null +++ b/assets/images/card_redirect.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/hyperswitch-checkout.php b/hyperswitch-checkout.php index da52991..518fdbd 100644 --- a/hyperswitch-checkout.php +++ b/hyperswitch-checkout.php @@ -5,7 +5,7 @@ * Description: Hyperswitch checkout plugin for WooCommerce * Author: Hyperswitch * Author URI: https://hyperswitch.io/ - * Version: 1.6.0 + * Version: 1.6.1 * License: GPLv2 or later * * WC requires at least: 4.0.0 @@ -32,7 +32,7 @@ exit; // Exit if accessed directly } -define( 'HYPERSWITCH_CHECKOUT_PLUGIN_VERSION', '1.6.0' ); +define( 'HYPERSWITCH_CHECKOUT_PLUGIN_VERSION', '1.6.1' ); define( 'HYPERSWITCH_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); require_once __DIR__ . '/includes/hyperswitch-webhook.php'; @@ -321,6 +321,11 @@ public function init_form_fields() { 'type' => 'password', 'description' => __( 'Find this on Developers > API Keys section of Hyperswitch Dashboard', 'hyperswitch-checkout' ) ), + 'profile_id' => array( + 'title' => 'Business Profile ID', + 'type' => 'text', + 'description' => __( 'Find this on Settings > Business profiles section of Hyperswitch Dashboard', 'hyperswitch-checkout' ) + ), 'enable_webhook' => array( 'title' => __( 'Enable Webhook', 'hyperswitch-checkout' ), 'type' => 'checkbox', @@ -411,7 +416,7 @@ function receipt_page( $payment_id ) { $woocommerce->add_error( __( "Something went wrong. Please contact support for assistance.", 'hyperswitch-checkout' ) ); $woocommerce->set_messages(); } - $redirect_url = get_permalink( woocommerce_get_page_id( 'cart' ) ); + $redirect_url = get_permalink( wc_get_page_id( 'cart' ) ); wp_redirect( $redirect_url ); exit; } @@ -462,6 +467,7 @@ function create_payment_intent( $order_id, $client_secret = null ) { global $woocommerce; $order = wc_get_order( $order_id ); $apiKey = $this->get_option( 'api_key' ); + $profileId = $this->get_option( 'profile_id' ); $publishable_key = $this->get_option( 'publishable_key' ); if ( isset( $client_secret ) ) { $payment_id = ""; @@ -579,8 +585,8 @@ function create_payment_intent( $order_id, $client_secret = null ) { $customer_logged_in = str_starts_with( $customer_id, "cust" ); $metadata = array( - "customer_created" => $customer_created, - "customer_logged_in" => $customer_logged_in, + "customer_created" => $customer_created ? "true" : "false", + "customer_logged_in" => $customer_logged_in ? "true" : "false", ); if ( $order ) { @@ -599,6 +605,9 @@ function create_payment_intent( $order_id, $client_secret = null ) { $payload["capture_method"] = $capture_method; $payload["amount"] = $amount; $payload["currency"] = $currency; + if ( isset( $profileId ) ) { + $payload["profile_id"] = $profileId; + } $args = array( 'body' => wp_json_encode( $payload ), diff --git a/js/hyperswitch-hyperservice.js b/js/hyperswitch-hyperservice.js index cb2638b..80a0671 100644 --- a/js/hyperswitch-hyperservice.js +++ b/js/hyperswitch-hyperservice.js @@ -291,6 +291,7 @@ document.addEventListener("DOMContentLoaded", () => { async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) { if (result || isOneClickPaymentMethod) { + let err; if (!isOneClickPaymentMethod && result) { const { error } = await hyper.confirmPayment({ confirmParams: { @@ -298,6 +299,7 @@ async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) { }, redirect: "if_required", }); + err = error; } else { const { error } = await hyper.confirmOneClickPayment( { @@ -308,10 +310,11 @@ async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) { }, result ); + err = error; } - if (error) { - if (error.type) { - if (error.type == "validation_error") { + if (err) { + if (err.type) { + if (err.type == "validation_error") { jQuery([document.documentElement, document.body]).animate( { scrollTop: jQuery( diff --git a/readme.txt b/readme.txt index 7a30239..97fbba9 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: vrishabjuspay Tags: woocommerce, hyperswitch, payment, e-commerce, checkout Requires at least: 4.0 Tested up to: 6.5.3 -Stable tag: 1.6.0 +Stable tag: 1.6.1 Requires PHP: 7.0 WC requires at least: 4.0.0 WC tested up to: 8.6.1