Skip to content
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 adyen split payments support #6952

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15447,7 +15447,7 @@
"split_payments": {
"allOf": [
{
"$ref": "#/components/schemas/SplitPaymentsResponse"
"$ref": "#/components/schemas/ConnectorChargeResponseData"
}
],
"nullable": true
Expand Down Expand Up @@ -16347,7 +16347,7 @@
"split_payments": {
"allOf": [
{
"$ref": "#/components/schemas/SplitPaymentsResponse"
"$ref": "#/components/schemas/ConnectorChargeResponseData"
}
],
"nullable": true
Expand Down Expand Up @@ -20498,7 +20498,7 @@
],
"description": "Fee information for Split Payments to be charged on the payment being collected"
},
"SplitPaymentsResponse": {
"ConnectorChargeResponseData": {
"oneOf": [
{
"type": "object",
Expand All @@ -20507,7 +20507,7 @@
],
"properties": {
"stripe_split_payment": {
"$ref": "#/components/schemas/StripeSplitPaymentsResponse"
"$ref": "#/components/schemas/StripeChargeResponseData"
}
}
}
Expand Down Expand Up @@ -20631,7 +20631,7 @@
},
"additionalProperties": false
},
"StripeSplitPaymentsResponse": {
"StripeChargeResponseData": {
"type": "object",
"description": "Fee information to be charged on the payment being collected",
"required": [
Expand Down
10 changes: 5 additions & 5 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -18805,7 +18805,7 @@
"split_payments": {
"allOf": [
{
"$ref": "#/components/schemas/SplitPaymentsResponse"
"$ref": "#/components/schemas/ConnectorChargeResponseData"
}
],
"nullable": true
Expand Down Expand Up @@ -20048,7 +20048,7 @@
"split_payments": {
"allOf": [
{
"$ref": "#/components/schemas/SplitPaymentsResponse"
"$ref": "#/components/schemas/ConnectorChargeResponseData"
}
],
"nullable": true
Expand Down Expand Up @@ -24934,7 +24934,7 @@
],
"description": "Fee information for Split Payments to be charged on the payment being collected"
},
"SplitPaymentsResponse": {
"ConnectorChargeResponseData": {
"oneOf": [
{
"type": "object",
Expand All @@ -24943,7 +24943,7 @@
],
"properties": {
"stripe_split_payment": {
"$ref": "#/components/schemas/StripeSplitPaymentsResponse"
"$ref": "#/components/schemas/StripeChargeResponseData"
}
}
}
Expand Down Expand Up @@ -25067,7 +25067,7 @@
},
"additionalProperties": false
},
"StripeSplitPaymentsResponse": {
"StripeChargeResponseData": {
"type": "object",
"description": "Fee information to be charged on the payment being collected",
"required": [
Expand Down
2 changes: 1 addition & 1 deletion connector-template/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<F,T> TryFrom<ResponseRouterData<F, {{project-name | downcase | pascal_case}
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
charge_id: None,
charges: None,
}),
..item.data
})
Expand Down
27 changes: 1 addition & 26 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4726,7 +4726,7 @@ pub struct PaymentsResponse {
pub updated: Option<PrimitiveDateTime>,

/// Fee information to be charged on the payment being collected
pub split_payments: Option<SplitPaymentsResponse>,
pub split_payments: Option<common_types::payments::ConnectorChargeResponseData>,

/// 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" }"#)]
Expand Down Expand Up @@ -4991,31 +4991,6 @@ pub struct PaymentStartRedirectionParams {
pub profile_id: id_type::ProfileId,
}

/// Fee information to be charged on the payment being collected
#[derive(Setter, Clone, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct StripeSplitPaymentsResponse {
/// 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
#[schema(value_type = i64, example = 6540)]
pub application_fees: MinorUnit,

/// Identifier for the reseller's account where the funds were transferred
pub transfer_account_id: String,
}

#[derive(Clone, Debug, PartialEq, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum SplitPaymentsResponse {
/// StripeSplitPaymentsResponse
StripeSplitPayment(StripeSplitPaymentsResponse),
}

/// Details of external authentication
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct ExternalAuthenticationDetailsResponse {
Expand Down
2 changes: 1 addition & 1 deletion crates/common_enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ openapi = []
payouts = []

[dependencies]
diesel = { version = "2.2.3", features = ["postgres"] }
diesel = { version = "2.2.3", features = ["postgres", "128-column-tables"]}
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
strum = { version = "0.26", features = ["derive"] }
Expand Down
38 changes: 38 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3613,3 +3613,41 @@ pub enum FeatureStatus {
NotSupported,
Supported,
}

#[derive(
Clone,
Debug,
Eq,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
ToSchema,
)]
#[strum(serialize_all = "camelCase")]
#[serde(rename_all = "camelCase")]
pub enum AdyenSplitType {
/// Books split amount to the specified account.
BalanceAccount,
/// The aggregated amount of the interchange and scheme fees.
AcquiringFees,
/// The aggregated amount of all transaction fees.
PaymentFee,
/// The aggregated amount of Adyen's commission and markup fees.
AdyenFees,
/// The transaction fees due to Adyen under blended rates.
AdyenCommission,
/// The transaction fees due to Adyen under Interchange ++ pricing.
AdyenMarkup,
/// The fees paid to the issuer for each payment made with the card network.
Interchange,
/// The fees paid to the card scheme for using their network.
SchemeFee,
/// Your platform's commission on the payment (specified in amount), booked to your liable balance account.
Commission,
/// Allows you and your users to top up balance accounts using direct debit, card payments, or other payment methods.
TopUp,
/// The value-added tax charged on the payment, booked to your platforms liable balance account.
Vat,
}
43 changes: 43 additions & 0 deletions crates/common_types/src/domain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Common types

use common_enums::enums;
use common_utils::{impl_to_sql_from_sql_json, types::MinorUnit};
use diesel::{sql_types::Jsonb, AsExpression, FromSqlRow};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
#[diesel(sql_type = Jsonb)]
#[serde(deny_unknown_fields)]
/// Fee information for Split Payments to be charged on the payment being collected for Adyen
pub struct AdyenSplitData {
/// The store identifier
pub store: Option<String>,
/// Data for the split items
pub split_items: Vec<AdyenSplitItem>,
}
impl_to_sql_from_sql_json!(AdyenSplitData);

#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
#[diesel(sql_type = Jsonb)]
#[serde(deny_unknown_fields)]
/// Data for the split items
pub struct AdyenSplitItem {
/// The amount of the split item
#[schema(value_type = i64, example = 6540)]
pub amount: Option<MinorUnit>,
/// Defines type of split item
#[schema(value_type = AdyenSplitType, example = "BalanceAccount")]
pub split_type: enums::AdyenSplitType,
/// The unique identifier of the account to which the split amount is allocated.
pub account: Option<String>,
/// Unique Identifier for the split item
pub reference: Option<String>,
/// Description for the part of the payment that will be allocated to the specified account.
pub description: Option<String>,
}
impl_to_sql_from_sql_json!(AdyenSplitItem);
1 change: 1 addition & 0 deletions crates/common_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![warn(missing_docs, missing_debug_implementations)]

pub mod domain;
pub mod payment_methods;
pub mod payments;
pub mod refunds;
42 changes: 42 additions & 0 deletions crates/common_types/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use diesel::{sql_types::Jsonb, AsExpression, FromSqlRow};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::domain as domain_types;

#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
Expand All @@ -16,6 +18,8 @@ use utoipa::ToSchema;
pub enum SplitPaymentsRequest {
/// StripeSplitPayment
StripeSplitPayment(StripeSplitPaymentRequest),
/// AdyenSplitPayment
AdyenSplitPayment(domain_types::AdyenSplitData),
}
impl_to_sql_from_sql_json!(SplitPaymentsRequest);

Expand All @@ -38,3 +42,41 @@ pub struct StripeSplitPaymentRequest {
pub transfer_account_id: String,
}
impl_to_sql_from_sql_json!(StripeSplitPaymentRequest);

/// Fee information to be charged on the payment being collected via Stripe
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
#[diesel(sql_type = Jsonb)]
#[serde(deny_unknown_fields)]
pub struct StripeChargeResponseData {
/// 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: enums::PaymentChargeType,

/// Platform fees collected on the payment
#[schema(value_type = i64, example = 6540)]
pub application_fees: MinorUnit,

/// Identifier for the reseller's account where the funds were transferred
pub transfer_account_id: String,
}
impl_to_sql_from_sql_json!(StripeChargeResponseData);

/// Charge Information
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
#[diesel(sql_type = Jsonb)]
#[serde(deny_unknown_fields)]
pub enum ConnectorChargeResponseData {
/// StripeChargeResponseData
StripeSplitPayment(StripeChargeResponseData),
/// AdyenChargeResponseData
AdyenSplitPayment(domain_types::AdyenSplitData),
}

impl_to_sql_from_sql_json!(ConnectorChargeResponseData);
4 changes: 4 additions & 0 deletions crates/common_types/src/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use diesel::{sql_types::Jsonb, AsExpression, FromSqlRow};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::domain as domain_types;

#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, FromSqlRow, AsExpression, ToSchema,
)]
Expand All @@ -15,6 +17,8 @@ use utoipa::ToSchema;
pub enum SplitRefund {
/// StripeSplitRefundRequest
StripeSplitRefund(StripeSplitRefundRequest),
/// AdyenSplitRefundRequest
AdyenSplitRefund(domain_types::AdyenSplitData),
}
impl_to_sql_from_sql_json!(SplitRefund);

Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ payment_methods_v2 = []

[dependencies]
async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" }
diesel = { version = "2.2.3", features = ["postgres", "serde_json", "time", "64-column-tables"] }
diesel = { version = "2.2.3", features = ["postgres", "serde_json", "time", "128-column-tables"] }
error-stack = "0.4.1"
rustc-hash = "1.1.0"
serde = { version = "1.0.197", features = ["derive"] }
Expand Down
Loading
Loading