Skip to content

refactor(core): structure of split payments#6706

Merged
Gnanasundari24 merged 25 commits intomainfrom
split-payments-refactor
Dec 13, 2024
Merged

refactor(core): structure of split payments#6706
Gnanasundari24 merged 25 commits intomainfrom
split-payments-refactor

Conversation

@swangi-kumari
Copy link
Contributor

@swangi-kumari swangi-kumari commented Dec 1, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Charges can be collected on payments for collecting fees for resellers. Adyen, Stripe allows creating charges on payment intents using their marketplace platform.

The support for collecting charges on payments and refunding charges needs to be added.

Payments

  • A new field split_payments is introduced to read charge specific details
  • Charge details are sent to the connector where request is transformed and sent
  • charge_id is returned by the connector which is persisted in payment_attempt table. This can later be used for refunding charges
    Before
"charges": {
        "charge_type": "destination",
            "fees": 100,
            "transfer_account_id":"{{CONNECTED_ACCOUNT_ID}}"
    }

Changes in this PR

"split_payments": {
    	"stripe_split_payment": {
        	"charge_type": "direct",
        	"application_fees": 100,
        	"transfer_account_id": "{{CONNECTED_ACCOUNT_ID}}"
    	}
}

Refunds

  • A new field split_refunds is introduced to read charge id and refund options
  • charge_id created during payments is fetched and used as a reference
    Before
 "charges": {
     "charge_id": "{CHARGE ID}",
     "revert_platform_fee": true,
     "revert_transfer": true
 }

Changes in this PR

"split_refunds": {
    		"stripe_split_refund": {
        		"revert_platform_fee": true,
        		"revert_transfer": true
    		}
	}

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

  1. Create Merchant Account
  2. Create API KEY
  3. Create Stripe Connector
curl --location 'http://localhost:8080/account/merchant_1733139894/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: integ-custom' \
--header 'api-key: ______' \
--data '{
    "connector_type": "payment_processor",
    "connector_name": "stripe",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "_______"
    },
    "test_mode": true,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "affirm",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "afterpay_clearpay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "bank_debit",
            "payment_method_types": [
                {
                    "payment_method_type": "ach",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ]
}'

I. Direct Charges

  1. Create charge on a Payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: ______' \
--data '{
    "amount": 200,
    "profile_id": "pro_zxqGZoX7GWtERcmSiOKz",
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "amount_to_capture": 200,
    "customer_id": "cust_no_pm",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "payment_method": "card",
    "payment_method_type": "debit",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "12",
            "card_exp_year": "34",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "split_payments": {
        "stripe_split_payment": {
            "charge_type": "direct",
            "application_fees": 100,
            "transfer_account_id": "acct_1PDftAIhl7EEkW0O"
        }
    }
}'

Response

