-
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(router): add payments incremental authorization api #3038
Conversation
…om:juspay/hyperswitch into add-core-changes-incremental-authorization
crates/api_models/src/payments.rs
Outdated
pub code: Option<String>, | ||
pub message: Option<String>, |
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.
Is this only for error_code
and error_message
, or some other code and message value can be present here? Can you also add doc comments to the fields?
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 can be any code and message sent by connector
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS authorization_count INTEGER; |
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.
All the previous payments should have this value as zero, will adding a default as 0 help?
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 to distinguish for normal payments with incremental auth performed payments
&self, | ||
_authorization: storage::AuthorizationNew, | ||
) -> CustomResult<storage::Authorization, errors::StorageError> { | ||
// TODO: Implement function for `MockDb` |
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.
Can you create good first issues for these? The issue can be linked to the parent issue #172
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.
async fn find_all_authorizations_by_merchant_id_payment_id( | ||
&self, | ||
merchant_id: &str, | ||
payment_id: &str, | ||
) -> CustomResult<Vec<storage::Authorization>, errors::StorageError> { | ||
let conn = connection::pg_connection_read(self).await?; | ||
storage::Authorization::find_by_merchant_id_payment_id(&conn, merchant_id, payment_id) | ||
.await | ||
.map_err(Into::into) | ||
.into_report() | ||
} |
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 should be an olap operation, can you include the feature flag?
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.
We are using this in get_trackers
of PaymentsRetrieve
Box::pin(payment_response_update_tracker( | ||
db, | ||
payment_id, | ||
payment_data, | ||
router_data, | ||
storage_scheme, | ||
)) | ||
.await | ||
} |
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.
Can you have a separate post_update_tracker
for this operation? Adding all of the update trackers in a single functions makes it bloated.
.store | ||
.insert_authorization(authorization_new.clone()) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError) |
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 should be to_duplicate_response
, and the error can be GenericDuplicateError
…ntal-authorization-api
…/hyperswitch into add-incremental-authorization-api
…/hyperswitch into add-incremental-authorization-api
error_code, | ||
error_message, |
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.
why will a success response have error code and message?
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.
In case of 2xx failures, we need error_code and error_message in IncrementalAuthorizationResponse
let authorizations = db | ||
.store | ||
.find_all_authorizations_by_merchant_id_payment_id( | ||
&router_data.merchant_id, | ||
&payment_data.payment_intent.payment_id, | ||
) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::InternalServerError) | ||
.attach_printable("failed while retrieving authorizations")?; |
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.
Is this to update the status of latest authorization
?
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.
No, this is to fetch all the authorizations and send back in the incremental auth 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.
Cybersource changes look good.
incremental_authorization_allowed: if payment_data | ||
.incremental_authorization_details | ||
.is_none() | ||
{ | ||
Some(false) | ||
} else { | ||
None | ||
}, |
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.
Can you remove this?
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.
@sai-harsha-vardhan I reviewed connector code, it looks good to me
Type of Change
Description
add payments incremental authorization api and add support for cybersource connector
Additional Changes
Motivation and Context
How did you test it?
Tested Manually
send request_incremental_authorization as false in payments request, to see incremental_authorization_allowed being sent as false in response
now, try doing an increment authorization for the above payment to see not allowed error
CURL
curl --location --request POST '{baseUrl}/payments/{payment_id}/incremental_authorization' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: {API_KEY}' \ --data-raw '{ "amount": 11005 }'
try sending request_incremental_authorization as true for payment for which capture_method is automatic to see not allowed error
now send request_incremental_authorization as true for payment with capture_method manual to see incremental_authorization_allowed being true in response
now, for above payment_id try doing an increment authorization with amount less than original amount to see now allowed error
now, do the increment authorization with amount greater than original amount to see final authorized amount
all the authorization details along with authorization_count can be seen in the response
Checklist
cargo +nightly fmt --all
cargo clippy