Skip to content

Commit 6da1a5a

Browse files
prajjwalkumar17hyperswitch-bot[bot]
authored andcommitted
feat(core): billing_details inclusion in Payment Intent (#5090)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent f4145ae commit 6da1a5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+212
-144
lines changed

crates/diesel_models/src/payment_intent.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct PaymentIntent {
6060
pub charges: Option<pii::SecretSerdeValue>,
6161
pub frm_metadata: Option<pii::SecretSerdeValue>,
6262
pub customer_details: Option<Encryption>,
63+
pub billing_details: Option<Encryption>,
6364
pub merchant_order_reference_id: Option<String>,
6465
}
6566

@@ -117,6 +118,7 @@ pub struct PaymentIntentNew {
117118
pub charges: Option<pii::SecretSerdeValue>,
118119
pub frm_metadata: Option<pii::SecretSerdeValue>,
119120
pub customer_details: Option<Encryption>,
121+
pub billing_details: Option<Encryption>,
120122
pub merchant_order_reference_id: Option<String>,
121123
}
122124

@@ -177,6 +179,7 @@ pub enum PaymentIntentUpdate {
177179
request_external_three_ds_authentication: Option<bool>,
178180
frm_metadata: Option<pii::SecretSerdeValue>,
179181
customer_details: Option<Encryption>,
182+
billing_details: Option<Encryption>,
180183
merchant_order_reference_id: Option<String>,
181184
},
182185
PaymentAttemptAndAttemptCountUpdate {
@@ -254,6 +257,7 @@ pub struct PaymentIntentUpdateInternal {
254257
pub request_external_three_ds_authentication: Option<bool>,
255258
pub frm_metadata: Option<pii::SecretSerdeValue>,
256259
pub customer_details: Option<Encryption>,
260+
pub billing_details: Option<Encryption>,
257261
pub merchant_order_reference_id: Option<String>,
258262
}
259263

@@ -291,6 +295,7 @@ impl PaymentIntentUpdate {
291295
request_external_three_ds_authentication,
292296
frm_metadata,
293297
customer_details,
298+
billing_details,
294299
merchant_order_reference_id,
295300
} = self.into();
296301
PaymentIntent {
@@ -330,6 +335,7 @@ impl PaymentIntentUpdate {
330335
.or(source.request_external_three_ds_authentication),
331336
frm_metadata: frm_metadata.or(source.frm_metadata),
332337
customer_details: customer_details.or(source.customer_details),
338+
billing_details: billing_details.or(source.billing_details),
333339
merchant_order_reference_id: merchant_order_reference_id
334340
.or(source.merchant_order_reference_id),
335341
..source
@@ -363,6 +369,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
363369
request_external_three_ds_authentication,
364370
frm_metadata,
365371
customer_details,
372+
billing_details,
366373
merchant_order_reference_id,
367374
} => Self {
368375
amount: Some(amount),
@@ -388,6 +395,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
388395
request_external_three_ds_authentication,
389396
frm_metadata,
390397
customer_details,
398+
billing_details,
391399
merchant_order_reference_id,
392400
..Default::default()
393401
},

crates/diesel_models/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ diesel::table! {
890890
charges -> Nullable<Jsonb>,
891891
frm_metadata -> Nullable<Jsonb>,
892892
customer_details -> Nullable<Bytea>,
893+
billing_details -> Nullable<Bytea>,
893894
#[max_length = 255]
894895
merchant_order_reference_id -> Nullable<Varchar>,
895896
}

crates/hyperswitch_domain_models/src/payments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ pub struct PaymentIntent {
6363
pub charges: Option<pii::SecretSerdeValue>,
6464
pub frm_metadata: Option<pii::SecretSerdeValue>,
6565
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
66+
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
6667
pub merchant_order_reference_id: Option<String>,
6768
}

crates/hyperswitch_domain_models/src/payments/payment_attempt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ impl behaviour::Conversion for PaymentIntent {
530530
charges: self.charges,
531531
frm_metadata: self.frm_metadata,
532532
customer_details: self.customer_details.map(Encryption::from),
533+
billing_details: self.billing_details.map(Encryption::from),
533534
merchant_order_reference_id: self.merchant_order_reference_id,
534535
})
535536
}
@@ -592,6 +593,10 @@ impl behaviour::Conversion for PaymentIntent {
592593
.customer_details
593594
.async_lift(inner_decrypt)
594595
.await?,
596+
billing_details: storage_model
597+
.billing_details
598+
.async_lift(inner_decrypt)
599+
.await?,
595600
merchant_order_reference_id: storage_model.merchant_order_reference_id,
596601
})
597602
}
@@ -647,6 +652,7 @@ impl behaviour::Conversion for PaymentIntent {
647652
charges: self.charges,
648653
frm_metadata: self.frm_metadata,
649654
customer_details: self.customer_details.map(Encryption::from),
655+
billing_details: self.billing_details.map(Encryption::from),
650656
merchant_order_reference_id: self.merchant_order_reference_id,
651657
})
652658
}

crates/hyperswitch_domain_models/src/payments/payment_intent.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub struct PaymentIntentNew {
134134
pub request_external_three_ds_authentication: Option<bool>,
135135
pub charges: Option<pii::SecretSerdeValue>,
136136
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
137+
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
137138
}
138139

139140
#[derive(Debug, Clone, Serialize)]
@@ -193,6 +194,7 @@ pub enum PaymentIntentUpdate {
193194
session_expiry: Option<PrimitiveDateTime>,
194195
request_external_three_ds_authentication: Option<bool>,
195196
customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
197+
billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
196198
merchant_order_reference_id: Option<String>,
197199
},
198200
PaymentAttemptAndAttemptCountUpdate {
@@ -271,6 +273,7 @@ pub struct PaymentIntentUpdateInternal {
271273
pub request_external_three_ds_authentication: Option<bool>,
272274
pub frm_metadata: Option<pii::SecretSerdeValue>,
273275
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
276+
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
274277
pub merchant_order_reference_id: Option<String>,
275278
}
276279

@@ -300,6 +303,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
300303
request_external_three_ds_authentication,
301304
frm_metadata,
302305
customer_details,
306+
billing_details,
303307
merchant_order_reference_id,
304308
} => Self {
305309
amount: Some(amount),
@@ -325,6 +329,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
325329
request_external_three_ds_authentication,
326330
frm_metadata,
327331
customer_details,
332+
billing_details,
328333
merchant_order_reference_id,
329334
..Default::default()
330335
},
@@ -566,6 +571,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
566571
request_external_three_ds_authentication,
567572
frm_metadata,
568573
customer_details,
574+
billing_details,
569575
merchant_order_reference_id,
570576
} => Self::Update {
571577
amount,
@@ -590,6 +596,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
590596
request_external_three_ds_authentication,
591597
frm_metadata,
592598
customer_details: customer_details.map(Encryption::from),
599+
billing_details: billing_details.map(Encryption::from),
593600
merchant_order_reference_id,
594601
},
595602
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
@@ -693,6 +700,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
693700
request_external_three_ds_authentication,
694701
frm_metadata,
695702
customer_details,
703+
billing_details,
696704
merchant_order_reference_id,
697705
} = value;
698706

@@ -728,6 +736,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
728736
request_external_three_ds_authentication,
729737
frm_metadata,
730738
customer_details: customer_details.map(Encryption::from),
739+
billing_details: billing_details.map(Encryption::from),
731740
merchant_order_reference_id,
732741
}
733742
}

crates/router/src/connector/rapyd/transformers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl TryFrom<&RapydRouterData<&types::PaymentsAuthorizeRouterData>> for RapydPay
151151
}
152152
_ => None,
153153
}
154-
.get_required_value("payment_method not implemnted")
154+
.get_required_value("payment_method not implemented")
155155
.change_context(errors::ConnectorError::NotImplemented(
156156
"payment_method".to_owned(),
157157
))?;

crates/router/src/connector/utils.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
341341
billing_address
342342
.clone()
343343
.address
344-
.and_then(|billing_address_details| billing_address_details.first_name.clone())
344+
.and_then(|billing_details| billing_details.first_name.clone())
345345
})
346346
.ok_or_else(missing_field_err(
347347
"payment_method_data.billing.address.first_name",
@@ -364,7 +364,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
364364
billing_address
365365
.clone()
366366
.address
367-
.and_then(|billing_address_details| billing_address_details.last_name.clone())
367+
.and_then(|billing_details| billing_details.last_name.clone())
368368
})
369369
.ok_or_else(missing_field_err(
370370
"payment_method_data.billing.address.last_name",
@@ -378,7 +378,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
378378
billing_address
379379
.clone()
380380
.address
381-
.and_then(|billing_address_details| billing_address_details.line1.clone())
381+
.and_then(|billing_details| billing_details.line1.clone())
382382
})
383383
.ok_or_else(missing_field_err(
384384
"payment_method_data.billing.address.line1",
@@ -391,7 +391,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
391391
billing_address
392392
.clone()
393393
.address
394-
.and_then(|billing_address_details| billing_address_details.city)
394+
.and_then(|billing_details| billing_details.city)
395395
})
396396
.ok_or_else(missing_field_err(
397397
"payment_method_data.billing.address.city",
@@ -421,7 +421,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
421421
billing_address
422422
.clone()
423423
.address
424-
.and_then(|billing_address_details| billing_address_details.line1)
424+
.and_then(|billing_details| billing_details.line1)
425425
})
426426
}
427427

@@ -432,7 +432,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
432432
billing_address
433433
.clone()
434434
.address
435-
.and_then(|billing_address_details| billing_address_details.line2)
435+
.and_then(|billing_details| billing_details.line2)
436436
})
437437
}
438438

@@ -443,7 +443,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
443443
billing_address
444444
.clone()
445445
.address
446-
.and_then(|billing_address_details| billing_address_details.city)
446+
.and_then(|billing_details| billing_details.city)
447447
})
448448
}
449449

@@ -454,7 +454,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
454454
billing_address
455455
.clone()
456456
.address
457-
.and_then(|billing_address_details| billing_address_details.country)
457+
.and_then(|billing_details| billing_details.country)
458458
})
459459
}
460460

@@ -465,7 +465,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
465465
billing_address
466466
.clone()
467467
.address
468-
.and_then(|billing_address_details| billing_address_details.zip)
468+
.and_then(|billing_details| billing_details.zip)
469469
})
470470
}
471471

@@ -476,7 +476,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
476476
billing_address
477477
.clone()
478478
.address
479-
.and_then(|billing_address_details| billing_address_details.state)
479+
.and_then(|billing_details| billing_details.state)
480480
})
481481
}
482482

@@ -487,7 +487,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
487487
billing_address
488488
.clone()
489489
.address
490-
.and_then(|billing_address_details| billing_address_details.first_name)
490+
.and_then(|billing_details| billing_details.first_name)
491491
})
492492
}
493493

@@ -498,7 +498,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
498498
billing_address
499499
.clone()
500500
.address
501-
.and_then(|billing_address_details| billing_address_details.last_name)
501+
.and_then(|billing_details| billing_details.last_name)
502502
})
503503
}
504504

@@ -615,7 +615,7 @@ impl AddressData for api::Address {
615615
fn get_optional_country(&self) -> Option<enums::CountryAlpha2> {
616616
self.address
617617
.as_ref()
618-
.and_then(|billing_address_details| billing_address_details.country)
618+
.and_then(|billing_details| billing_details.country)
619619
}
620620

621621
fn get_optional_full_name(&self) -> Option<Secret<String>> {

crates/router/src/core/payments/helpers.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,6 +3151,7 @@ mod tests {
31513151
charges: None,
31523152
frm_metadata: None,
31533153
customer_details: None,
3154+
billing_details: None,
31543155
merchant_order_reference_id: None,
31553156
};
31563157
let req_cs = Some("1".to_string());
@@ -3212,6 +3213,7 @@ mod tests {
32123213
charges: None,
32133214
frm_metadata: None,
32143215
customer_details: None,
3216+
billing_details: None,
32153217
merchant_order_reference_id: None,
32163218
};
32173219
let req_cs = Some("1".to_string());
@@ -3272,6 +3274,7 @@ mod tests {
32723274
charges: None,
32733275
frm_metadata: None,
32743276
customer_details: None,
3277+
billing_details: None,
32753278
merchant_order_reference_id: None,
32763279
};
32773280
let req_cs = Some("1".to_string());

crates/router/src/core/payments/operations/payment_confirm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
blocklist::utils as blocklist_utils,
2323
errors::{self, CustomResult, RouterResult, StorageErrorExt},
2424
mandate::helpers as m_helpers,
25+
payment_methods::cards::create_encrypted_data,
2526
payments::{
2627
self, helpers, operations, populate_surcharge_details, CustomerDetails, PaymentAddress,
2728
PaymentData,
@@ -1218,6 +1219,10 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
12181219
.in_current_span(),
12191220
);
12201221

1222+
let billing_address = payment_data.address.get_payment_billing();
1223+
let billing_details = billing_address
1224+
.async_and_then(|_| async { create_encrypted_data(key_store, billing_address).await })
1225+
.await;
12211226
let m_payment_data_payment_intent = payment_data.payment_intent.clone();
12221227
let m_customer_id = customer_id.clone();
12231228
let m_shipping_address_id = shipping_address_id.clone();
@@ -1263,6 +1268,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
12631268
frm_metadata: m_frm_metadata,
12641269
customer_details,
12651270
merchant_order_reference_id: None,
1271+
billing_details,
12661272
},
12671273
&m_key_store,
12681274
storage_scheme,

crates/router/src/core/payments/operations/payment_create.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,16 @@ impl PaymentCreate {
10451045
.change_context(errors::ApiErrorResponse::InternalServerError)?
10461046
.map(Secret::new);
10471047

1048+
// Derivation of directly supplied Billing Address data in our Payment Create Request
1049+
// Encrypting our Billing Address Details to be stored in Payment Intent
1050+
let billing_details = request
1051+
.billing
1052+
.clone()
1053+
.async_and_then(|_| async {
1054+
create_encrypted_data(key_store, request.billing.clone()).await
1055+
})
1056+
.await;
1057+
10481058
// Derivation of directly supplied Customer data in our Payment Create Request
10491059
let raw_customer_details = if request.customer_id.is_none()
10501060
&& (request.name.is_some()
@@ -1116,6 +1126,7 @@ impl PaymentCreate {
11161126
.request_external_three_ds_authentication,
11171127
charges,
11181128
frm_metadata: request.frm_metadata.clone(),
1129+
billing_details,
11191130
customer_details,
11201131
merchant_order_reference_id: request.merchant_order_reference_id.clone(),
11211132
})

0 commit comments

Comments
 (0)