mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(payments): [Payment links] Add configs for payment link (#7288)
This commit is contained in:
		| @ -130,6 +130,8 @@ pub async fn form_payment_link_data( | ||||
|                 details_layout: None, | ||||
|                 branding_visibility: None, | ||||
|                 payment_button_text: None, | ||||
|                 custom_message_for_card_terms: None, | ||||
|                 payment_button_colour: None, | ||||
|             } | ||||
|         }; | ||||
|  | ||||
| @ -276,6 +278,8 @@ pub async fn form_payment_link_data( | ||||
|         details_layout: payment_link_config.details_layout, | ||||
|         branding_visibility: payment_link_config.branding_visibility, | ||||
|         payment_button_text: payment_link_config.payment_button_text.clone(), | ||||
|         custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms.clone(), | ||||
|         payment_button_colour: payment_link_config.payment_button_colour.clone(), | ||||
|     }; | ||||
|  | ||||
|     Ok(( | ||||
| @ -327,6 +331,8 @@ pub async fn initiate_secure_payment_link_flow( | ||||
|                 show_card_form_by_default: payment_link_config.show_card_form_by_default, | ||||
|                 payment_link_details: *link_details.to_owned(), | ||||
|                 payment_button_text: payment_link_config.payment_button_text, | ||||
|                 custom_message_for_card_terms: payment_link_config.custom_message_for_card_terms, | ||||
|                 payment_button_colour: payment_link_config.payment_button_colour, | ||||
|             }; | ||||
|             let js_script = format!( | ||||
|                 "window.__PAYMENT_DETAILS = {}", | ||||
| @ -625,6 +631,24 @@ pub fn get_payment_link_config_based_on_priority( | ||||
|         (hide_card_nickname_field, DEFAULT_HIDE_CARD_NICKNAME_FIELD), | ||||
|         (show_card_form_by_default, DEFAULT_SHOW_CARD_FORM) | ||||
|     ); | ||||
|  | ||||
|     let ( | ||||
|         details_layout, | ||||
|         background_image, | ||||
|         payment_button_text, | ||||
|         custom_message_for_card_terms, | ||||
|         payment_button_colour, | ||||
|     ) = get_payment_link_config_value!( | ||||
|         payment_create_link_config, | ||||
|         business_theme_configs, | ||||
|         (details_layout), | ||||
|         (background_image, |background_image| background_image | ||||
|             .foreign_into()), | ||||
|         (payment_button_text), | ||||
|         (custom_message_for_card_terms), | ||||
|         (payment_button_colour), | ||||
|     ); | ||||
|  | ||||
|     let payment_link_config = | ||||
|         PaymentLinkConfig { | ||||
|             theme, | ||||
| @ -640,41 +664,11 @@ pub fn get_payment_link_config_based_on_priority( | ||||
|             transaction_details: payment_create_link_config.as_ref().and_then( | ||||
|                 |payment_link_config| payment_link_config.theme_config.transaction_details.clone(), | ||||
|             ), | ||||
|             details_layout: payment_create_link_config | ||||
|                 .as_ref() | ||||
|                 .and_then(|payment_link_config| payment_link_config.theme_config.details_layout) | ||||
|                 .or_else(|| { | ||||
|                     business_theme_configs | ||||
|                         .as_ref() | ||||
|                         .and_then(|business_theme_config| business_theme_config.details_layout) | ||||
|                 }), | ||||
|             background_image: payment_create_link_config | ||||
|                 .as_ref() | ||||
|                 .and_then(|payment_link_config| { | ||||
|                     payment_link_config.theme_config.background_image.clone() | ||||
|                 }) | ||||
|                 .or_else(|| { | ||||
|                     business_theme_configs | ||||
|                         .as_ref() | ||||
|                         .and_then(|business_theme_config| { | ||||
|                             business_theme_config | ||||
|                                 .background_image | ||||
|                                 .as_ref() | ||||
|                                 .map(|background_image| background_image.clone().foreign_into()) | ||||
|                         }) | ||||
|                 }), | ||||
|             payment_button_text: payment_create_link_config | ||||
|                 .as_ref() | ||||
|                 .and_then(|payment_link_config| { | ||||
|                     payment_link_config.theme_config.payment_button_text.clone() | ||||
|                 }) | ||||
|                 .or_else(|| { | ||||
|                     business_theme_configs | ||||
|                         .as_ref() | ||||
|                         .and_then(|business_theme_config| { | ||||
|                             business_theme_config.payment_button_text.clone() | ||||
|                         }) | ||||
|                 }), | ||||
|             details_layout, | ||||
|             background_image, | ||||
|             payment_button_text, | ||||
|             custom_message_for_card_terms, | ||||
|             payment_button_colour, | ||||
|         }; | ||||
|  | ||||
|     Ok((payment_link_config, domain_name)) | ||||
| @ -778,6 +772,8 @@ pub async fn get_payment_link_status( | ||||
|             details_layout: None, | ||||
|             branding_visibility: None, | ||||
|             payment_button_text: None, | ||||
|             custom_message_for_card_terms: None, | ||||
|             payment_button_colour: None, | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|  | ||||
| @ -640,7 +640,6 @@ body { | ||||
|   margin-top: 20px; | ||||
|   width: 100%; | ||||
|   height: 38px; | ||||
|   background-color: var(--primary-color); | ||||
|   border: 0; | ||||
|   border-radius: 4px; | ||||
|   font-size: 18px; | ||||
|  | ||||
| @ -308,6 +308,7 @@ function initializeEventListeners(paymentDetails) { | ||||
|  | ||||
|   if (submitButtonNode instanceof HTMLButtonElement) { | ||||
|     submitButtonNode.style.color = contrastBWColor; | ||||
|     submitButtonNode.style.backgroundColor = paymentDetails.payment_button_colour || primaryColor; | ||||
|   } | ||||
|  | ||||
|   if (hyperCheckoutCartImageNode instanceof HTMLDivElement) { | ||||
|  | ||||
| @ -64,6 +64,7 @@ function initializeSDK() { | ||||
|     }, | ||||
|     showCardFormByDefault: paymentDetails.show_card_form_by_default, | ||||
|     hideCardNicknameField: hideCardNicknameField, | ||||
|     customMessageForCardTerms: paymentDetails.custom_message_for_card_terms, | ||||
|   }; | ||||
|   // @ts-ignore | ||||
|   unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions); | ||||
|  | ||||
| @ -87,6 +87,7 @@ if (!isFramed) { | ||||
|       }, | ||||
|       hideCardNicknameField: hideCardNicknameField, | ||||
|       showCardFormByDefault: paymentDetails.show_card_form_by_default, | ||||
|       customMessageForCardTerms: paymentDetails.custom_message_for_card_terms, | ||||
|     }; | ||||
|     // @ts-ignore | ||||
|     unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions); | ||||
|  | ||||
| @ -4301,6 +4301,8 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest> | ||||
|                 ) | ||||
|             }), | ||||
|             payment_button_text: config.payment_button_text, | ||||
|             custom_message_for_card_terms: config.custom_message_for_card_terms, | ||||
|             payment_button_colour: config.payment_button_colour, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -4364,6 +4366,8 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments> | ||||
|                 ) | ||||
|             }), | ||||
|             payment_button_text: config.payment_button_text, | ||||
|             custom_message_for_card_terms: config.custom_message_for_card_terms, | ||||
|             payment_button_colour: config.payment_button_colour, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -32,4 +32,37 @@ macro_rules! get_payment_link_config_value { | ||||
|             $(get_payment_link_config_value_based_on_priority!($config, $business_config, $field, $default)),* | ||||
|         ) | ||||
|     }; | ||||
|     ($config:expr, $business_config:expr, $(($field:ident)),*) => { | ||||
|         ( | ||||
|             $( | ||||
|                 $config | ||||
|                     .as_ref() | ||||
|                     .and_then(|pc_config| pc_config.theme_config.$field.clone()) | ||||
|                     .or_else(|| { | ||||
|                         $business_config | ||||
|                             .as_ref() | ||||
|                             .and_then(|business_config| business_config.$field.clone()) | ||||
|                     }) | ||||
|             ),* | ||||
|         ) | ||||
|     }; | ||||
|     ($config:expr, $business_config:expr, $(($field:ident $(, $transform:expr)?)),* $(,)?) => { | ||||
|         ( | ||||
|             $( | ||||
|                 $config | ||||
|                     .as_ref() | ||||
|                     .and_then(|pc_config| pc_config.theme_config.$field.clone()) | ||||
|                     .or_else(|| { | ||||
|                         $business_config | ||||
|                             .as_ref() | ||||
|                             .and_then(|business_config| { | ||||
|                                 let value = business_config.$field.clone(); | ||||
|                                 $(let value = value.map($transform);)? | ||||
|                                 value | ||||
|                             }) | ||||
|                     }) | ||||
|             ),* | ||||
|         ) | ||||
|     }; | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -2566,7 +2566,7 @@ pub async fn payments_finish_redirection( | ||||
|  | ||||
|     let locking_action = payload.get_locking_input(flow.clone()); | ||||
|  | ||||
|     api::server_wrap( | ||||
|     Box::pin(api::server_wrap( | ||||
|         flow, | ||||
|         state, | ||||
|         &req, | ||||
| @ -2588,7 +2588,7 @@ pub async fn payments_finish_redirection( | ||||
|             profile_id: profile_id.clone(), | ||||
|         }, | ||||
|         locking_action, | ||||
|     ) | ||||
|     )) | ||||
|     .await | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -2105,6 +2105,8 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest> | ||||
|                 .background_image | ||||
|                 .map(|background_image| background_image.foreign_into()), | ||||
|             payment_button_text: item.payment_button_text, | ||||
|             custom_message_for_card_terms: item.custom_message_for_card_terms, | ||||
|             payment_button_colour: item.payment_button_colour, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -2128,6 +2130,8 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest> | ||||
|                 .background_image | ||||
|                 .map(|background_image| background_image.foreign_into()), | ||||
|             payment_button_text: item.payment_button_text, | ||||
|             custom_message_for_card_terms: item.custom_message_for_card_terms, | ||||
|             payment_button_colour: item.payment_button_colour, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Debarati Ghatak
					Debarati Ghatak