Skip to content

Commit 933fbc7

Browse files
authored
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.
1 parent ecd84f6 commit 933fbc7

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

Diff for: assets/images/card_redirect.svg

+8
Loading

Diff for: hyperswitch-checkout.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Hyperswitch checkout plugin for WooCommerce
66
* Author: Hyperswitch
77
* Author URI: https://hyperswitch.io/
8-
* Version: 1.6.0
8+
* Version: 1.6.1
99
* License: GPLv2 or later
1010
*
1111
* WC requires at least: 4.0.0
@@ -32,7 +32,7 @@
3232
exit; // Exit if accessed directly
3333
}
3434

35-
define( 'HYPERSWITCH_CHECKOUT_PLUGIN_VERSION', '1.6.0' );
35+
define( 'HYPERSWITCH_CHECKOUT_PLUGIN_VERSION', '1.6.1' );
3636
define( 'HYPERSWITCH_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
3737

3838
require_once __DIR__ . '/includes/hyperswitch-webhook.php';
@@ -321,6 +321,11 @@ public function init_form_fields() {
321321
'type' => 'password',
322322
'description' => __( 'Find this on Developers > API Keys section of Hyperswitch Dashboard', 'hyperswitch-checkout' )
323323
),
324+
'profile_id' => array(
325+
'title' => 'Business Profile ID',
326+
'type' => 'text',
327+
'description' => __( 'Find this on Settings > Business profiles section of Hyperswitch Dashboard', 'hyperswitch-checkout' )
328+
),
324329
'enable_webhook' => array(
325330
'title' => __( 'Enable Webhook', 'hyperswitch-checkout' ),
326331
'type' => 'checkbox',
@@ -411,7 +416,7 @@ function receipt_page( $payment_id ) {
411416
$woocommerce->add_error( __( "Something went wrong. Please contact support for assistance.", 'hyperswitch-checkout' ) );
412417
$woocommerce->set_messages();
413418
}
414-
$redirect_url = get_permalink( woocommerce_get_page_id( 'cart' ) );
419+
$redirect_url = get_permalink( wc_get_page_id( 'cart' ) );
415420
wp_redirect( $redirect_url );
416421
exit;
417422
}
@@ -462,6 +467,7 @@ function create_payment_intent( $order_id, $client_secret = null ) {
462467
global $woocommerce;
463468
$order = wc_get_order( $order_id );
464469
$apiKey = $this->get_option( 'api_key' );
470+
$profileId = $this->get_option( 'profile_id' );
465471
$publishable_key = $this->get_option( 'publishable_key' );
466472
if ( isset( $client_secret ) ) {
467473
$payment_id = "";
@@ -579,8 +585,8 @@ function create_payment_intent( $order_id, $client_secret = null ) {
579585
$customer_logged_in = str_starts_with( $customer_id, "cust" );
580586

581587
$metadata = array(
582-
"customer_created" => $customer_created,
583-
"customer_logged_in" => $customer_logged_in,
588+
"customer_created" => $customer_created ? "true" : "false",
589+
"customer_logged_in" => $customer_logged_in ? "true" : "false",
584590
);
585591

586592
if ( $order ) {
@@ -599,6 +605,9 @@ function create_payment_intent( $order_id, $client_secret = null ) {
599605
$payload["capture_method"] = $capture_method;
600606
$payload["amount"] = $amount;
601607
$payload["currency"] = $currency;
608+
if ( isset( $profileId ) ) {
609+
$payload["profile_id"] = $profileId;
610+
}
602611

603612
$args = array(
604613
'body' => wp_json_encode( $payload ),

Diff for: js/hyperswitch-hyperservice.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,15 @@ document.addEventListener("DOMContentLoaded", () => {
291291

292292
async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) {
293293
if (result || isOneClickPaymentMethod) {
294+
let err;
294295
if (!isOneClickPaymentMethod && result) {
295296
const { error } = await hyper.confirmPayment({
296297
confirmParams: {
297298
return_url: hyperswitchReturnUrl,
298299
},
299300
redirect: "if_required",
300301
});
302+
err = error;
301303
} else {
302304
const { error } = await hyper.confirmOneClickPayment(
303305
{
@@ -308,10 +310,11 @@ async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) {
308310
},
309311
result
310312
);
313+
err = error;
311314
}
312-
if (error) {
313-
if (error.type) {
314-
if (error.type == "validation_error") {
315+
if (err) {
316+
if (err.type) {
317+
if (err.type == "validation_error") {
315318
jQuery([document.documentElement, document.body]).animate(
316319
{
317320
scrollTop: jQuery(

Diff for: readme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: vrishabjuspay
33
Tags: woocommerce, hyperswitch, payment, e-commerce, checkout
44
Requires at least: 4.0
55
Tested up to: 6.5.3
6-
Stable tag: 1.6.0
6+
Stable tag: 1.6.1
77
Requires PHP: 7.0
88
WC requires at least: 4.0.0
99
WC tested up to: 8.6.1

0 commit comments

Comments
 (0)