Skip to content

Commit

Permalink
chnages in cybersource to supporte mandatepayment
Browse files Browse the repository at this point in the history
  • Loading branch information
Aprabhat19 committed Jan 2, 2024
1 parent 71e490e commit 989fe6c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ connectors_with_webhook_source_verification_call = "paypal"

[mandates.supported_payment_methods]
pay_later.klarna = { connector_list = "adyen" }
wallet.google_pay = { connector_list = "stripe,adyen" }
wallet.apple_pay = { connector_list = "stripe,adyen" }
wallet.google_pay = { connector_list = "stripe,adyen,cybersource" }
wallet.apple_pay = { connector_list = "stripe,adyen,cybersource,noon" }
wallet.paypal = { connector_list = "adyen" }
card.credit = { connector_list = "stripe,adyen,authorizedotnet,cybersource,globalpay,worldpay,multisafepay,nmi,nexinets,noon" }
card.debit = { connector_list = "stripe,adyen,authorizedotnet,cybersource,globalpay,worldpay,multisafepay,nmi,nexinets,noon" }
Expand Down
54 changes: 45 additions & 9 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl TryFrom<&types::SetupMandateRouterData> for CybersourceZeroMandateRequest {
});
PaymentInformation::Cards(CardPaymentInformation {
card,
instrument_identifier: None,
payment_instrument: None,
})
}
_ => Err(errors::ConnectorError::NotImplemented(
Expand Down Expand Up @@ -217,7 +217,7 @@ pub struct CaptureOptions {
#[serde(rename_all = "camelCase")]
pub struct CardPaymentInformation {
card: CardDetails,
instrument_identifier: Option<CybersoucreInstrumentIdentifier>,
payment_instrument: Option<CybersoucreInstrumentIdentifier>,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -249,6 +249,12 @@ pub struct ApplePayPaymentInformation {
tokenized_card: TokenizedCard,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MandatePaymentInformation {
payment_instrument: Option<CybersoucreInstrumentIdentifier>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FluidData {
Expand All @@ -268,6 +274,7 @@ pub enum PaymentInformation {
GooglePay(GooglePayPaymentInformation),
ApplePay(ApplePayPaymentInformation),
ApplePayToken(ApplePayTokenPaymentInformation),
MandatePayment(MandatePaymentInformation),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -507,15 +514,15 @@ impl
Err(_) => None,
};

let instrument_identifier =
let payment_instrument =
item.router_data
.request
.connector_mandate_id()
.map(|mandate_token_id| CybersoucreInstrumentIdentifier {
id: mandate_token_id,
});

let card = if instrument_identifier.is_some() {
let card = if payment_instrument.is_some() {
CardDetails::MandateCard(MandateCardDetails {
expiration_month: ccard.card_exp_month,
expiration_year: ccard.card_exp_year,
Expand All @@ -532,7 +539,7 @@ impl

let payment_information = PaymentInformation::Cards(CardPaymentInformation {
card,
instrument_identifier,
payment_instrument,
});
let processing_information = ProcessingInformation::from((item, None));
let client_reference_information = ClientReferenceInformation::from(item);
Expand Down Expand Up @@ -726,13 +733,42 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsAuthorizeRouterData>>
)
.into()),
},
payments::PaymentMethodData::MandatePayment => {
let processing_information = ProcessingInformation::from((item, None));
let payment_instrument =
item.router_data
.request
.connector_mandate_id()
.map(|mandate_token_id| CybersoucreInstrumentIdentifier {
id: mandate_token_id,
});

let email = item.router_data.request.get_email()?;
let bill_to = build_bill_to(item.router_data.get_billing()?, email)?;
let order_information = OrderInformationWithBill::from((item, bill_to));
let payment_information =
PaymentInformation::MandatePayment(MandatePaymentInformation {
payment_instrument,
});
let client_reference_information = ClientReferenceInformation::from(item);
let merchant_defined_information =
item.router_data.request.metadata.clone().map(|metadata| {
Vec::<MerchantDefinedInformation>::foreign_from(metadata.peek().to_owned())
});
Ok(Self {
processing_information,
payment_information,
order_information,
client_reference_information,
merchant_defined_information,
})
}
payments::PaymentMethodData::CardRedirect(_)
| payments::PaymentMethodData::PayLater(_)
| payments::PaymentMethodData::BankRedirect(_)
| payments::PaymentMethodData::BankDebit(_)
| payments::PaymentMethodData::BankTransfer(_)
| payments::PaymentMethodData::Crypto(_)
| payments::PaymentMethodData::MandatePayment
| payments::PaymentMethodData::Reward
| payments::PaymentMethodData::Upi(_)
| payments::PaymentMethodData::Voucher(_)
Expand Down Expand Up @@ -1038,7 +1074,7 @@ pub struct ClientReferenceInformation {
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CybersourceTokenInformation {
instrument_identifier: CybersoucreInstrumentIdentifier,
payment_instrument: CybersoucreInstrumentIdentifier,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -1161,7 +1197,7 @@ fn get_payment_response(
.token_information
.clone()
.map(|token_info| types::MandateReference {
connector_mandate_id: Some(token_info.instrument_identifier.id),
connector_mandate_id: Some(token_info.payment_instrument.id),
payment_method_id: None,
});
Ok(types::PaymentsResponseData::TransactionResponse {
Expand Down Expand Up @@ -1331,7 +1367,7 @@ impl<F, T>
item.response
.token_information
.map(|token_info| types::MandateReference {
connector_mandate_id: Some(token_info.instrument_identifier.id),
connector_mandate_id: Some(token_info.payment_instrument.id),
payment_method_id: None,
});
let mut mandate_status = enums::AttemptStatus::foreign_from((item.response.status, false));
Expand Down
8 changes: 6 additions & 2 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,11 @@ where
.unwrap_or(false);

let payment_data_and_tokenization_action = match connector {
Some(connector) if !is_mandate && is_operation_confirm(&operation) => {
Some(_) if is_mandate => (
payment_data.to_owned(),
TokenizationAction::SkipConnectorTokenization,
),
Some(connector) if is_operation_confirm(&operation) => {
let payment_method = &payment_data
.payment_attempt
.payment_method
Expand Down Expand Up @@ -1852,7 +1856,7 @@ where
};
(payment_data.to_owned(), connector_tokenization_action)
}
Some(_) | None => (
_ => (
payment_data.to_owned(),
TokenizationAction::SkipConnectorTokenization,
),
Expand Down

0 comments on commit 989fe6c

Please sign in to comment.