Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(api_keys): provide identifier for api key in the expiry reminder email (#3888)

Ravi Kiran901d61bc0ddb
diff --git a/crates/diesel_models/src/api_keys.rs b/crates/diesel_models/src/api_keys.rs
index 1875fc4dc5..7676e20d22 100644
--- a/crates/diesel_models/src/api_keys.rs
+++ b/crates/diesel_models/src/api_keys.rs
@@ -141,6 +141,8 @@ mod diesel_impl {
pub struct ApiKeyExpiryTrackingData {
pub key_id: String,
pub merchant_id: String,
+ pub api_key_name: String,
+ pub prefix: String,
pub api_key_expiry: Option<PrimitiveDateTime>,
// Days on which email reminder about api_key expiry has to be sent, prior to it's expiry.
pub expiry_reminder_days: Vec<u8>,
diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs
index 7d2069618d..a2fcacb3b3 100644
--- a/crates/router/src/core/api_keys.rs
+++ b/crates/router/src/core/api_keys.rs
@@ -207,6 +207,8 @@ pub async fn add_api_key_expiry_task(
let api_key_expiry_tracker = storage::ApiKeyExpiryTrackingData {
key_id: api_key.key_id.clone(),
merchant_id: api_key.merchant_id.clone(),
+ api_key_name: api_key.name.clone(),
+ prefix: api_key.prefix.clone(),
// We need API key expiry too, because we need to decide on the schedule_time in
// execute_workflow() where we won't be having access to the Api key object.
api_key_expiry: api_key.expires_at,
@@ -369,6 +371,8 @@ pub async fn update_api_key_expiry_task(
let updated_tracking_data = &storage::ApiKeyExpiryTrackingData {
key_id: api_key.key_id.clone(),
merchant_id: api_key.merchant_id.clone(),
+ api_key_name: api_key.name.clone(),
+ prefix: api_key.prefix.clone(),
api_key_expiry: api_key.expires_at,
expiry_reminder_days,
};
diff --git a/crates/router/src/services/email/assets/api_key_expiry_reminder.html b/crates/router/src/services/email/assets/api_key_expiry_reminder.html
index 1865ae3814..772602d71e 100644
--- a/crates/router/src/services/email/assets/api_key_expiry_reminder.html
+++ b/crates/router/src/services/email/assets/api_key_expiry_reminder.html
@@ -43,20 +43,7 @@
cellpadding="0"
cellspacing="0"
>
- <tr>
- <td
- class="spacer-lg"
- style="
- -premailer-height: 75;
- -premailer-width: 100%;
- line-height: 30px;
- margin: 0 auto;
- padding: 0;
- "
- height="75"
- width="100%"
- ></td>
- </tr>
+
<tr>
<td
class="spacer-lg"
@@ -96,13 +83,13 @@
line-height: 36px;
margin: 0 auto;
padding: 0;
- text-align: center;
+ text-align: left;
"
align="center"
>
<p style="font-size: 18px">Dear Merchant,</p>
<span style="font-size: 18px">
- It has come to our attention that your API key will expire in {expires_in} days. To ensure uninterrupted
+ It has come to our attention that your API key, <b>{api_key_name}</b> (<code>{prefix}*****</code>) </code> will expire in {expires_in} days. To ensure uninterrupted
access to our platform and continued smooth operation of your services, we kindly request that you take the
necessary actions as soon as possible.
</span>
@@ -118,39 +105,11 @@
margin: 0 auto;
padding: 0;
"
- width="100%"
- ></td>
- </tr>
-
- <tr>
- <td
- class="spacer-sm"
- style="
- -premailer-height: 20;
- -premailer-width: 100%;
- line-height: 10px;
- margin: 0 auto;
- padding: 0;
- "
height="20"
width="100%"
></td>
</tr>
- <tr>
- <td
- class="spacer-lg"
- style="
- -premailer-height: 75;
- -premailer-width: 100%;
- line-height: 30px;
- margin: 0 auto;
- padding: 0;
- "
- height="75"
- width="100%"
- ></td>
- </tr>
<tr>
<td
class="headline"
@@ -162,7 +121,7 @@
line-height: 36px;
margin: 0 auto;
padding: 0;
- text-align: center;
+ text-align: left;
"
align="center"
>
@@ -184,20 +143,7 @@
width="100%"
></td>
</tr>
- <tr>
- <td
- class="spacer-lg"
- style="
- -premailer-height: 75;
- -premailer-width: 100%;
- line-height: 30px;
- margin: 0 auto;
- padding: 0;
- "
- height="75"
- width="100%"
- ></td>
- </tr>
+
</table>
</div>
</body>
diff --git a/crates/router/src/services/email/types.rs b/crates/router/src/services/email/types.rs
index fa1eecbaab..2fbe7d606e 100644
--- a/crates/router/src/services/email/types.rs
+++ b/crates/router/src/services/email/types.rs
@@ -50,6 +50,8 @@ pub enum EmailBody {
},
ApiKeyExpiryReminder {
expires_in: u8,
+ api_key_name: String,
+ prefix: String,
},
}
@@ -128,8 +130,14 @@ Email : {user_email}
(note: This is an auto generated email. Use merchant email for any further communications)",
),
- EmailBody::ApiKeyExpiryReminder { expires_in } => format!(
+ EmailBody::ApiKeyExpiryReminder {
+ expires_in,
+ api_key_name,
+ prefix,
+ } => format!(
include_str!("assets/api_key_expiry_reminder.html"),
+ api_key_name = api_key_name,
+ prefix = prefix,
expires_in = expires_in,
),
}
@@ -441,6 +449,8 @@ pub struct ApiKeyExpiryReminder {
pub recipient_email: domain::UserEmail,
pub subject: &'static str,
pub expires_in: u8,
+ pub api_key_name: String,
+ pub prefix: String,
}
#[async_trait::async_trait]
@@ -450,6 +460,8 @@ impl EmailData for ApiKeyExpiryReminder {
let body = html::get_html_body(EmailBody::ApiKeyExpiryReminder {
expires_in: self.expires_in,
+ api_key_name: self.api_key_name.clone(),
+ prefix: self.prefix.clone(),
});
Ok(EmailContents {
diff --git a/crates/router/src/workflows/api_key_expiry.rs b/crates/router/src/workflows/api_key_expiry.rs
index e9e1f32370..c591481010 100644
--- a/crates/router/src/workflows/api_key_expiry.rs
+++ b/crates/router/src/workflows/api_key_expiry.rs
@@ -54,6 +54,10 @@ impl ProcessTrackerWorkflow<AppState> for ApiKeyExpiryWorkflow {
let retry_count = process.retry_count;
+ let api_key_name = tracking_data.api_key_name.clone();
+
+ let prefix = tracking_data.prefix.clone();
+
let expires_in = tracking_data
.expiry_reminder_days
.get(
@@ -69,6 +73,9 @@ impl ProcessTrackerWorkflow<AppState> for ApiKeyExpiryWorkflow {
})?,
subject: "API Key Expiry Notice",
expires_in: *expires_in,
+ api_key_name,
+ prefix,
+
};
state