feat(connector): [Paybox] Add mandates Flow for Paybox (#6378)

This commit is contained in:
awasthi21
2024-10-30 21:32:59 +05:30
committed by GitHub
parent c514608594
commit 37513e0f1e
55 changed files with 728 additions and 152 deletions

View File

@ -80,6 +80,7 @@ pub async fn save_payment_method<FData>(
billing_name: Option<Secret<String>>,
payment_method_billing_address: Option<&api::Address>,
business_profile: &domain::Profile,
mut original_connector_mandate_reference_id: Option<ConnectorMandateReferenceId>,
) -> RouterResult<SavePaymentMethodDataResponse>
where
FData: mandate::MandateBehaviour + Clone,
@ -155,21 +156,23 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to serialize customer acceptance to value")?;
let (connector_mandate_id, mandate_metadata) = match responses {
types::PaymentsResponseData::TransactionResponse {
mandate_reference, ..
} => {
if let Some(ref mandate_ref) = *mandate_reference {
(
mandate_ref.connector_mandate_id.clone(),
mandate_ref.mandate_metadata.clone(),
)
} else {
(None, None)
let (connector_mandate_id, mandate_metadata, connector_mandate_request_reference_id) =
match responses {
types::PaymentsResponseData::TransactionResponse {
mandate_reference, ..
} => {
if let Some(ref mandate_ref) = *mandate_reference {
(
mandate_ref.connector_mandate_id.clone(),
mandate_ref.mandate_metadata.clone(),
mandate_ref.connector_mandate_request_reference_id.clone(),
)
} else {
(None, None, None)
}
}
}
_ => (None, None),
};
_ => (None, None, None),
};
let pm_id = if customer_acceptance.is_some() {
let payment_method_create_request =
@ -689,12 +692,24 @@ where
};
// check if there needs to be a config if yes then remove it to a different place
let connector_mandate_reference_id = if connector_mandate_id.is_some() {
Some(ConnectorMandateReferenceId {
connector_mandate_id: connector_mandate_id.clone(),
payment_method_id: None,
update_history: None,
mandate_metadata: mandate_metadata.clone(),
})
if let Some(ref mut record) = original_connector_mandate_reference_id {
record.update(
connector_mandate_id,
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
);
Some(record.clone())
} else {
Some(ConnectorMandateReferenceId::new(
connector_mandate_id,
None,
None,
mandate_metadata,
connector_mandate_request_reference_id,
))
}
} else {
None
};
@ -728,6 +743,7 @@ pub async fn save_payment_method<FData>(
_billing_name: Option<Secret<String>>,
_payment_method_billing_address: Option<&api::Address>,
_business_profile: &domain::Profile,
_connector_mandate_request_reference_id: Option<String>,
) -> RouterResult<SavePaymentMethodDataResponse>
where
FData: mandate::MandateBehaviour + Clone,
@ -1134,6 +1150,7 @@ pub fn add_connector_mandate_details_in_payment_method(
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
connector_mandate_id: Option<String>,
mandate_metadata: Option<serde_json::Value>,
connector_mandate_request_reference_id: Option<String>,
) -> Option<storage::PaymentsMandateReference> {
let mut mandate_details = HashMap::new();
@ -1149,6 +1166,7 @@ pub fn add_connector_mandate_details_in_payment_method(
original_payment_authorized_currency: authorized_currency,
mandate_metadata,
connector_mandate_status: Some(ConnectorMandateStatus::Active),
connector_mandate_request_reference_id,
},
);
Some(storage::PaymentsMandateReference(mandate_details))
@ -1156,7 +1174,7 @@ pub fn add_connector_mandate_details_in_payment_method(
None
}
}
#[allow(clippy::too_many_arguments)]
pub fn update_connector_mandate_details(
mandate_details: Option<storage::PaymentsMandateReference>,
payment_method_type: Option<storage_enums::PaymentMethodType>,
@ -1165,6 +1183,7 @@ pub fn update_connector_mandate_details(
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
connector_mandate_id: Option<String>,
mandate_metadata: Option<serde_json::Value>,
connector_mandate_request_reference_id: Option<String>,
) -> RouterResult<Option<serde_json::Value>> {
let mandate_reference = match mandate_details {
Some(mut payment_mandate_reference) => {
@ -1178,6 +1197,8 @@ pub fn update_connector_mandate_details(
original_payment_authorized_currency: authorized_currency,
mandate_metadata: mandate_metadata.clone(),
connector_mandate_status: Some(ConnectorMandateStatus::Active),
connector_mandate_request_reference_id: connector_mandate_request_reference_id
.clone(),
};
payment_mandate_reference
@ -1190,6 +1211,7 @@ pub fn update_connector_mandate_details(
original_payment_authorized_currency: authorized_currency,
mandate_metadata: mandate_metadata.clone(),
connector_mandate_status: Some(ConnectorMandateStatus::Active),
connector_mandate_request_reference_id,
});
Some(payment_mandate_reference)
} else {
@ -1203,6 +1225,7 @@ pub fn update_connector_mandate_details(
merchant_connector_id,
connector_mandate_id,
mandate_metadata,
connector_mandate_request_reference_id,
),
};
let connector_mandate_details = mandate_reference