{
    "payment_id": "pay_hCpC82M0IRXHCQBsO0jG",
    "merchant_id": "merchant_1733386856",
    "status": "succeeded",
    "amount": 200,
    "net_amount": 200,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 200,
    "connector": "stripe",
    "client_secret": "pay_hCpC82M0IRXHCQBsO0jG_secret_TgKJgpPoxO420p9crUI9",
    "created": "2024-12-06T11:34:54.293Z",
    "currency": "USD",
    "customer_id": "cust_no_pm",
    "customer": {
        "id": "cust_no_pm",
        "name": "John Doe",
        "email": null,
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "12",
            "card_exp_year": "34",
            "card_holder_name": null,
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": null,
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cust_no_pm",
        "created_at": 1733484894,
        "expires": 1733488494,
        "secret": "epk_88436523e5054069afa72612dc3614a3"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QSzoAIhl7EEkW0O1IkSTtgi",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QSzoAIhl7EEkW0O1IkSTtgi",
    "payment_link": null,
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-06T11:49:54.293Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-06T11:34:56.115Z",
    "split_payments": {
        "stripe_split_payment": {
            "charge_id": "ch_3QSzoAIhl7EEkW0O12IPHRiC",
            "charge_type": "direct",
            "application_fees": 100,
            "transfer_account_id": "acct_1PDftAIhl7EEkW0O"
        }
    },
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}
  1. Payment Sync
curl --location 'http://localhost:8080/payments/pay_hCpC82M0IRXHCQBsO0jG' \
--header 'Accept: application/json' \
--header 'api-key: _'

Response

{
    "payment_id": "pay_5F8NC4paD8bg8NVnka6J",
    "merchant_id": "merchant_1733386856",
    "status": "succeeded",
    "amount": 200,
    "net_amount": 200,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 200,
    "connector": "stripe",
    "client_secret": "pay_5F8NC4paD8bg8NVnka6J_secret_810pk3NhPAJq7SyOVP0k",
    "created": "2024-12-05T10:58:55.747Z",
    "currency": "USD",
    "customer_id": "cust_no_pm",
    "customer": {
        "id": "cust_no_pm",
        "name": "John Doe",
        "email": null,
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "12",
            "card_exp_year": "34",
            "card_holder_name": null,
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": null,
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QScloIhl7EEkW0O2WeUMnx4",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QScloIhl7EEkW0O2WeUMnx4",
    "payment_link": null,
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-05T11:13:55.747Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-05T10:58:57.440Z",
    "split_payments": {
        "stripe_split_payment": {
            "charge_id": "ch_3QScloIhl7EEkW0O2g9wekLT",
            "charge_type": "direct",
            "application_fees": 100,
            "transfer_account_id": "acct_1PDftAIhl7EEkW0O"
        }
    },
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}
  1. Create Refund
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: ______' \
--data '{
    "payment_id": "pay_hCpC82M0IRXHCQBsO0jG",
    "amount": 200,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2024-05-05T10:11:12Z"
    },
    "split_refunds": {
        "stripe_split_refund": {
            "revert_platform_fee": true
        }
    }
}'

Response

{
    "refund_id": "ref_rnc9z3xBF94GIanCSByG",
    "payment_id": "pay_5F8NC4paD8bg8NVnka6J",
    "amount": 200,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2024-05-05T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-12-05T11:00:13.205Z",
    "updated_at": "2024-12-05T11:00:15.037Z",
    "connector": "stripe",
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "split_refunds": {
        "stripe_split_refund": {
            "revert_platform_fee": true,
            "revert_transfer": null
        }
    }
}
  1. Refund Sync
curl --location 'http://localhost:8080/refunds/sync' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'api-key: _' \
--data '{
    "refund_id": "ref_6OjFwcPC1yDIIF05zuN5",
    "force_sync": true
}'

Response

{
    "refund_id": "ref_rnc9z3xBF94GIanCSByG",
    "payment_id": "pay_5F8NC4paD8bg8NVnka6J",
    "amount": 200,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2024-05-05T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-12-05T11:00:13.205Z",
    "updated_at": "2024-12-05T11:00:18.624Z",
    "connector": "stripe",
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "split_refunds": {
        "stripe_split_refund": {
            "revert_platform_fee": true,
            "revert_transfer": null
        }
    }
}

II. Destination Charges

  1. Create a charge on payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: _' \
--data '{
    "amount": 6540,
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "new",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "debit",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "12",
            "card_exp_year": "34",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "split_payments": {
        "stripe_split_payment": {
            "charge_type": "destination",
            "application_fees": 100,
            "transfer_account_id": "acct_1PDftAIhl7EEkW0O"
        }
    }
}'

Response

