Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: applepay feature release #636

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 91 additions & 42 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,51 +1098,100 @@ pub struct GpaySessionTokenData {
#[serde(rename_all = "lowercase")]
pub enum SessionToken {
/// The session response structure for Google Pay
Gpay {
/// The merchant info
merchant_info: GpayMerchantInfo,
/// List of the allowed payment meythods
allowed_payment_methods: Vec<GpayAllowedPaymentMethods>,
/// The transaction info Google Pay requires
transaction_info: GpayTransactionInfo,
},
Gpay(Box<GpaySessionTokenResponse>),
/// The session response structure for Klarna
Klarna {
/// The session token for Klarna
session_token: String,
/// The identifier for the session
session_id: String,
},
Klarna(Box<KlarnaSessionTokenResponse>),
/// The session response structure for PayPal
Paypal {
/// The session token for PayPal
session_token: String,
},
Paypal(Box<PaypalSessionTokenResponse>),
/// The session response structure for Apple Pay
Applepay {
/// Timestamp at which session is requested
epoch_timestamp: u64,
/// Timestamp at which session expires
expires_at: u64,
/// The identifier for the merchant session
merchant_session_identifier: String,
/// Applepay generates unique ID (UUID) value
nonce: String,
/// The identifier for the merchant
merchant_identifier: String,
/// The domain name of the merchant which is registered in Apple Pay
domain_name: String,
/// The name to be displayed on Apple Pay button
display_name: String,
/// A string which represents the properties of a payment
signature: String,
/// The identifier for the operational analytics
operational_analytics_identifier: String,
/// The number of retries to get the session response
retries: u8,
/// The identifier for the connector transaction
psp_id: String,
},
Applepay(Box<ApplepaySessionTokenResponse>),
}

#[derive(Debug, Clone, serde::Serialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub struct GpaySessionTokenResponse {
/// The merchant info
pub merchant_info: GpayMerchantInfo,
/// List of the allowed payment meythods
pub allowed_payment_methods: Vec<GpayAllowedPaymentMethods>,
/// The transaction info Google Pay requires
pub transaction_info: GpayTransactionInfo,
}

#[derive(Debug, Clone, serde::Serialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub struct KlarnaSessionTokenResponse {
/// The session token for Klarna
pub session_token: String,
/// The identifier for the session
pub session_id: String,
}

#[derive(Debug, Clone, serde::Serialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub struct PaypalSessionTokenResponse {
/// The session token for PayPal
pub session_token: String,
}

#[derive(Debug, Clone, serde::Serialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub struct ApplepaySessionTokenResponse {
/// Session object for Apple Pay
pub session_token_data: ApplePaySessionResponse,
/// Payment request object for Apple Pay
pub payment_request_data: ApplePayPaymentRequest,
}

#[derive(Debug, Clone, serde::Serialize, ToSchema, serde::Deserialize)]
pub struct ApplePaySessionResponse {
/// Timestamp at which session is requested
pub epoch_timestamp: u64,
/// Timestamp at which session expires
pub expires_at: u64,
/// The identifier for the merchant session
pub merchant_session_identifier: String,
/// Apple pay generated unique ID (UUID) value
pub nonce: String,
/// The identifier for the merchant
pub merchant_identifier: String,
/// The domain name of the merchant which is registered in Apple Pay
pub domain_name: String,
/// The name to be displayed on Apple Pay button
pub display_name: String,
/// A string which represents the properties of a payment
pub signature: String,
/// The identifier for the operational analytics
pub operational_analytics_identifier: String,
/// The number of retries to get the session response
pub retries: u8,
/// The identifier for the connector transaction
pub psp_id: String,
}

#[derive(Debug, Clone, serde::Serialize, ToSchema, serde::Deserialize)]
pub struct ApplePayPaymentRequest {
/// The code for country
pub country_code: String,
/// The code for currency
pub currency_code: String,
/// Represents the total for the payment.
pub total: AmountInfo,
/// The list of merchant capabilities(ex: whether capable of 3ds or no-3ds)
pub merchant_capabilities: Vec<String>,
/// The list of supported networks
pub supported_networks: Vec<String>,
}

#[derive(Debug, Clone, serde::Serialize, ToSchema, serde::Deserialize)]
pub struct AmountInfo {
/// The label must be the name of the merchant.
pub label: String,
/// A value that indicates whether the line item(Ex: total, tax, discount, or grand total) is final or pending.
#[serde(rename = "type")]
pub total_type: String,
/// The total amount for the payment
pub amount: String,
}

#[derive(Default, Debug, serde::Serialize, Clone, ToSchema)]
Expand Down
14 changes: 7 additions & 7 deletions crates/router/src/connector/applepay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl
data: &types::PaymentsSessionRouterData,
res: types::Response,
) -> CustomResult<types::PaymentsSessionRouterData, errors::ConnectorError> {
let response: applepay::ApplepaySessionResponse = res
let response: applepay::ApplepaySessionTokenResponse = res
.response
.parse_struct("ApplepaySessionResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
Expand Down Expand Up @@ -197,11 +197,11 @@ impl
.get_required_value("connector_meta_data")
.change_context(errors::ConnectorError::NoConnectorMetaData)?;

let session_object: transformers::SessionObject = metadata
.parse_value("SessionObject")
let metadata: transformers::ApplePayMetadata = metadata
.parse_value("ApplePayMetaData")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;

Ok(Some(session_object.certificate))
Ok(Some(metadata.session_token_data.certificate))
}

fn get_certificate_key(
Expand All @@ -214,11 +214,11 @@ impl
.get_required_value("connector_meta_data")
.change_context(errors::ConnectorError::NoConnectorMetaData)?;

let session_object: transformers::SessionObject = metadata
.parse_value("SessionObject")
let metadata: transformers::ApplePayMetadata = metadata
.parse_value("ApplePayMetaData")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;

Ok(Some(session_object.certificate_keys))
Ok(Some(metadata.session_token_data.certificate_keys))
}
}

Expand Down
Loading