-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(connector): [XENDIT] Added Integrity Check for Authorize, Capture, Refund & RSync flows #8049
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
Conversation
Changed Files
|
pub amount: FloatMajorUnit, | ||
pub currency: 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.
are we sure about this as required fields @deepanshu-iiitu can you please check and confirm
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.
currency should be an enum of Currency, correcting it
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 please test end to end!
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.
I have tested the flows, added them in the PR description as well
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.
okay sure! but you are sure about the required fields from connector end right. We don't want a deserialization error
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.
yes, these two are marked as req fields
ref : https://developers.xendit.co/api-reference/payments-api/#payment-request-object
pub fn get_sync_integrity_object<T>( | ||
amount_convertor: &dyn AmountConvertor<Output = T>, | ||
amount: T, | ||
currency: String, | ||
) -> Result<SyncIntegrityObject, error_stack::Report<errors::ConnectorError>> { | ||
let currency_enum = enums::Currency::from_str(currency.to_uppercase().as_str()) | ||
.change_context(errors::ConnectorError::ParsingFailed)?; | ||
let amount_in_minor_unit = | ||
convert_back_amount_to_minor_units(amount_convertor, amount, currency_enum)?; | ||
|
||
Ok(SyncIntegrityObject { | ||
amount: Some(amount_in_minor_unit), | ||
currency: Some(currency_enum), | ||
}) | ||
} | ||
|
||
pub fn get_capture_integrity_object<T>( | ||
amount_convertor: &dyn AmountConvertor<Output = T>, | ||
capture_amount: Option<T>, | ||
currency: String, | ||
) -> Result<CaptureIntegrityObject, error_stack::Report<errors::ConnectorError>> { |
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.
what about Authorise Flow
why are not doing integrity for authorisation?
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.
missed it, adding that
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.
also please change the pr title mentioning authorise flow
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.
Sure
if ( | ||
setupFutureUsage === "off_session" && | ||
response.body.status === "succeeded" | ||
) { |
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 we remove all the unnecessary changes in the cypress files
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.
these are formatting changes that took place due to this command cargo +nightly fmt --all
Type of Change
Description
In this PR, we have added integrity checks for Authorize, Capture, Refund and RSync flows for Xendit Connector
Also, moved the integrity functions from
crates/router/src/connector/utils.rs
tocrates/hyperswitch_connectors/src/utils.rs
. Thereby also changing the imports inStripe.rs
.What is an integrity check?
A scenario where there is a discrepancy between the amount sent in the request and the amount received from the connector, which is checked during response handling.
Additional Changes
Motivation and Context
This Pr holds the payment in a non-terminal state incase there is any data discrepancy in the above flows.
How did you test it?
Case 1: AUTOMATIC Capture
Do a Payments - Create
Request:
Now after completing the 3DS authentication in the browser, Do a PSync on the payment_id you received in the response
PSync cURL :
Response:
Why this behaviour?
I have hardcoded the amount in the code and the amount i hardcoded is more than the amount in the request causing the payment to fail.
Case 2: MANUAL Capture
Do a payments create
Request:
Now do a force PSync after the 3DS authentication is done in the web browser and you got the payment_id
PSync cURL :
Response :
Why this behaviour?
I have hardcoded the amount in code for it to fail
Case 3: Refunds
Do a payments create and this time donot hardcode anything in the code for Payments Create
Now do a force PSync after the 3DS authentication is completed in the web browser and you have the payment_id
PSync cURL :
Response:
Now do a Refunds Create and in postman send an amount which is lower than the Captured Amount
Refunds Create cURL :
Response:
Why this behaviour?
I have hardcoded the amount to be refunded in the code as the same as the captured amount but in postman the amount i have sent is less than that, causing the payments to fail (intentionally)
Checklist
cargo +nightly fmt --all
cargo clippy