Skip to content

Commit 064113a

Browse files
feat(connector): add apple pay decrypt support for Adyen (#8605)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent 871c082 commit 064113a

File tree

4 files changed

+61
-22
lines changed

4 files changed

+61
-22
lines changed

crates/connector_configs/toml/development.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ label="Payment Processing Details At"
286286
placeholder="Enter Payment Processing Details At"
287287
required=true
288288
type="Radio"
289-
options=["Connector"]
289+
options=["Connector", "Hyperswitch"]
290290

291291
[[adyen.metadata.google_pay]]
292292
name="merchant_name"

crates/connector_configs/toml/production.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ label="Payment Processing Details At"
192192
placeholder="Enter Payment Processing Details At"
193193
required=true
194194
type="Radio"
195-
options=["Connector"]
195+
options=["Connector", "Hyperswitch"]
196196

197197
[[adyen.metadata.google_pay]]
198198
name="merchant_name"

crates/connector_configs/toml/sandbox.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ label="Payment Processing Details At"
284284
placeholder="Enter Payment Processing Details At"
285285
required=true
286286
type="Radio"
287-
options=["Connector"]
287+
options=["Connector", "Hyperswitch"]
288288

289289
[[adyen.metadata.google_pay]]
290290
name="merchant_name"

crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ use crate::{
5757
SubmitEvidenceRouterData,
5858
},
5959
utils::{
60-
self, is_manual_capture, missing_field_err, AddressDetailsData, BrowserInformationData,
61-
CardData, ForeignTryFrom, NetworkTokenData as UtilsNetworkTokenData,
62-
PaymentsAuthorizeRequestData, PhoneDetailsData, RouterData as OtherRouterData,
60+
self, is_manual_capture, missing_field_err, AddressDetailsData, ApplePayDecrypt,
61+
BrowserInformationData, CardData, ForeignTryFrom,
62+
NetworkTokenData as UtilsNetworkTokenData, PaymentsAuthorizeRequestData, PhoneDetailsData,
63+
RouterData as OtherRouterData,
6364
},
6465
};
6566

