Skip to content

Commit

Permalink
Feat/profile id compatibility (#14)
Browse files Browse the repository at this point in the history
* card redirect

* Fixes for sandbox

* changed the deprecated function

* Implements profile ID handling

* Feat: profile_id setting for multiple busness profiles.
  • Loading branch information
whiteagle3k authored May 13, 2024
1 parent ecd84f6 commit 933fbc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions assets/images/card_redirect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 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.6.0
* Version: 1.6.1
* 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.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';
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 ),
Expand Down
9 changes: 6 additions & 3 deletions js/hyperswitch-hyperservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,15 @@ document.addEventListener("DOMContentLoaded", () => {

async function hyperswitchPaymentHandleSubmit(isOneClickPaymentMethod, result) {
if (result || isOneClickPaymentMethod) {
let err;
if (!isOneClickPaymentMethod && result) {
const { error } = await hyper.confirmPayment({
confirmParams: {
return_url: hyperswitchReturnUrl,
},
redirect: "if_required",
});
err = error;
} else {
const { error } = await hyper.confirmOneClickPayment(
{
Expand All @@ -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(
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: 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
Expand Down

0 comments on commit 933fbc7

Please sign in to comment.