Skip to content

Commit

Permalink
add payment link support for sdkHandleConfirmPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
cookieg13 committed Dec 17, 2024
1 parent c154a38 commit 6f24a75
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 4 deletions.
40 changes: 39 additions & 1 deletion api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12725,7 +12725,8 @@
"display_sdk_only",
"enabled_saved_payment_method",
"hide_card_nickname_field",
"show_card_form_by_default"
"show_card_form_by_default",
"sdk_handle_confirm_payment"
],
"properties": {
"theme": {
Expand Down Expand Up @@ -12797,6 +12798,30 @@
"type": "boolean",
"description": "Toggle for HyperSwitch branding visibility",
"nullable": true
},
"sdk_handle_confirm_payment":{
"type": "object",
"properties": {
"handle_confirm": {
"type": "boolean",
"description": "Boolean to enable handle confirm button from sdk",
},
"button_text": {
"type": "string",
"description": "Text for sdk's handle confirm button",
"nullable": true
},
"confirm_params": {
"type": "object",
"properties": {
"return_url": {
"type": "string",
"description": "URL where the user should be redirected after payment confirmation"
}
}
}
},
"nullable": true
}
}
},
Expand Down Expand Up @@ -12882,6 +12907,19 @@
}
],
"nullable": true
},
"sdk_handle_confirm_payment":{
"type": "object",
"properties": {
"handle_confirm": {
"type": "string",
"description": "Boolean to enable handle confirm button from sdk"
},
"button_text": {
"type": "string",
"description": "Text for sdk's handle confirm button"
}
}
}
}
},
Expand Down
41 changes: 39 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15409,7 +15409,8 @@
"display_sdk_only",
"enabled_saved_payment_method",
"hide_card_nickname_field",
"show_card_form_by_default"
"show_card_form_by_default",
"sdk_handle_confirm_payment"
],
"properties": {
"theme": {
Expand Down Expand Up @@ -15481,7 +15482,30 @@
"type": "boolean",
"description": "Toggle for HyperSwitch branding visibility",
"nullable": true
}
},
"sdk_handle_confirm_payment":{
"type": "object",
"properties": {
"handle_confirm": {
"type": "boolean",
"description": "Boolean to enable handle confirm button from sdk"
},
"button_text": {
"type": "string",
"description": "Text for sdk's handle confirm button",
"nullable": true
},
"confirm_params": {
"type": "object",
"properties": {
"return_url": {
"type": "string",
"description": "URL where the user should be redirected after payment confirmation"
}
}
}
},
"nullable": true
}
},
"PaymentLinkConfigRequest": {
Expand Down Expand Up @@ -15566,6 +15590,19 @@
}
],
"nullable": true
},
"sdk_handle_confirm_payment":{
"type": "object",
"properties": {
"handle_confirm": {
"type": "boolean",
"description": "Boolean to enable handle confirm button from sdk"
},
"button_text": {
"type": "string",
"description": "Text for sdk's handle confirm button"
}
}
}
}
},
Expand Down
21 changes: 21 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,8 @@ pub struct PaymentLinkConfigRequest {
/// Custom layout for details section
#[schema(value_type = Option<PaymentLinkDetailsLayout>, example = "layout1")]
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
/// Handle confirm payment from sdk end
pub sdk_handle_confirm_payment: Option<SdkHandleConfirmPayment>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
Expand Down Expand Up @@ -2809,6 +2811,23 @@ pub struct PaymentLinkBackgroundImageConfig {
pub size: Option<api_enums::ElementSize>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct ConfirmParams {
/// URL where the user should be redirected after payment confirmation
pub return_url: String,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct SdkHandleConfirmPayment {
/// Boolean to enable confirm button from sdk
#[schema(default = false, example = true)]
pub handle_confirm: bool,
/// Text for sdk's handle confirm button
#[schema(value_type = Option<String>, example = "Pay with SDK")]
pub button_text: Option<String>,
pub confirm_params: ConfirmParams,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
pub struct PaymentLinkConfig {
/// custom theme for the payment link
Expand Down Expand Up @@ -2838,6 +2857,8 @@ pub struct PaymentLinkConfig {
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
/// Toggle for HyperSwitch branding visibility
pub branding_visibility: Option<bool>,
/// Handle confirm payment from sdk end
pub sdk_handle_confirm_payment: Option<SdkHandleConfirmPayment>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6863,6 +6863,7 @@ pub struct PaymentLinkDetails {
pub background_image: Option<admin::PaymentLinkBackgroundImageConfig>,
pub details_layout: Option<api_enums::PaymentLinkDetailsLayout>,
pub branding_visibility: Option<bool>,
pub sdk_handle_confirm_payment: Option<admin::SdkHandleConfirmPayment>,
}

#[derive(Debug, serde::Serialize, Clone)]
Expand All @@ -6872,6 +6873,7 @@ pub struct SecurePaymentLinkDetails {
pub show_card_form_by_default: bool,
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
pub sdk_handle_confirm_payment: Option<admin::SdkHandleConfirmPayment>,
}

#[derive(Debug, serde::Serialize)]
Expand Down
13 changes: 13 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ pub struct PaymentLinkConfigRequest {
pub show_card_form_by_default: Option<bool>,
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
pub sdk_handle_confirm_payment: Option<SdkHandleConfirmPayment>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
Expand All @@ -580,6 +581,18 @@ pub struct PaymentLinkBackgroundImageConfig {
pub size: Option<common_enums::ElementSize>,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
pub struct ConfirmParams {
pub return_url: String,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
pub struct SdkHandleConfirmPayment {
pub handle_confirm: bool,
pub button_text: Option<String>,
pub confirm_params: ConfirmParams,
}

common_utils::impl_to_sql_from_sql_json!(BusinessPaymentLinkConfig);

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression)]
Expand Down
7 changes: 6 additions & 1 deletion crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use crate::schema::payment_intent;
use crate::schema_v2::payment_intent;
#[cfg(feature = "v2")]
use crate::types::{FeatureMetadata, OrderDetailsWithAmount};
use crate::{business_profile::PaymentLinkBackgroundImageConfig, enums as storage_enums};
use crate::{
business_profile::{PaymentLinkBackgroundImageConfig, SdkHandleConfirmPayment},
enums as storage_enums,
};

#[cfg(feature = "v2")]
#[derive(Clone, Debug, PartialEq, Identifiable, Queryable, Serialize, Deserialize, Selectable)]
Expand Down Expand Up @@ -167,6 +170,8 @@ pub struct PaymentLinkConfigRequestForPayments {
pub background_image: Option<PaymentLinkBackgroundImageConfig>,
/// Custom layout for details section
pub details_layout: Option<common_enums::PaymentLinkDetailsLayout>,
/// Handle confirm payment from sdk
pub sdk_handle_confirm_payment: Option<SdkHandleConfirmPayment>,
}

common_utils::impl_to_sql_from_sql_json!(PaymentLinkConfigRequestForPayments);
Expand Down
35 changes: 35 additions & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
background_image,
)
}),
sdk_handle_confirm_payment: item.sdk_handle_confirm_payment.map(
|sdk_handle_confirm_payment| {
diesel_models::business_profile::SdkHandleConfirmPayment::convert_from(
sdk_handle_confirm_payment,
)
},
),
}
}
fn convert_back(self) -> api_models::admin::PaymentLinkConfigRequest {
Expand All @@ -224,6 +231,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
transaction_details,
background_image,
details_layout,
sdk_handle_confirm_payment,
} = self;
api_models::admin::PaymentLinkConfigRequest {
theme,
Expand All @@ -243,6 +251,8 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
}),
background_image: background_image
.map(|background_image| background_image.convert_back()),
sdk_handle_confirm_payment: sdk_handle_confirm_payment
.map(|sdk_handle_confirm_payment| sdk_handle_confirm_payment.convert_back()),
}
}
}
Expand Down Expand Up @@ -300,6 +310,31 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkBackgroundImag
}
}