@@ -309,7 +310,8 @@ struct AdyenSplitData {
309310
struct AdyenMpiData {
310311
directory_response: String,
311312
authentication_response: String,
312-
token_authentication_verification_value: Secret<String>,
313+
cavv: Option<Secret<String>>,
314+
token_authentication_verification_value: Option<Secret<String>>,
313315
eci: Option<String>,
314316
}
315317

@@ -675,6 +677,7 @@ pub enum AdyenPaymentMethod<'a> {
675677
#[serde(rename = "alipay_hk")]
676678
AliPayHk,
677679
ApplePay(Box<AdyenApplePay>),
680+
ApplePayDecrypt(Box<AdyenApplePayDecryptData>),
678681
Atome,
679682
#[serde(rename = "scheme")]
680683
BancontactCard(Box<AdyenCard>),
@@ -1253,6 +1256,18 @@ pub struct AdyenPazeData {
12531256
network_payment_reference: Option<Secret<String>>,
12541257
}
12551258

1259+
#[serde_with::skip_serializing_none]
1260+
#[derive(Debug, Clone, Serialize, Deserialize)]
1261+
#[serde(rename_all = "camelCase")]
1262+
pub struct AdyenApplePayDecryptData {
1263+
number: Secret<String>,
1264+
expiry_month: Secret<String>,
1265+
expiry_year: Secret<String>,
1266+
brand: String,
1267+
#[serde(rename = "type")]
1268+
payment_type: PaymentType,
1269+
}
1270+
12561271
#[derive(Debug, Clone, Serialize, Deserialize)]
12571272
#[serde(rename_all = "lowercase")]
12581273
pub enum CardBrand {
@@ -2194,11 +2209,27 @@ impl TryFrom<(&WalletData, &PaymentsAuthorizeRouterData)> for AdyenPaymentMethod
21942209
Ok(AdyenPaymentMethod::Gpay(Box::new(gpay_data)))
21952210
}
21962211
WalletData::ApplePay(data) => {
2197-
let apple_pay_data = AdyenApplePay {
2198-
apple_pay_token: Secret::new(data.payment_data.to_string()),
2199-
};
2200-
2201-
Ok(AdyenPaymentMethod::ApplePay(Box::new(apple_pay_data)))
2212+
if let Some(PaymentMethodToken::ApplePayDecrypt(apple_pay_decrypte)) =
2213+
item.payment_method_token.clone()
2214+
{
2215+
let expiry_year_4_digit = apple_pay_decrypte.get_four_digit_expiry_year()?;
2216+
let exp_month = apple_pay_decrypte.get_expiry_month()?;
2217+
let apple_pay_decrypted_data = AdyenApplePayDecryptData {
2218+
number: apple_pay_decrypte.application_primary_account_number,
2219+
expiry_month: exp_month,
2220+
expiry_year: expiry_year_4_digit,
2221+
brand: "applepay".to_string(),
2222+
payment_type: PaymentType::Scheme,
2223+
};
2224+
Ok(AdyenPaymentMethod::ApplePayDecrypt(Box::new(
2225+
apple_pay_decrypted_data,
2226+
)))
2227+
} else {
2228+
let apple_pay_data = AdyenApplePay {
2229+
apple_pay_token: Secret::new(data.payment_data.to_string()),
2230+
};
2231+
Ok(AdyenPaymentMethod::ApplePay(Box::new(apple_pay_data)))
2232+
}
22022233
}
22032234
WalletData::PaypalRedirect(_) => Ok(AdyenPaymentMethod::AdyenPaypal),
22042235
WalletData::AliPayRedirect(_) => Ok(AdyenPaymentMethod::AliPay),
@@ -3428,15 +3459,23 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &WalletData)>
34283459
let shopper_email = get_shopper_email(item.router_data, store_payment_method.is_some())?;
34293460
let billing_address =
34303461
get_address_info(item.router_data.get_optional_billing()).and_then(Result::ok);
3431-
let mpi_data = if let WalletData::Paze(_) = wallet_data {
3462+
let mpi_data = if matches!(wallet_data, WalletData::Paze(_) | WalletData::ApplePay(_)) {
34323463
match item.router_data.payment_method_token.clone() {
3433-
Some(PaymentMethodToken::PazeDecrypt(paze_decrypted_data)) => Some(AdyenMpiData {
3464+
Some(PaymentMethodToken::PazeDecrypt(paze_data)) => Some(AdyenMpiData {
34343465
directory_response: "Y".to_string(),
34353466
authentication_response: "Y".to_string(),
3436-
token_authentication_verification_value: paze_decrypted_data
3437-
.token
3438-
.payment_account_reference,
3439-
eci: paze_decrypted_data.eci,
3467+
cavv: None,
3468+
token_authentication_verification_value: Some(
3469+
paze_data.token.payment_account_reference,
3470+
),
3471+
eci: paze_data.eci,
3472+
}),
3473+
Some(PaymentMethodToken::ApplePayDecrypt(apple_data)) => Some(AdyenMpiData {
3474+
directory_response: "Y".to_string(),
3475+
authentication_response: "Y".to_string(),
3476+
cavv: Some(apple_data.payment_data.online_payment_cryptogram),
3477+
token_authentication_verification_value: None,
3478+
eci: apple_data.payment_data.eci_indicator,
34403479
}),
34413480
_ => None,
34423481
}
@@ -5854,10 +5893,10 @@ impl
58545893
let mpi_data = AdyenMpiData {
58555894
directory_response: "Y".to_string(),
58565895
authentication_response: "Y".to_string(),
5857-
token_authentication_verification_value: token_data
5858-
.get_cryptogram()
5859-
.clone()
5860-
.unwrap_or_default(),
5896+
cavv: None,
5897+
token_authentication_verification_value: Some(
5898+
token_data.get_cryptogram().clone().unwrap_or_default(),
5899+
),
58615900
eci: Some("02".to_string()),
58625901
};
58635902
let (store, splits) = match item.router_data.request.split_payments.as_ref() {

0 commit comments

Comments
 (0)