feat(payment_charges): add support for collecting and refunding charges on payments (#4628)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com>
Co-authored-by: Shankar Singh C <83439957+ShankarSinghC@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: YongJoon Kim <penubokim@gmail.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com>
Co-authored-by: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com>
Co-authored-by: Sampras Lopes <Sampras.lopes@juspay.in>
This commit is contained in:
Kashif
2024-05-24 13:39:04 +05:30
committed by GitHub
parent a7fc4c6fcd
commit 55ccce6189
106 changed files with 882 additions and 22 deletions

View File

@ -600,6 +600,50 @@ pub fn convert_authentication_connector(connector_name: &str) -> Option<Authenti
AuthenticationConnectors::from_str(connector_name).ok()
}
#[derive(
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
Hash,
)]
pub enum PaymentChargeType {
#[serde(untagged)]
Stripe(StripeChargeType),
}
impl Default for PaymentChargeType {
fn default() -> Self {
Self::Stripe(StripeChargeType::default())
}
}
#[derive(
Clone,
Debug,
Default,
Hash,
Eq,
PartialEq,
ToSchema,
serde::Serialize,
serde::Deserialize,
strum::Display,
strum::EnumString,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum StripeChargeType {
#[default]
Direct,
Destination,
}
#[cfg(feature = "frm")]
pub fn convert_frm_connector(connector_name: &str) -> Option<FrmConnectors> {
FrmConnectors::from_str(connector_name).ok()

View File

@ -474,6 +474,23 @@ pub struct PaymentsRequest {
/// Details required for recurring payment
pub recurring_details: Option<RecurringDetails>,
/// Fee information to be charged on the payment being collected
pub charges: Option<PaymentChargeRequest>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct PaymentChargeRequest {
/// Stripe's charge type
#[schema(value_type = PaymentChargeType, example = "direct")]
pub charge_type: api_enums::PaymentChargeType,
/// Platform fees to be collected on the payment
pub fees: i64,
/// Identifier for the reseller's account to send the funds to
pub transfer_account_id: String,
}
impl PaymentsRequest {
@ -3426,11 +3443,30 @@ pub struct PaymentsResponse {
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub updated: Option<PrimitiveDateTime>,
/// Fee information to be charged on the payment being collected
pub charges: Option<PaymentChargeResponse>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. FRM Metadata is useful for storing additional, structured information on an object related to FRM.
#[schema(value_type = Option<Object>, example = r#"{ "fulfillment_method" : "deliver", "coverage_request" : "fraud" }"#)]
pub frm_metadata: Option<pii::SecretSerdeValue>,
}
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct PaymentChargeResponse {
/// Identifier for charge created for the payment
pub charge_id: Option<String>,
/// Type of charge (connector specific)
#[schema(value_type = PaymentChargeType, example = "direct")]
pub charge_type: api_enums::PaymentChargeType,
/// Platform fees collected on the payment
pub application_fees: i64,
/// Identifier for the reseller's account where the funds were transferred
pub transfer_account_id: String,
}
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct ExternalAuthenticationDetailsResponse {
/// Authentication Type - Challenge / Frictionless

View File

@ -1,6 +1,7 @@
use std::collections::HashMap;
use common_utils::pii;
pub use common_utils::types::ChargeRefunds;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use utoipa::ToSchema;
@ -53,6 +54,10 @@ pub struct RefundRequest {
/// Merchant connector details used to make payments.
#[schema(value_type = Option<MerchantConnectorDetailsWrap>)]
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
/// Charge specific fields for controlling the revert of funds from either platform or connected account
#[schema(value_type = Option<ChargeRefunds>)]
pub charges: Option<ChargeRefunds>,
}
#[derive(Default, Debug, Clone, Deserialize)]
@ -137,6 +142,9 @@ pub struct RefundResponse {
pub profile_id: Option<String>,
/// The merchant_connector_id of the processor through which this payment went through
pub merchant_connector_id: Option<String>,
/// Charge specific fields for controlling the revert of funds from either platform or connected account
#[schema(value_type = Option<ChargeRefunds>)]
pub charges: Option<ChargeRefunds>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
@ -168,7 +176,7 @@ pub struct RefundListRequest {
pub refund_status: Option<Vec<enums::RefundStatus>>,
}
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, ToSchema)]
pub struct RefundListResponse {
/// The number of refunds included in the list
pub count: usize,