#[cfg(feature = "v2")]
impl ApiModelToDieselModelConvertor<api_models::admin::SdkHandleConfirmPayment>
for diesel_models::business_profile::SdkHandleConfirmPayment
{
fn convert_from(from: api_models::admin::SdkHandleConfirmPayment) -> Self {
Self {
handle_confirm: from.handle_confirm,
button_text: from.button_text,
confirm_params: from.confirm_params,
}
}
fn convert_back(self) -> api_models::admin::SdkHandleConfirmPayment {
let Self {
handle_confirm,
button_text,
confirm_params,
} = self;
api_models::admin::SdkHandleConfirmPayment {
handle_confirm,
button_text,
confirm_params,
}
}
}

#[cfg(feature = "v2")]
impl ApiModelToDieselModelConvertor<api_models::admin::TransactionDetailsUiConfiguration>
for diesel_models::TransactionDetailsUiConfiguration
Expand Down
24 changes: 24 additions & 0 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub async fn form_payment_link_data(
background_image: None,
details_layout: None,
branding_visibility: None,
sdk_handle_confirm_payment: None,
}
};

Expand Down Expand Up @@ -277,6 +278,7 @@ pub async fn form_payment_link_data(
background_image: payment_link_config.background_image.clone(),
details_layout: payment_link_config.details_layout,
branding_visibility: payment_link_config.branding_visibility,
sdk_handle_confirm_payment: payment_link_config.sdk_handle_confirm_payment.clone(),
};

