feat(payment_v2): implement payments sync (#6464)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-11-11 18:44:15 +05:30
committed by GitHub
parent 0a506b1729
commit 42bdf47fd2
65 changed files with 2448 additions and 491 deletions

View File

@ -1297,6 +1297,28 @@ pub enum IntentStatus {
PartiallyCapturedAndCapturable,
}
impl IntentStatus {
/// Indicates whether the syncing with the connector should be allowed or not
pub fn should_force_sync_with_connector(&self) -> bool {
match self {
// Confirm has not happened yet
Self::RequiresConfirmation
| Self::RequiresPaymentMethod
// Once the status is success, failed or cancelled need not force sync with the connector
| Self::Succeeded
| Self::Failed
| Self::Cancelled
| Self::PartiallyCaptured
| Self::RequiresCapture => false,
Self::Processing
| Self::RequiresCustomerAction
| Self::RequiresMerchantAction
| Self::PartiallyCapturedAndCapturable
=> true,
}
}
}
/// Indicates that you intend to make future payments with the payment methods used for this Payment. Providing this parameter will attach the payment method to the Customer, if present, after the Payment is confirmed and any required actions from the user are complete.
/// - On_session - Payment method saved only at hyperswitch when consent is provided by the user. CVV will asked during the returning user payment
/// - Off_session - Payment method saved at both hyperswitch and Processor when consent is provided by the user. No input is required during the returning user payment.

View File

@ -2,7 +2,10 @@ use std::fmt::{Display, Formatter};
use serde::{Deserialize, Serialize};
use crate::enums::{Country, CountryAlpha2, CountryAlpha3, PaymentMethod, PaymentMethodType};
use crate::enums::{
AttemptStatus, Country, CountryAlpha2, CountryAlpha3, IntentStatus, PaymentMethod,
PaymentMethodType,
};
impl Display for NumericCountryCodeParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
@ -2065,6 +2068,41 @@ impl super::PresenceOfCustomerDuringPayment {
}
}
impl From<AttemptStatus> for IntentStatus {
fn from(s: AttemptStatus) -> Self {
match s {
AttemptStatus::Charged | AttemptStatus::AutoRefunded => Self::Succeeded,
AttemptStatus::ConfirmationAwaited => Self::RequiresConfirmation,
AttemptStatus::PaymentMethodAwaited => Self::RequiresPaymentMethod,
AttemptStatus::Authorized => Self::RequiresCapture,
AttemptStatus::AuthenticationPending | AttemptStatus::DeviceDataCollectionPending => {
Self::RequiresCustomerAction
}
AttemptStatus::Unresolved => Self::RequiresMerchantAction,
AttemptStatus::PartialCharged => Self::PartiallyCaptured,
AttemptStatus::PartialChargedAndChargeable => Self::PartiallyCapturedAndCapturable,
AttemptStatus::Started
| AttemptStatus::AuthenticationSuccessful
| AttemptStatus::Authorizing
| AttemptStatus::CodInitiated
| AttemptStatus::VoidInitiated
| AttemptStatus::CaptureInitiated
| AttemptStatus::Pending => Self::Processing,
AttemptStatus::AuthenticationFailed
| AttemptStatus::AuthorizationFailed
| AttemptStatus::VoidFailed
| AttemptStatus::RouterDeclined
| AttemptStatus::CaptureFailed
| AttemptStatus::Failure => Self::Failed,
AttemptStatus::Voided => Self::Cancelled,
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]