Skip to content

Commit

Permalink
feat(core): [Paypal] Add session_token flow for Paypal sdk (#4697)
Browse files Browse the repository at this point in the history
Co-authored-by: swangi-kumari <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 27, 2024
1 parent 8d9c7bc commit b3d4d13
Show file tree
Hide file tree
Showing 28 changed files with 526 additions and 102 deletions.
40 changes: 36 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2939,13 +2939,17 @@ pub enum NextActionType {
#[serde(tag = "type", rename_all = "snake_case")]
pub enum NextActionData {
/// Contains the url for redirection flow
RedirectToUrl { redirect_to_url: String },
RedirectToUrl {
redirect_to_url: String,
},
/// Informs the next steps for bank transfer and also contains the charges details (ex: amount received, amount charged etc)
DisplayBankTransferInformation {
bank_transfer_steps_and_charges_details: BankTransferNextStepsData,
},
/// Contains third party sdk session token response
ThirdPartySdkSessionToken { session_token: Option<SessionToken> },
ThirdPartySdkSessionToken {
session_token: Option<SessionToken>,
},
/// Contains url for Qr code image, this qr code has to be shown in sdk
QrCodeInformation {
#[schema(value_type = String)]
Expand All @@ -2967,7 +2971,12 @@ pub enum NextActionData {
display_to_timestamp: Option<i128>,
},
/// Contains the information regarding three_ds_method_data submission, three_ds authentication, and authorization flows
ThreeDsInvoke { three_ds_data: ThreeDsData },
ThreeDsInvoke {
three_ds_data: ThreeDsData,
},
InvokeSdkClient {
next_action_data: SdkNextActionData,
},
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -3030,6 +3039,12 @@ pub enum QrCodeInformation {
},
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct SdkNextActionData {
pub next_action: NextActionCall,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct BankTransferNextStepsData {
/// The instructions for performing a bank transfer
Expand Down Expand Up @@ -4030,6 +4045,17 @@ pub struct GpaySessionTokenData {
pub data: GpayMetaData,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaypalSdkMetaData {
pub client_id: String,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaypalSdkSessionTokenData {
#[serde(rename = "paypal_sdk")]
pub data: PaypalSdkMetaData,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApplepaySessionRequest {
Expand Down Expand Up @@ -4207,8 +4233,12 @@ pub struct KlarnaSessionTokenResponse {
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub struct PaypalSessionTokenResponse {
/// Name of the connector
pub connector: String,
/// The session token for PayPal
pub session_token: String,
/// The next action for the sdk (ex: calling confirm or sync call)
pub sdk_next_action: SdkNextAction,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -4238,13 +4268,15 @@ pub struct SdkNextAction {
pub next_action: NextActionCall,
}

#[derive(Debug, Eq, PartialEq, serde::Serialize, Clone, ToSchema)]
#[derive(Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum NextActionCall {
/// The next action call is confirm
Confirm,
/// The next action call is sync
Sync,
/// The next action call is Complete Authorize
CompleteAuthorize,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema)]
Expand Down
8 changes: 8 additions & 0 deletions crates/connector_configs/src/common_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ pub enum GooglePayData {
Zen(ZenGooglePay),
}

#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaypalSdkData {
pub client_id: Option<String>,
}

#[serde_with::skip_serializing_none]
#[derive(Debug, Deserialize, serde::Serialize, Clone)]
#[serde(untagged)]
Expand All @@ -79,6 +85,7 @@ pub struct ApiModelMetaData {
pub terminal_id: Option<String>,
pub merchant_id: Option<String>,
pub google_pay: Option<GoogleApiModelData>,
pub paypal_sdk: Option<PaypalSdkData>,
pub apple_pay: Option<ApplePayData>,
pub apple_pay_combined: Option<ApplePayData>,
pub endpoint_prefix: Option<String>,
Expand Down Expand Up @@ -180,6 +187,7 @@ pub struct DashboardMetaData {
pub terminal_id: Option<String>,
pub merchant_id: Option<String>,
pub google_pay: Option<GooglePayData>,
pub paypal_sdk: Option<PaypalSdkData>,
pub apple_pay: Option<ApplePayData>,
pub apple_pay_combined: Option<ApplePayData>,
pub endpoint_prefix: Option<String>,
Expand Down
3 changes: 2 additions & 1 deletion crates/connector_configs/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Deserialize;
#[cfg(any(feature = "sandbox", feature = "development", feature = "production"))]
use toml;

use crate::common_config::{CardProvider, GooglePayData, Provider, ZenApplePay};
use crate::common_config::{CardProvider, GooglePayData, PaypalSdkData, Provider, ZenApplePay};

#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Classic {
Expand Down Expand Up @@ -79,6 +79,7 @@ pub struct ConfigMetadata {
pub account_name: Option<String>,
pub terminal_id: Option<String>,
pub google_pay: Option<GooglePayData>,
pub paypal_sdk: Option<PaypalSdkData>,
pub apple_pay: Option<ApplePayTomlConfig>,
pub merchant_id: Option<String>,
pub endpoint_prefix: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions crates/connector_configs/src/response_modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl From<ApiModelMetaData> for DashboardMetaData {
terminal_id: api_model.terminal_id,
merchant_id: api_model.merchant_id,
google_pay: get_google_pay_metadata_response(api_model.google_pay),
paypal_sdk: api_model.paypal_sdk,
apple_pay: api_model.apple_pay,
apple_pay_combined: api_model.apple_pay_combined,
endpoint_prefix: api_model.endpoint_prefix,
Expand Down
7 changes: 6 additions & 1 deletion crates/connector_configs/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ impl DashboardRequestPayload {
(Connector::Zen, GooglePay) | (Connector::Zen, ApplePay) => {
Some(api_models::enums::PaymentExperience::RedirectToUrl)
}
(Connector::Braintree, Paypal) | (Connector::Klarna, Klarna) => {
(Connector::Paypal, Paypal)
| (Connector::Braintree, Paypal)
| (Connector::Klarna, Klarna) => {
Some(api_models::enums::PaymentExperience::InvokeSdkClient)
}
(Connector::Globepay, AliPay)
Expand Down Expand Up @@ -194,6 +196,7 @@ impl DashboardRequestPayload {
three_ds_requestor_name: None,
three_ds_requestor_id: None,
pull_mechanism_for_external_3ds_enabled: None,
paypal_sdk: None,
};
let meta_data = match request.metadata {
Some(data) => data,
Expand All @@ -205,6 +208,7 @@ impl DashboardRequestPayload {
let merchant_id = meta_data.merchant_id.clone();
let terminal_id = meta_data.terminal_id.clone();
let endpoint_prefix = meta_data.endpoint_prefix.clone();
let paypal_sdk = meta_data.paypal_sdk;
let apple_pay = meta_data.apple_pay;
let apple_pay_combined = meta_data.apple_pay_combined;
let merchant_config_currency = meta_data.merchant_config_currency;
Expand All @@ -228,6 +232,7 @@ impl DashboardRequestPayload {
merchant_config_currency,
apple_pay_combined,
endpoint_prefix,
paypal_sdk,
mcc,
merchant_country_code,
merchant_name,
Expand Down
2 changes: 2 additions & 0 deletions crates/connector_configs/toml/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,8 @@ api_key="Client Secret"
key1="Client ID"
[paypal.connector_webhook_details]
merchant_secret="Source verification key"
[paypal.metadata.paypal_sdk]
client_id="Client ID"

[paypal_payout]
[[paypal.wallet]]
Expand Down
2 changes: 2 additions & 0 deletions crates/connector_configs/toml/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,8 @@ api_key="Client Secret"
key1="Client ID"
[paypal.connector_webhook_details]
merchant_secret="Source verification key"
[paypal.metadata.paypal_sdk]
client_id="Client ID"

[payu]
[[payu.credit]]
Expand Down
2 changes: 2 additions & 0 deletions crates/connector_configs/toml/sandbox.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,8 @@ api_key="Client Secret"
key1="Client ID"
[paypal.connector_webhook_details]
merchant_secret="Source verification key"
[paypal.metadata.paypal_sdk]
client_id="Client ID"

[paypal_payout]
[[paypal.wallet]]
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::ApplepaySessionTokenResponse,
api_models::payments::SdkNextAction,
api_models::payments::NextActionCall,
api_models::payments::SdkNextActionData,
api_models::payments::SamsungPayWalletData,
api_models::payments::WeChatPay,
api_models::payments::GpayTokenizationData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ pub enum StripeNextAction {
display_from_timestamp: i128,
display_to_timestamp: Option<i128>,
},
InvokeSdkClient {
next_action_data: payments::SdkNextActionData,
},
}

pub(crate) fn into_stripe_next_action(
Expand Down Expand Up @@ -871,6 +874,9 @@ pub(crate) fn into_stripe_next_action(
url: None,
},
},
payments::NextActionData::InvokeSdkClient { next_action_data } => {
StripeNextAction::InvokeSdkClient { next_action_data }
}
})
}

Expand Down
6 changes: 6 additions & 0 deletions crates/router/src/compatibility/stripe/setup_intents/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ pub enum StripeNextAction {
display_from_timestamp: i128,
display_to_timestamp: Option<i128>,
},
InvokeSdkClient {
next_action_data: payments::SdkNextActionData,
},
}

pub(crate) fn into_stripe_next_action(
Expand Down Expand Up @@ -437,6 +440,9 @@ pub(crate) fn into_stripe_next_action(
url: None,
},
},
payments::NextActionData::InvokeSdkClient { next_action_data } => {
StripeNextAction::InvokeSdkClient { next_action_data }
}
})
}

Expand Down
Loading

0 comments on commit b3d4d13

Please sign in to comment.