{
    "payment_id": "pay_goWewVT3vwQrWEQC2zpC",
    "merchant_id": "merchant_1733386856",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "stripe",
    "client_secret": "pay_goWewVT3vwQrWEQC2zpC_secret_UJskiDNGAS6O8NbeRQ0E",
    "created": "2024-12-05T11:00:23.307Z",
    "currency": "USD",
    "customer_id": "new",
    "customer": {
        "id": "new",
        "name": "John Doe",
        "email": null,
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "12",
            "card_exp_year": "34",
            "card_holder_name": null,
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": null,
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "new",
        "created_at": 1733396423,
        "expires": 1733400023,
        "secret": "epk_e06e9125bac144c8a9a9f0cb20fa7135"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QScnDIVaesDjvMP036XjmWQ",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QScnDIVaesDjvMP036XjmWQ",
    "payment_link": null,
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-05T11:15:23.307Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-05T11:00:25.206Z",
    "split_payments": {
        "stripe_split_payment": {
            "charge_id": "ch_3QScnDIVaesDjvMP09pnAixC",
            "charge_type": "destination",
            "application_fees": 100,
            "transfer_account_id": "acct_1PDftAIhl7EEkW0O"
        }
    },
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}
  1. Payment Sync
curl --location 'http://localhost:8080/payments/pay_hCpC82M0IRXHCQBsO0jG' \
--header 'Accept: application/json' \
--header 'api-key: _'

Response

{
    "payment_id": "pay_hCpC82M0IRXHCQBsO0jG",
    "merchant_id": "merchant_1733386856",
    "status": "succeeded",
    "amount": 200,
    "net_amount": 200,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 200,
    "connector": "stripe",
    "client_secret": "pay_hCpC82M0IRXHCQBsO0jG_secret_TgKJgpPoxO420p9crUI9",
    "created": "2024-12-06T11:34:54.293Z",
    "currency": "USD",
    "customer_id": "cust_no_pm",
    "customer": {
        "id": "cust_no_pm",
        "name": "John Doe",
        "email": null,
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "12",
            "card_exp_year": "34",
            "card_holder_name": null,
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": null,
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QSzoAIhl7EEkW0O1IkSTtgi",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QSzoAIhl7EEkW0O1IkSTtgi",
    "payment_link": null,
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-06T11:49:54.293Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-06T11:34:56.115Z",
    "split_payments": {
        "stripe_split_payment": {
            "charge_id": "ch_3QSzoAIhl7EEkW0O12IPHRiC",
            "charge_type": "direct",
            "application_fees": 100,
            "transfer_account_id": "acct_1PDftAIhl7EEkW0O"
        }
    },
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}
  1. Create a Refund
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_5sqSbSWLn96RJpHuxQoXV4Cn9AOKqWjxxyDcQalE7ACxWXL5NFV6WTxptuWVhIhY' \
--data '{
    "payment_id": "pay_hCpC82M0IRXHCQBsO0jG",
    "amount": 6540,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2024-05-05T10:11:12Z"
    },
     "split_refunds": {
        "stripe_split_refund": {
            
            "revert_platform_fee": true,
            "revert_transfer": true
        }
    }
}'

Response

{
    "refund_id": "ref_6OjFwcPC1yDIIF05zuN5",
    "payment_id": "pay_goWewVT3vwQrWEQC2zpC",
    "amount": 6540,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2024-05-05T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-12-05T11:00:28.575Z",
    "updated_at": "2024-12-05T11:00:30.812Z",
    "connector": "stripe",
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "split_refunds": {
        "stripe_split_refund": {
            "revert_platform_fee": true,
            "revert_transfer": true
        }
    }
}
  1. Refund Sync
curl --location 'http://localhost:8080/refunds/ref_6OjFwcPC1yDIIF05zuN5' \
--header 'Accept: application/json' \
--header 'api-key: ___'

Response

{
    "refund_id": "ref_6OjFwcPC1yDIIF05zuN5",
    "payment_id": "pay_goWewVT3vwQrWEQC2zpC",
    "amount": 6540,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2024-05-05T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-12-05T11:00:28.575Z",
    "updated_at": "2024-12-05T11:00:30.812Z",
    "connector": "stripe",
    "profile_id": "pro_eSge5v6egtjkbZWDvvZY",
    "merchant_connector_id": "mca_xWtFAyzTrLDHK4ogUND0",
    "split_refunds": {
        "stripe_split_refund": {
            "revert_platform_fee": true,
            "revert_transfer": true
        }
    }
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@swangi-kumari swangi-kumari added A-core Area: Core flows C-refactor Category: Refactor labels Dec 1, 2024
@swangi-kumari swangi-kumari self-assigned this Dec 1, 2024
@swangi-kumari swangi-kumari requested review from a team as code owners December 1, 2024 19:17
@semanticdiff-com
Copy link

semanticdiff-com bot commented Dec 1, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/connector/stripe/transformers.rs  87% smaller
  crates/router/src/core/refunds/validator.rs  86% smaller
  crates/router/src/connector/stripe.rs  66% smaller
  crates/router/src/core/payments/helpers.rs  59% smaller
  api-reference-v2/openapi_spec.json  58% smaller
  crates/api_models/src/refunds.rs  57% smaller
  api-reference/openapi_spec.json  56% smaller
  crates/hyperswitch_domain_models/src/payments/payment_intent.rs  50% smaller
  crates/router/src/core/payments/operations/payment_create.rs  40% smaller
  crates/router/src/core/refunds.rs  32% smaller
  crates/router/src/core/payments/transformers.rs  32% smaller
  crates/router/src/core/refunds/transformers.rs  31% smaller
  crates/hyperswitch_domain_models/src/router_request_types.rs  29% smaller
  crates/hyperswitch_domain_models/src/payments.rs  18% smaller
  crates/api_models/src/payments.rs  9% smaller
  crates/router/src/core/utils.rs  8% smaller
  crates/openapi/src/openapi.rs  2% smaller
  crates/openapi/src/openapi_v2.rs  2% smaller
  crates/router/src/core/payments/types.rs  2% smaller
  Cargo.lock Unsupported file format
  crates/api_models/Cargo.toml Unsupported file format
  crates/api_models/src/enums.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/common_types/Cargo.toml Unsupported file format
  crates/common_types/src/lib.rs  0% smaller
  crates/common_types/src/payments.rs  0% smaller
  crates/common_types/src/refunds.rs  0% smaller
  crates/diesel_models/Cargo.toml Unsupported file format
  crates/diesel_models/src/payment_intent.rs  0% smaller
  crates/diesel_models/src/refund.rs  0% smaller
  crates/diesel_models/src/schema.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/Cargo.toml Unsupported file format
  crates/openapi/Cargo.toml Unsupported file format
  crates/router/Cargo.toml Unsupported file format
  crates/router/src/db/refund.rs  0% smaller
  crates/router/src/types.rs  0% smaller
  crates/router/src/types/api/verify_connector.rs  0% smaller
  crates/router/src/utils/user/sample_data.rs  0% smaller
  crates/router/tests/connectors/utils.rs  0% smaller
  crates/router/tests/payments.rs  0% smaller
  crates/router/tests/payments2.rs  0% smaller
  migrations/2024-11-22-091336_add_split_payments_in_payment_intent/down.sql Unsupported file format
  migrations/2024-11-22-091336_add_split_payments_in_payment_intent/up.sql Unsupported file format
  migrations/2024-11-28-103344_add_split_refunds/down.sql Unsupported file format
  migrations/2024-11-28-103344_add_split_refunds/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Dec 1, 2024
@swangi-kumari swangi-kumari force-pushed the split-payments-refactor branch from 85e0b3a to 13ea66f Compare December 2, 2024 07:55
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 2, 2024
@swangi-kumari swangi-kumari force-pushed the split-payments-refactor branch 4 times, most recently from 81af0b1 to 2b26ce6 Compare December 4, 2024 11:43
SanchithHegde
SanchithHegde previously approved these changes Dec 10, 2024
Narayanbhat166
Narayanbhat166 previously approved these changes Dec 10, 2024
apoorvdixit88
apoorvdixit88 previously approved these changes Dec 10, 2024
SanchithHegde
SanchithHegde previously approved these changes Dec 11, 2024
Narayanbhat166
Narayanbhat166 previously approved these changes Dec 11, 2024
apoorvdixit88
apoorvdixit88 previously approved these changes Dec 11, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Dec 13, 2024
Merged via the queue into main with commit 5a85213 Dec 13, 2024
@Gnanasundari24 Gnanasundari24 deleted the split-payments-refactor branch December 13, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core flows C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants