Skip to content

Commit bed8326

Browse files
fix(core): update amount_capturable in update trackers (#2142)
1 parent 9d74a75 commit bed8326

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

crates/data_models/src/payments/payment_attempt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ pub enum PaymentAttemptUpdate {
216216
payment_token: Option<String>,
217217
connector: Option<String>,
218218
straight_through_algorithm: Option<serde_json::Value>,
219+
amount_capturable: Option<i64>,
219220
},
220221
AuthenticationTypeUpdate {
221222
authentication_type: storage_enums::AuthenticationType,
@@ -236,6 +237,7 @@ pub enum PaymentAttemptUpdate {
236237
straight_through_algorithm: Option<serde_json::Value>,
237238
error_code: Option<Option<String>>,
238239
error_message: Option<Option<String>>,
240+
amount_capturable: Option<i64>,
239241
},
240242
RejectUpdate {
241243
status: storage_enums::AttemptStatus,

crates/diesel_models/src/payment_attempt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub enum PaymentAttemptUpdate {
137137
payment_token: Option<String>,
138138
connector: Option<String>,
139139
straight_through_algorithm: Option<serde_json::Value>,
140+
amount_capturable: Option<i64>,
140141
},
141142
AuthenticationTypeUpdate {
142143
authentication_type: storage_enums::AuthenticationType,
@@ -157,6 +158,7 @@ pub enum PaymentAttemptUpdate {
157158
straight_through_algorithm: Option<serde_json::Value>,
158159
error_code: Option<Option<String>>,
159160
error_message: Option<Option<String>>,
161+
amount_capturable: Option<i64>,
160162
},
161163
VoidUpdate {
162164
status: storage_enums::AttemptStatus,
@@ -339,6 +341,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
339341
straight_through_algorithm,
340342
error_code,
341343
error_message,
344+
amount_capturable,
342345
} => Self {
343346
amount: Some(amount),
344347
currency: Some(currency),
@@ -356,6 +359,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
356359
straight_through_algorithm,
357360
error_code,
358361
error_message,
362+
amount_capturable,
359363
..Default::default()
360364
},
361365
PaymentAttemptUpdate::VoidUpdate {
@@ -432,10 +436,12 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
432436
payment_token,
433437
connector,
434438
straight_through_algorithm,
439+
amount_capturable,
435440
} => Self {
436441
payment_token,
437442
connector,
438443
straight_through_algorithm,
444+
amount_capturable,
439445
..Default::default()
440446
},
441447
PaymentAttemptUpdate::UnresolvedResponseUpdate {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
513513
.take();
514514
let order_details = payment_data.payment_intent.order_details.clone();
515515
let metadata = payment_data.payment_intent.metadata.clone();
516-
516+
let authorized_amount = payment_data.payment_attempt.amount;
517517
let payment_attempt_fut = db
518518
.update_payment_attempt_with_attempt_id(
519519
payment_data.payment_attempt,
@@ -533,6 +533,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
533533
straight_through_algorithm,
534534
error_code,
535535
error_message,
536+
amount_capturable: Some(authorized_amount),
536537
},
537538
storage_scheme,
538539
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
386386
.payment_attempt
387387
.straight_through_algorithm
388388
.clone();
389+
let authorized_amount = payment_data.payment_attempt.amount;
389390

390391
payment_data.payment_attempt = db
391392
.update_payment_attempt_with_attempt_id(
@@ -394,6 +395,10 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
394395
payment_token,
395396
connector,
396397
straight_through_algorithm,
398+
amount_capturable: match payment_data.confirm.unwrap_or(true) {
399+
true => Some(authorized_amount),
400+
false => None,
401+
},
397402
},
398403
storage_scheme,
399404
)

crates/storage_impl/src/payments/payment_attempt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,12 @@ impl DataModelExt for PaymentAttemptUpdate {
10891089
payment_token,
10901090
connector,
10911091
straight_through_algorithm,
1092+
amount_capturable,
10921093
} => DieselPaymentAttemptUpdate::UpdateTrackers {
10931094
payment_token,
10941095
connector,
10951096
straight_through_algorithm,
1097+
amount_capturable,
10961098
},
10971099
Self::AuthenticationTypeUpdate {
10981100
authentication_type,
@@ -1115,6 +1117,7 @@ impl DataModelExt for PaymentAttemptUpdate {
11151117
straight_through_algorithm,
11161118
error_code,
11171119
error_message,
1120+
amount_capturable,
11181121
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
11191122
amount,
11201123
currency,
@@ -1131,6 +1134,7 @@ impl DataModelExt for PaymentAttemptUpdate {
11311134
straight_through_algorithm,
11321135
error_code,
11331136
error_message,
1137+
amount_capturable,
11341138
},
11351139
Self::VoidUpdate {
11361140
status,
@@ -1275,10 +1279,12 @@ impl DataModelExt for PaymentAttemptUpdate {
12751279
payment_token,
12761280
connector,
12771281
straight_through_algorithm,
1282+
amount_capturable,
12781283
} => Self::UpdateTrackers {
12791284
payment_token,
12801285
connector,
12811286
straight_through_algorithm,
1287+
amount_capturable,
12821288
},
12831289
DieselPaymentAttemptUpdate::AuthenticationTypeUpdate {
12841290
authentication_type,
@@ -1301,6 +1307,7 @@ impl DataModelExt for PaymentAttemptUpdate {
13011307
straight_through_algorithm,
13021308
error_code,
13031309
error_message,
1310+
amount_capturable,
13041311
} => Self::ConfirmUpdate {
13051312
amount,
13061313
currency,
@@ -1317,6 +1324,7 @@ impl DataModelExt for PaymentAttemptUpdate {
13171324
straight_through_algorithm,
13181325
error_code,
13191326
error_message,
1327+
amount_capturable,
13201328
},
13211329
DieselPaymentAttemptUpdate::VoidUpdate {
13221330
status,

0 commit comments

Comments
 (0)