Skip to content

Commit 42261a5

Browse files
fix: null fields in payments respose (#2745)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 09c3e17 commit 42261a5

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

crates/data_models/src/payments/payment_intent.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -215,35 +215,6 @@ pub struct PaymentIntentUpdateInternal {
215215
pub surcharge_applicable: Option<bool>,
216216
}
217217

218-
impl PaymentIntentUpdate {
219-
pub fn apply_changeset(self, source: PaymentIntent) -> PaymentIntent {
220-
let internal_update: PaymentIntentUpdateInternal = self.into();
221-
PaymentIntent {
222-
amount: internal_update.amount.unwrap_or(source.amount),
223-
currency: internal_update.currency.or(source.currency),
224-
status: internal_update.status.unwrap_or(source.status),
225-
amount_captured: internal_update.amount_captured.or(source.amount_captured),
226-
customer_id: internal_update.customer_id.or(source.customer_id),
227-
return_url: internal_update.return_url.or(source.return_url),
228-
setup_future_usage: internal_update
229-
.setup_future_usage
230-
.or(source.setup_future_usage),
231-
off_session: internal_update.off_session.or(source.off_session),
232-
metadata: internal_update.metadata.or(source.metadata),
233-
billing_address_id: internal_update
234-
.billing_address_id
235-
.or(source.billing_address_id),
236-
shipping_address_id: internal_update
237-
.shipping_address_id
238-
.or(source.shipping_address_id),
239-
modified_at: common_utils::date_time::now(),
240-
order_details: internal_update.order_details.or(source.order_details),
241-
updated_by: internal_update.updated_by,
242-
..source
243-
}
244-
}
245-
}
246-
247218
impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
248219
fn from(payment_intent_update: PaymentIntentUpdate) -> Self {
249220
match payment_intent_update {

crates/storage_impl/src/mock_db/payment_intent.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use diesel_models::enums as storage_enums;
1111
use error_stack::{IntoReport, ResultExt};
1212

1313
use super::MockDb;
14+
use crate::DataModelExt;
1415

1516
#[async_trait::async_trait]
1617
impl PaymentIntentInterface for MockDb {
@@ -123,7 +124,11 @@ impl PaymentIntentInterface for MockDb {
123124
.iter_mut()
124125
.find(|item| item.id == this.id)
125126
.unwrap();
126-
*payment_intent = update.apply_changeset(this);
127+
*payment_intent = PaymentIntent::from_storage_model(
128+
update
129+
.to_storage_model()
130+
.apply_changeset(this.to_storage_model()),
131+
);
127132
Ok(payment_intent.clone())
128133
}
129134

crates/storage_impl/src/payments/payment_intent.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
146146
let key = format!("mid_{}_pid_{}", this.merchant_id, this.payment_id);
147147
let field = format!("pi_{}", this.payment_id);
148148

149-
let updated_intent = payment_intent_update.clone().apply_changeset(this.clone());
150-
let diesel_intent = updated_intent.clone().to_storage_model();
149+
let diesel_intent_update = payment_intent_update.to_storage_model();
150+
let origin_diesel_intent = this.to_storage_model();
151+
152+
let diesel_intent = diesel_intent_update
153+
.clone()
154+
.apply_changeset(origin_diesel_intent.clone());
151155
// Check for database presence as well Maybe use a read replica here ?
152156

153157
let redis_value =
@@ -158,8 +162,8 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
158162
op: kv::DBOperation::Update {
159163
updatable: kv::Updateable::PaymentIntentUpdate(
160164
kv::PaymentIntentUpdateMems {
161-
orig: this.to_storage_model(),
162-
update_data: payment_intent_update.to_storage_model(),
165+
orig: origin_diesel_intent,
166+
update_data: diesel_intent_update,
163167
},
164168
),
165169
},
@@ -175,7 +179,7 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
175179
.try_into_hset()
176180
.change_context(StorageError::KVError)?;
177181

178-
Ok(updated_intent)
182+
Ok(PaymentIntent::from_storage_model(diesel_intent))
179183
}
180184
}
181185
}

0 commit comments

Comments
 (0)