-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(payments_v2): implement create and confirm setup intent flow #7106
base: main
Are you sure you want to change the base?
Conversation
@@ -1405,6 +1405,18 @@ impl PaymentAttemptUpdate { | |||
} | |||
} | |||
|
|||
#[cfg(feature = "v2")] | |||
#[derive(Debug, Clone, Serialize)] | |||
pub struct ConfirmIntentResponseUpdate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to move this as a separate struct because of the clippy::large_enum_variant
lint being thrown.
impl | ||
TrackerPostUpdateObjects< | ||
router_flow_types::SetupMandate, | ||
router_request_types::SetupMandateRequestData, | ||
payments::PaymentConfirmData<router_flow_types::SetupMandate>, | ||
> | ||
for RouterData< | ||
router_flow_types::SetupMandate, | ||
router_request_types::SetupMandateRequestData, | ||
router_response_types::PaymentsResponseData, | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is almost entirely a copy-paste of the implementation of the Autorize flow. Didn't bother to reduce code duplication between these two implementations.
impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::SetupMandateRequestData> | ||
for PaymentResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, a copy-paste of the authorize flow implementation.
crates/router/src/routes/app.rs
Outdated
.route(web::post().to(payments::payments_create_intent)), | ||
) | ||
.service( | ||
web::resource("/setup-intent") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if the path needs to be changed.
@@ -592,7 +592,6 @@ async fn handle_response( | |||
|
|||
match status_code { | |||
200..=202 | 302 | 204 => { | |||
logger::debug!(response=?response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this redundant log line, since the response is being logged (with the same key) on line 589, before the match
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is not setup-intent, it is just /payments
. The term we need to use payments
and not setup-intent
.
…sRequest` and `SetupIntentWrapperResponse` to `PaymentsResponse`
…nt()` to `payments_create_and_confirm_intent()`
…plementation on `PaymentConfirmData`
…tsConfirmIntentResponse`
…e_and_confirm_intent()`
…rder amount in `payments_create_and_confirm_intent()`
…in API reference
Type of Change
Description
This PR introduces the setup intent flow for payments v2. As of now, this PR includes a single endpoint that handles both the create intent and confirm intent steps. This is done so as to allow the payment methods v2 endpoints to create multiple-use tokens for a specified customer's payment method. The implementation mostly builds on top of payment create intent v2 and payment confirm intent v2 implementations. Note that the API contract is not finalized and is possibly subject to change.
Additional Changes
This PR introduces a new setup intent endpoint for payments v2.
Motivation and Context
The endpoint introduced in this PR would allow the creation of multiple-use tokens by the payments methods v2 endpoints.
How did you test it?
Using the v2 endpoints, create an organization, merchant account, profile, API key and merchant connector account.
Call the setup intent endpoint:
amount_details
,payment_method_data
,payment_method_type
andpayment_method_subtype
.The request and response are included below:
Note that the
order_amount
is zero in the above request. Also, note that theconnector_token
field is populated in the response, and theconnector_transaction_id
beingseti_*
indicates that Stripe's setup intent flow was called.Additional fields may be passed in the request, such as
customer_id
, etc. which would be reflected in the response and database entries.Passing in a non-zero value for the
order_amount
causes it to follow the regular create intent + confirm intent flow:In this case, the
connector_transaction_id
ispi_*
, indicating that Stripe's authorize flow was called.Checklist
cargo +nightly fmt --all
cargo clippy