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(core): add payments post_session_tokens flow #6202

Merged
merged 38 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0265c1d
feat: add order_create_endpoint
swangi-kumari Oct 2, 2024
e343022
refactor: paypal sdk via create order
swangi-kumari Oct 3, 2024
bae1ed8
refactor: merge main
swangi-kumari Oct 3, 2024
3eea57a
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 3, 2024
97b7104
feat: post update tracker for craete order
swangi-kumari Oct 7, 2024
902b799
Merge branch 'create-order' of https://github.com/juspay/hyperswitch …
swangi-kumari Oct 7, 2024
1cd705b
refactor: next action
swangi-kumari Oct 7, 2024
1e258a8
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 7, 2024
99a03bf
Merge branch 'main' into create-order
swangi-kumari Oct 7, 2024
6071f12
refactor: some refactor
swangi-kumari Oct 7, 2024
1563a0b
refactor: rename to post_session_tokens
swangi-kumari Oct 8, 2024
990a535
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 8, 2024
abf5f65
refactor: status of paymene attempt
swangi-kumari Oct 8, 2024
bfe5bec
refactor: refactor post_update_trackers
swangi-kumari Oct 8, 2024
5aa4a7a
refactor: add dynamic fields
swangi-kumari Oct 9, 2024
7235dac
refactor: paypal paymnet succeeded
swangi-kumari Oct 10, 2024
2bda2ef
Merge branch 'main' of https://github.com/juspay/hyperswitch into cre…
swangi-kumari Oct 10, 2024
5b57ae3
refactor: mereg main
swangi-kumari Oct 11, 2024
f4cd68f
chore: run formatter
hyperswitch-bot[bot] Oct 11, 2024
6b14707
refactor: formating
swangi-kumari Oct 11, 2024
5a0b776
Merge branch 'create-order' of https://github.com/juspay/hyperswitch …
swangi-kumari Oct 11, 2024
6b3fcc0
Merge branch 'main' into create-order
swangi-kumari Oct 11, 2024
1f152c1
refactor: solve clippy
swangi-kumari Oct 12, 2024
5ff5f6f
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 12, 2024
f463adf
refactor: some refactor
swangi-kumari Oct 12, 2024
e93d487
Merge branch 'create-order' of https://github.com/juspay/hyperswitch …
swangi-kumari Oct 12, 2024
4833097
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 12, 2024
a4044a8
refactor: remove shipping cost
swangi-kumari Oct 12, 2024
42aee19
Merge branch 'create-order' of https://github.com/juspay/hyperswitch …
swangi-kumari Oct 12, 2024
04b3afe
refactor: open api
swangi-kumari Oct 13, 2024
ebf6d43
refactor: store connector_transaction_id in connector_metadata
swangi-kumari Oct 14, 2024
e88f86e
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 14, 2024
5a2f0f1
Merge branch 'main' into create-order
swangi-kumari Oct 14, 2024
6117ddf
refactor: resolve comments
swangi-kumari Oct 15, 2024
d34a704
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 15, 2024
2976976
refactor: add status
swangi-kumari Oct 15, 2024
7a68862
Merge branch 'create-order' of https://github.com/juspay/hyperswitch …
swangi-kumari Oct 15, 2024
d3da258
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Oct 15, 2024
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
5 changes: 5 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -10167,6 +10167,7 @@
"NextActionCall": {
"type": "string",
"enum": [
"post_session_tokens",
"confirm",
"sync",
"complete_authorize"
Expand Down Expand Up @@ -19277,6 +19278,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 @@ -13811,6 +13851,7 @@
"NextActionCall": {
"type": "string",
"enum": [
"post_session_tokens",
"confirm",
"sync",
"complete_authorize"
Expand Down Expand Up @@ -17928,6 +17969,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 @@ -23039,6 +23129,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 @@ -3819,6 +3819,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 @@ -4873,6 +4874,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,
Comment on lines +4879 to +4882
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not obtaining this from the request (not deserializing it), why are we including it in the request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for ApiEventMetrics and ApiLocking

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Narayanbhat166 Should we consider having an "internal" struct for such purposes, or are we okay with this practice?

/// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we using this response anywhere? I think we are sending the payments response. Instead of that can we use this struct?

/// 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 @@ -5429,6 +5458,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 @@ -475,6 +475,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 @@ -3065,6 +3069,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
Loading