Skip to content

Commit

Permalink
feat: paypal flow refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
swangi-kumari committed Oct 15, 2024
1 parent 7908761 commit ba11316
Show file tree
Hide file tree
Showing 41 changed files with 1,560 additions and 108 deletions.
5 changes: 5 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -10051,6 +10051,7 @@
"NextActionCall": {
"type": "string",
"enum": [
"post_session_tokens",
"confirm",
"sync",
"complete_authorize"
Expand Down Expand Up @@ -19075,6 +19076,10 @@
"properties": {
"next_action": {
"$ref": "#/components/schemas/NextActionCall"
},
"order_id": {
"type": "string",
"nullable": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /payments/{payment_id}/post_session_tokens
---
3 changes: 2 additions & 1 deletion api-reference/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"api-reference/payments/payments-link--retrieve",
"api-reference/payments/payments--list",
"api-reference/payments/payments--external-3ds-authentication",
"api-reference/payments/payments--complete-authorize"
"api-reference/payments/payments--complete-authorize",
"api-reference/payments/post-session-tokens"
]
},
{
Expand Down
94 changes: 94 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,46 @@
]
}
},
"/payments/{payment_id}/post_session_tokens": {
"post": {
"tags": [
"Payments"
],
"summary": "Payments - Post Session Tokens",
"description": "\n",
"operationId": "Create Post Session Tokens for a Payment",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaymentsPostSessionTokensRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Post Session Token is done",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaymentsPostSessionTokensResponse"
}
}
}
},
"400": {
"description": "Missing mandatory fields"
}
},
"security": [
{
"publishable_key": []
}
]
}
},
"/refunds": {
"post": {
"tags": [
Expand Down Expand Up @@ -13735,6 +13775,7 @@
"NextActionCall": {
"type": "string",
"enum": [
"post_session_tokens",
"confirm",
"sync",
"complete_authorize"
Expand Down Expand Up @@ -17851,6 +17892,55 @@
}
}
},
"PaymentsPostSessionTokensRequest": {
"type": "object",
"required": [
"client_secret",
"payment_method_type",
"payment_method"
],
"properties": {
"client_secret": {
"type": "string",
"description": "It's a token used for client side verification."
},
"payment_method_type": {
"$ref": "#/components/schemas/PaymentMethodType"
},
"payment_method": {
"$ref": "#/components/schemas/PaymentMethod"
}
}
},
"PaymentsPostSessionTokensResponse": {
"type": "object",
"required": [
"payment_id",
"status"
],
"properties": {
"payment_id": {
"type": "string",
"description": "The identifier for the payment"
},
"next_action": {
"allOf": [
{
"$ref": "#/components/schemas/NextActionData"
}
],
"nullable": true
},
"status": {
"allOf": [
{
"$ref": "#/components/schemas/IntentStatus"
}
],
"default": "requires_confirmation"
}
}
},
"PaymentsRequest": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -22847,6 +22937,10 @@
"properties": {
"next_action": {
"$ref": "#/components/schemas/NextActionCall"
},
"order_id": {
"type": "string",
"nullable": true
}
}
},
Expand Down
19 changes: 18 additions & 1 deletion crates/api_models/src/events/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use crate::{
PaymentsCompleteAuthorizeRequest, PaymentsDynamicTaxCalculationRequest,
PaymentsDynamicTaxCalculationResponse, PaymentsExternalAuthenticationRequest,
PaymentsExternalAuthenticationResponse, PaymentsIncrementalAuthorizationRequest,
PaymentsManualUpdateRequest, PaymentsManualUpdateResponse, PaymentsRejectRequest,
PaymentsManualUpdateRequest, PaymentsManualUpdateResponse,
PaymentsPostSessionTokensRequest, PaymentsPostSessionTokensResponse, PaymentsRejectRequest,
PaymentsRequest, PaymentsResponse, PaymentsRetrieveRequest, PaymentsSessionResponse,
PaymentsStartRequest, RedirectionResponse,
},
Expand Down Expand Up @@ -71,6 +72,22 @@ impl ApiEventMetric for PaymentsDynamicTaxCalculationRequest {
}
}

