mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
feat(router): add an api to migrate the payment method (#5186)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -75,6 +75,128 @@ pub struct PaymentMethodCreate {
|
||||
/// Payment method data to be passed in case of client
|
||||
/// based flow
|
||||
pub payment_method_data: Option<PaymentMethodCreateData>,
|
||||
|
||||
/// The billing details of the payment method
|
||||
#[schema(value_type = Option<Address>)]
|
||||
pub billing: Option<payments::Address>,
|
||||
|
||||
#[serde(skip_deserializing)]
|
||||
/// The connector mandate details of the payment method, this is added only for cards migration
|
||||
/// api and is skipped during deserialization of the payment method create request as this
|
||||
/// it should not be passed in the request
|
||||
pub connector_mandate_details: Option<PaymentsMandateReference>,
|
||||
|
||||
#[serde(skip_deserializing)]
|
||||
/// The transaction id of a CIT (customer initiated transaction) associated with the payment method,
|
||||
/// this is added only for cards migration api and is skipped during deserialization of the
|
||||
/// payment method create request as it should not be passed in the request
|
||||
pub network_transaction_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||
/// This struct is only used by and internal api to migrate payment method
|
||||
pub struct PaymentMethodMigrate {
|
||||
/// Merchant id
|
||||
pub merchant_id: String,
|
||||
|
||||
/// The type of payment method use for the payment.
|
||||
pub payment_method: Option<api_enums::PaymentMethod>,
|
||||
|
||||
/// This is a sub-category of payment method.
|
||||
pub payment_method_type: Option<api_enums::PaymentMethodType>,
|
||||
|
||||
/// The name of the bank/ provider issuing the payment method to the end user
|
||||
pub payment_method_issuer: Option<String>,
|
||||
|
||||
/// A standard code representing the issuer of payment method
|
||||
pub payment_method_issuer_code: Option<api_enums::PaymentMethodIssuerCode>,
|
||||
|
||||
/// Card Details
|
||||
pub card: Option<MigrateCardDetail>,
|
||||
|
||||
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
|
||||
/// The unique identifier of the customer.
|
||||
pub customer_id: Option<id_type::CustomerId>,
|
||||
|
||||
/// The card network
|
||||
pub card_network: Option<String>,
|
||||
|
||||
/// Payment method details from locker
|
||||
#[cfg(feature = "payouts")]
|
||||
pub bank_transfer: Option<payouts::Bank>,
|
||||
|
||||
/// Payment method details from locker
|
||||
#[cfg(feature = "payouts")]
|
||||
pub wallet: Option<payouts::Wallet>,
|
||||
|
||||
/// Payment method data to be passed in case of client
|
||||
/// based flow
|
||||
pub payment_method_data: Option<PaymentMethodCreateData>,
|
||||
|
||||
/// The billing details of the payment method
|
||||
pub billing: Option<payments::Address>,
|
||||
|
||||
/// The connector mandate details of the payment method
|
||||
pub connector_mandate_details: Option<PaymentsMandateReference>,
|
||||
|
||||
// The CIT (customer initiated transaction) transaction id associated with the payment method
|
||||
pub network_transaction_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct PaymentsMandateReference(pub HashMap<String, PaymentsMandateReferenceRecord>);
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct PaymentsMandateReferenceRecord {
|
||||
pub connector_mandate_id: String,
|
||||
pub payment_method_type: Option<common_enums::PaymentMethodType>,
|
||||
pub original_payment_authorized_amount: Option<i64>,
|
||||
pub original_payment_authorized_currency: Option<common_enums::Currency>,
|
||||
}
|
||||
|
||||
impl PaymentMethodCreate {
|
||||
pub fn get_payment_method_create_from_payment_method_migrate(
|
||||
card_number: CardNumber,
|
||||
payment_method_migrate: &PaymentMethodMigrate,
|
||||
) -> Self {
|
||||
let card_details =
|
||||
payment_method_migrate
|
||||
.card
|
||||
.as_ref()
|
||||
.map(|payment_method_migrate_card| CardDetail {
|
||||
card_number,
|
||||
card_exp_month: payment_method_migrate_card.card_exp_month.clone(),
|
||||
card_exp_year: payment_method_migrate_card.card_exp_year.clone(),
|
||||
card_holder_name: payment_method_migrate_card.card_holder_name.clone(),
|
||||
nick_name: payment_method_migrate_card.nick_name.clone(),
|
||||
card_issuing_country: payment_method_migrate_card.card_issuing_country.clone(),
|
||||
card_network: payment_method_migrate_card.card_network.clone(),
|
||||
card_issuer: payment_method_migrate_card.card_issuer.clone(),
|
||||
card_type: payment_method_migrate_card.card_type.clone(),
|
||||
});
|
||||
|
||||
Self {
|
||||
customer_id: payment_method_migrate.customer_id.clone(),
|
||||
payment_method: payment_method_migrate.payment_method,
|
||||
payment_method_type: payment_method_migrate.payment_method_type,
|
||||
payment_method_issuer: payment_method_migrate.payment_method_issuer.clone(),
|
||||
payment_method_issuer_code: payment_method_migrate.payment_method_issuer_code,
|
||||
metadata: payment_method_migrate.metadata.clone(),
|
||||
payment_method_data: payment_method_migrate.payment_method_data.clone(),
|
||||
connector_mandate_details: payment_method_migrate.connector_mandate_details.clone(),
|
||||
client_secret: None,
|
||||
billing: payment_method_migrate.billing.clone(),
|
||||
card: card_details,
|
||||
card_network: payment_method_migrate.card_network.clone(),
|
||||
#[cfg(feature = "payouts")]
|
||||
bank_transfer: payment_method_migrate.bank_transfer.clone(),
|
||||
#[cfg(feature = "payouts")]
|
||||
wallet: payment_method_migrate.wallet.clone(),
|
||||
network_transaction_id: payment_method_migrate.network_transaction_id.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||
@ -139,6 +261,43 @@ pub struct CardDetail {
|
||||
pub card_type: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct MigrateCardDetail {
|
||||
/// Card Number
|
||||
#[schema(value_type = String,example = "4111111145551142")]
|
||||
pub card_number: masking::Secret<String>,
|
||||
|
||||
/// Card Expiry Month
|
||||
#[schema(value_type = String,example = "10")]
|
||||
pub card_exp_month: masking::Secret<String>,
|
||||
|
||||
/// Card Expiry Year
|
||||
#[schema(value_type = String,example = "25")]
|
||||
pub card_exp_year: masking::Secret<String>,
|
||||
|
||||
/// Card Holder Name
|
||||
#[schema(value_type = String,example = "John Doe")]
|
||||
pub card_holder_name: Option<masking::Secret<String>>,
|
||||
|
||||
/// Card Holder's Nick Name
|
||||
#[schema(value_type = Option<String>,example = "John Doe")]
|
||||
pub nick_name: Option<masking::Secret<String>>,
|
||||
|
||||
/// Card Issuing Country
|
||||
pub card_issuing_country: Option<String>,
|
||||
|
||||
/// Card's Network
|
||||
#[schema(value_type = Option<CardNetwork>)]
|
||||
pub card_network: Option<api_enums::CardNetwork>,
|
||||
|
||||
/// Issuer Bank for Card
|
||||
pub card_issuer: Option<String>,
|
||||
|
||||
/// Card Type
|
||||
pub card_type: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CardDetailUpdate {
|
||||
|
||||
Reference in New Issue
Block a user