Ok((
Expand Down Expand Up @@ -335,6 +337,7 @@ pub async fn initiate_secure_payment_link_flow(
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
show_card_form_by_default: payment_link_config.show_card_form_by_default,
payment_link_details: *link_details.to_owned(),
sdk_handle_confirm_payment: payment_link_config.sdk_handle_confirm_payment.clone(),
};
let js_script = format!(
"window.__PAYMENT_DETAILS = {}",
Expand Down Expand Up @@ -680,6 +683,26 @@ pub fn get_payment_link_config_based_on_priority(
.map(|background_image| background_image.clone().foreign_into())
})
}),
sdk_handle_confirm_payment: payment_create_link_config
.as_ref()
.and_then(|payment_link_config| {
payment_link_config
.theme_config
.sdk_handle_confirm_payment
.clone()
})
.or_else(|| {
business_theme_configs
.as_ref()
.and_then(|business_theme_config| {
business_theme_config
.sdk_handle_confirm_payment
.as_ref()
.map(|sdk_handle_confirm_payment| {
sdk_handle_confirm_payment.clone().foreign_into()
})
})
}),
};

Ok((payment_link_config, domain_name))
Expand Down Expand Up @@ -786,6 +809,7 @@ pub async fn get_payment_link_status(
background_image: None,
details_layout: None,
branding_visibility: None,
sdk_handle_confirm_payment: None,
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function initializeSDK() {
// @ts-ignore
var paymentDetails = window.__PAYMENT_DETAILS;
var client_secret = paymentDetails.client_secret;
console.log("<<>>paymentDetails",paymentDetails);
var appearance = {
variables: {
colorPrimary: paymentDetails.theme || "rgb(0, 109, 249)",
Expand Down Expand Up @@ -41,6 +42,16 @@ function initializeSDK() {
? "accordion"
: paymentDetails.sdk_layout;
var hideCardNicknameField = paymentDetails.hide_card_nickname_field;
var sdkHandleConfirmPayment = paymentDetails.sdk_handle_confirm_payment
? {
handleConfirm: paymentDetails.sdk_handle_confirm_payment.handle_confirm,
buttonText: paymentDetails.sdk_handle_confirm_payment.button_text || null,
confirmParams: {
return_url: paymentDetails.sdk_handle_confirm_payment.confirm_params.return_url
}
}
: null;

var unifiedCheckoutOptions = {
displaySavedPaymentMethodsCheckbox: false,
displaySavedPaymentMethods: false,
Expand All @@ -59,6 +70,7 @@ function initializeSDK() {
},
showCardFormByDefault: paymentDetails.show_card_form_by_default,
hideCardNicknameField: hideCardNicknameField,
sdkHandleConfirmPayment: sdkHandleConfirmPayment,
};
// @ts-ignore
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
Expand Down
Loading

0 comments on commit 6f24a75

Please sign in to comment.