impl ApiEventMetric for PaymentsPostSessionTokensRequest {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Payment {
payment_id: self.payment_id.clone(),
})
}
}

impl ApiEventMetric for PaymentsPostSessionTokensResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Payment {
payment_id: self.payment_id.clone(),
})
}
}

impl ApiEventMetric for PaymentsDynamicTaxCalculationResponse {}

impl ApiEventMetric for PaymentsCancelRequest {
Expand Down
31 changes: 31 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3731,6 +3731,7 @@ pub enum QrCodeInformation {
#[serde(rename_all = "snake_case")]
pub struct SdkNextActionData {
pub next_action: NextActionCall,
pub order_id: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down Expand Up @@ -4761,6 +4762,34 @@ pub struct PaymentsSessionRequest {
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
pub struct PaymentsPostSessionTokensRequest {
/// The unique identifier for the payment
#[serde(skip_deserializing)]
#[schema(value_type = String)]
pub payment_id: id_type::PaymentId,
/// It's a token used for client side verification.
#[schema(value_type = String)]
pub client_secret: Secret<String>,
/// Payment method type
#[schema(value_type = PaymentMethodType)]
pub payment_method_type: api_enums::PaymentMethodType,
/// The payment method that is to be used for the payment
#[schema(value_type = PaymentMethod, example = "card")]
pub payment_method: api_enums::PaymentMethod,
}

#[derive(Debug, serde::Serialize, Clone, ToSchema)]
pub struct PaymentsPostSessionTokensResponse {
/// The identifier for the payment
#[schema(value_type = String)]
pub payment_id: id_type::PaymentId,
/// Additional information required for redirection
pub next_action: Option<NextActionData>,
#[schema(value_type = IntentStatus, example = "failed", default = "requires_confirmation")]
pub status: api_enums::IntentStatus,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentsDynamicTaxCalculationRequest {
/// The unique identifier for the payment
Expand Down Expand Up @@ -5291,6 +5320,8 @@ pub struct SdkNextAction {
#[derive(Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum NextActionCall {
/// The next action call is Post Session Tokens
PostSessionTokens,
/// The next action call is confirm
Confirm,
/// The next action call is sync
Expand Down
58 changes: 58 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ pub enum PaymentAttemptUpdate {
unified_message: Option<String>,
connector_transaction_id: Option<String>,
},
PostSessionTokensUpdate {
updated_by: String,
connector_metadata: Option<serde_json::Value>,
},
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -3119,6 +3123,60 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
shipping_cost: None,
order_tax_amount: None,
},
PaymentAttemptUpdate::PostSessionTokensUpdate {
updated_by,
connector_metadata,
} => Self {
status: None,
error_code: None,
modified_at: common_utils::date_time::now(),
error_message: None,
error_reason: None,
updated_by,
unified_code: None,
unified_message: None,
amount: None,
net_amount: None,
currency: None,
connector_transaction_id: None,
amount_to_capture: None,
connector: None,
authentication_type: None,
payment_method: None,
payment_method_id: None,
cancellation_reason: None,
mandate_id: None,
browser_info: None,
payment_token: None,
connector_metadata,
payment_method_data: None,
payment_method_type: None,
payment_experience: None,
business_sub_label: None,
straight_through_algorithm: None,
preprocessing_step_id: None,
capture_method: None,
connector_response_reference_id: None,
multiple_capture_count: None,
surcharge_amount: None,
tax_amount: None,
amount_capturable: None,
merchant_connector_id: None,
authentication_data: None,
encoded_data: None,
external_three_ds_authentication_attempted: None,
authentication_connector: None,
authentication_id: None,
fingerprint_id: None,
payment_method_billing_address_id: None,
charge_id: None,
client_source: None,
client_version: None,
customer_acceptance: None,
card_network: None,
shipping_cost: None,
order_tax_amount: None,
},
}
}
}
Expand Down
57 changes: 49 additions & 8 deletions crates/hyperswitch_connectors/src/default_implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ use hyperswitch_domain_models::{
mandate_revoke::MandateRevoke,
payments::{
Approve, AuthorizeSessionToken, CalculateTax, CompleteAuthorize,
CreateConnectorCustomer, IncrementalAuthorization, PostProcessing, PreProcessing,
Reject, SdkSessionUpdate,
CreateConnectorCustomer, IncrementalAuthorization, PostProcessing, PostSessionTokens,
PreProcessing, Reject, SdkSessionUpdate,
},
webhooks::VerifyWebhookSource,
},
router_request_types::{
AcceptDisputeRequestData, AuthorizeSessionTokenData, CompleteAuthorizeData,
ConnectorCustomerData, DefendDisputeRequestData, MandateRevokeRequestData,
PaymentsApproveData, PaymentsIncrementalAuthorizationData, PaymentsPostProcessingData,
PaymentsPreProcessingData, PaymentsRejectData, PaymentsTaxCalculationData,
RetrieveFileRequestData, SdkPaymentsSessionUpdateData, SubmitEvidenceRequestData,
UploadFileRequestData, VerifyWebhookSourceRequestData,
PaymentsPostSessionTokensData, PaymentsPreProcessingData, PaymentsRejectData,
PaymentsTaxCalculationData, RetrieveFileRequestData, SdkPaymentsSessionUpdateData,
SubmitEvidenceRequestData, UploadFileRequestData, VerifyWebhookSourceRequestData,
},
router_response_types::{
AcceptDisputeResponse, DefendDisputeResponse, MandateRevokeResponseData,
Expand All @@ -65,9 +65,9 @@ use hyperswitch_interfaces::{
files::{FileUpload, RetrieveFile, UploadFile},
payments::{
ConnectorCustomer, PaymentApprove, PaymentAuthorizeSessionToken,
PaymentIncrementalAuthorization, PaymentReject, PaymentSessionUpdate,
PaymentsCompleteAuthorize, PaymentsPostProcessing, PaymentsPreProcessing,
TaxCalculation,
PaymentIncrementalAuthorization, PaymentPostSessionTokens, PaymentReject,
PaymentSessionUpdate, PaymentsCompleteAuthorize, PaymentsPostProcessing,
PaymentsPreProcessing, TaxCalculation,
},
ConnectorIntegration, ConnectorMandateRevoke, ConnectorRedirectResponse,
},
Expand Down Expand Up @@ -195,6 +195,47 @@ default_imp_for_session_update!(
connectors::Volt
);

macro_rules! default_imp_for_post_session_tokens {
($($path:ident::$connector:ident),*) => {
$( impl PaymentPostSessionTokens for $path::$connector {}
impl
ConnectorIntegration<
PostSessionTokens,
PaymentsPostSessionTokensData,
PaymentsResponseData,
> for $path::$connector
{}
)*
};
}

default_imp_for_post_session_tokens!(
connectors::Bambora,
connectors::Bitpay,
connectors::Cashtocode,
connectors::Coinbase,
connectors::Cryptopay,
connectors::Digitalvirgo,
connectors::Dlocal,
connectors::Square,
connectors::Fiserv,
connectors::Fiservemea,
connectors::Helcim,
connectors::Stax,
connectors::Taxjar,
connectors::Mollie,
connectors::Novalnet,
connectors::Nexixpay,
connectors::Fiuu,
connectors::Globepay,
connectors::Worldline,
connectors::Powertranz,
connectors::Thunes,
connectors::Tsys,
connectors::Deutschebank,
connectors::Volt
);

use crate::connectors;
macro_rules! default_imp_for_complete_authorize {
($($path:ident::$connector:ident),*) => {
Expand Down
Loading

0 comments on commit ba11316

Please sign in to comment.