Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(connector): [Trustly] Implement Payouts (#11538)

Vani Gupta0ef39e8bc949
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 44a0b05e90..c88b2cf478 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -11138,6 +11138,9 @@
},
{
"$ref": "#/components/schemas/PixBankTransfer"
+ },
+ {
+ "$ref": "#/components/schemas/TrustlyBankTransfer"
}
]
},
@@ -11154,6 +11157,9 @@
},
{
"$ref": "#/components/schemas/PixBankTransferAdditionalData"
+ },
+ {
+ "$ref": "#/components/schemas/TrustlyBankTransferAdditionalData"
}
],
"description": "Masked payout method details for bank payout method"
@@ -15074,6 +15080,7 @@
"tesouro",
"tokenex",
"tokenio",
+ "trustly",
"truelayer",
"trustpay",
"trustpayments",
@@ -32692,6 +32699,7 @@
"paypal",
"stripe",
"truelayer",
+ "trustly",
"wise",
"worldpay",
"worldpayxml",
@@ -37094,6 +37102,7 @@
"stripebilling",
"tesouro",
"truelayer",
+ "trustly",
"trustpay",
"trustpayments",
"tokenio",
@@ -39567,6 +39576,65 @@
"external"
]
},
+ "TrustlyBankTransfer": {
+ "type": "object",
+ "required": [
+ "iban",
+ "country_code",
+ "account_number",
+ "bank_number"
+ ],
+ "properties": {
+ "iban": {
+ "type": "string",
+ "description": "International Bank Account Number (iban) - used in many countries for identifying a bank along with it's customer.",
+ "example": "token_12345"
+ },
+ "country_code": {
+ "$ref": "#/components/schemas/CountryAlpha2"
+ },
+ "account_number": {
+ "type": "string",
+ "description": "The account number, identifying the end-user's account in the bank.",
+ "example": "69706212"
+ },
+ "bank_number": {
+ "type": "string",
+ "description": "The bank number identifying the end-user's bank in the given clearing house.",
+ "example": "6112"
+ }
+ }
+ },
+ "TrustlyBankTransferAdditionalData": {
+ "type": "object",
+ "description": "Masked payout method details for Trustly bank transfer payout method",
+ "required": [
+ "iban",
+ "country_code",
+ "account_number",
+ "bank_number"
+ ],
+ "properties": {
+ "iban": {
+ "type": "string",
+ "description": "International Bank Account Number (iban) - used in many countries for identifying a bank along with it's customer.",
+ "example": "token_12345"
+ },
+ "country_code": {
+ "$ref": "#/components/schemas/CountryAlpha2"
+ },
+ "account_number": {
+ "type": "string",
+ "description": "The account number, identifying the end-user's account in the bank.",
+ "example": "69706212"
+ },
+ "bank_number": {
+ "type": "string",
+ "description": "The bank number identifying the end-user's bank in the given clearing house.",
+ "example": "6112"
+ }
+ }
+ },
"TxnStatus": {
"type": "string",
"enum": [
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 5a51b78515..ba70713895 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -7004,6 +7004,9 @@
},
{
"$ref": "#/components/schemas/PixBankTransfer"
+ },
+ {
+ "$ref": "#/components/schemas/TrustlyBankTransfer"
}
]
},
@@ -7020,6 +7023,9 @@
},
{
"$ref": "#/components/schemas/PixBankTransferAdditionalData"
+ },
+ {
+ "$ref": "#/components/schemas/TrustlyBankTransferAdditionalData"
}
],
"description": "Masked payout method details for bank payout method"
@@ -10622,6 +10628,7 @@
"tesouro",
"tokenex",
"tokenio",
+ "trustly",
"truelayer",
"trustpay",
"trustpayments",
@@ -24069,6 +24076,7 @@
"paypal",
"stripe",
"truelayer",
+ "trustly",
"wise",
"worldpay",
"worldpayxml",
@@ -27733,6 +27741,7 @@
"stripebilling",
"tesouro",
"truelayer",
+ "trustly",
"trustpay",
"trustpayments",
"tokenio",
@@ -29966,6 +29975,65 @@
"external"
]
},
+ "TrustlyBankTransfer": {
+ "type": "object",
+ "required": [
+ "iban",
+ "country_code",
+ "account_number",
+ "bank_number"
+ ],
+ "properties": {
+ "iban": {
+ "type": "string",
+ "description": "International Bank Account Number (iban) - used in many countries for identifying a bank along with it's customer.",
+ "example": "token_12345"
+ },
+ "country_code": {
+ "$ref": "#/components/schemas/CountryAlpha2"
+ },
+ "account_number": {
+ "type": "string",
+ "description": "The account number, identifying the end-user's account in the bank.",
+ "example": "69706212"
+ },
+ "bank_number": {
+ "type": "string",
+ "description": "The bank number identifying the end-user's bank in the given clearing house.",
+ "example": "6112"
+ }
+ }
+ },
+ "TrustlyBankTransferAdditionalData": {
+ "type": "object",
+ "description": "Masked payout method details for Trustly bank transfer payout method",
+ "required": [
+ "iban",
+ "country_code",
+ "account_number",
+ "bank_number"
+ ],
+ "properties": {
+ "iban": {
+ "type": "string",
+ "description": "International Bank Account Number (iban) - used in many countries for identifying a bank along with it's customer.",
+ "example": "token_12345"
+ },
+ "country_code": {
+ "$ref": "#/components/schemas/CountryAlpha2"
+ },
+ "account_number": {
+ "type": "string",
+ "description": "The account number, identifying the end-user's account in the bank.",
+ "example": "69706212"
+ },
+ "bank_number": {
+ "type": "string",
+ "description": "The bank number identifying the end-user's bank in the given clearing house.",
+ "example": "6112"
+ }
+ }
+ },
"UIWidgetFormLayout": {
"type": "string",
"enum": [
diff --git a/config/config.example.toml b/config/config.example.toml
index 709788a439..4891759442 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -734,6 +734,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.plaid]
open_banking_pis = {currency = "EUR,GBP"}
@@ -1043,7 +1046,7 @@ google_pay = { country = "AF,DZ,AW,AU,AZ,BS,BH,BD,BB,BZ,BM,BT,BO,BA,BW,BR,BN,BG,
apple_pay = { country = "AF,DZ,AW,AU,AZ,BS,BH,BD,BB,BZ,BM,BT,BO,BA,BW,BR,BN,BG,BI,KH,CA,CV,KY,CL,CO,KM,CD,CR,CZ,DK,DJ,ST,DO,EC,EG,SV,ER,ET,FK,FJ,GM,GE,GH,GI,GT,GN,GY,HT,HN,HK,HU,IS,IN,ID,IR,IQ,IE,IL,IT,JM,JP,JO,KZ,KE,KW,LA,LB,LS,LR,LY,LT,MO,MK,MG,MW,MY,MV,MR,MU,MX,MD,MN,MA,MZ,MM,NA,NZ,NI,NG,KP,NO,AR,PK,PG,PY,PE,UY,PH,PL,GB,QA,OM,RO,RU,RW,WS,SG,ST,ZA,KR,LK,SH,SD,SR,SZ,SE,CH,SY,TW,TJ,TZ,TH,TT,TN,TR,UG,UA,US,UZ,VU,VE,VN,ZM,ZW", currency = "AFN,DZD,ANG,AWG,AUD,AZN,BSD,BHD,BDT,BBD,BZD,BMD,BTN,BOB,BAM,BWP,BRL,BND,BGN,BIF,KHR,CAD,CVE,KYD,XOF,XAF,XPF,CLP,COP,KMF,CDF,CRC,EUR,CZK,DKK,DJF,DOP,XCD,EGP,SVC,ERN,ETB,EUR,FKP,FJD,GMD,GEL,GHS,GIP,GTQ,GNF,GYD,HTG,HNL,HKD,HUF,ISK,INR,IDR,IRR,IQD,ILS,JMD,JPY,JOD,KZT,KES,KWD,LAK,LBP,LSL,LRD,LYD,MOP,MKD,MGA,MWK,MYR,MVR,MRU,MUR,MXN,MDL,MNT,MAD,MZN,MMK,NAD,NPR,NZD,NIO,NGN,KPW,NOK,ARS,PKR,PAB,PGK,PYG,PEN,UYU,PHP,PLN,GBP,QAR,OMR,RON,RUB,RWF,WST,SAR,RSD,SCR,SLL,SGD,STN,SBD,SOS,ZAR,KRW,LKR,SHP,SDG,SRD,SZL,SEK,CHF,SYP,TWD,TJS,TZS,THB,TOP,TTD,TND,TRY,TMT,AED,UGX,UAH,USD,UZS,VUV,VND,YER,CNY,ZMW,ZWL" }
[connector_customer]
-payout_connector_list = "nomupay,stripe,wise"
+payout_connector_list = "nomupay,stripe,wise,trustly"
[bank_config.online_banking_fpx]
adyen.banks = "affin_bank,agro_bank,alliance_bank,am_bank,bank_islam,bank_muamalat,bank_rakyat,bank_simpanan_nasional,cimb_bank,hong_leong_bank,hsbc_bank,kuwait_finance_house,maybank,ocbc_bank,public_bank,rhb_bank,standard_chartered_bank,uob_bank"
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index 869b970430..ac62d05cde 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -218,7 +218,7 @@ force_cookies = false
enabled = true
[connector_customer]
-payout_connector_list = "nomupay,stripe,wise"
+payout_connector_list = "nomupay,stripe,wise,trustly"
[delayed_session_response]
connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which have delayed session response
@@ -666,6 +666,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.redsys]
credit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }
debit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }
diff --git a/config/deployments/production.toml b/config/deployments/production.toml
index c65d36a786..19a7164925 100644
--- a/config/deployments/production.toml
+++ b/config/deployments/production.toml
@@ -15,7 +15,7 @@ open_banking_uk.adyen.banks = "aib,bank_of_scotland,danske_bank,first_direct,fir
przelewy24.stripe.banks = "alior_bank,bank_millennium,bank_nowy_bfg_sa,bank_pekao_sa,banki_spbdzielcze,blik,bnp_paribas,boz,citi,credit_agricole,e_transfer_pocztowy24,getin_bank,idea_bank,inteligo,mbank_mtransfer,nest_przelew,noble_pay,pbac_z_ipko,plus_bank,santander_przelew24,toyota_bank,volkswagen_bank"
[connector_customer]
-payout_connector_list = "nomupay,stripe,wise"
+payout_connector_list = "nomupay,stripe,wise,trustly"
# Connector configuration, provided attributes will be used to fulfill API requests.
# Examples provided here are sandbox/test base urls, can be replaced by live or mock
@@ -708,6 +708,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.redsys]
credit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }
debit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index cb82221bbc..e4bccafbec 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -15,7 +15,7 @@ open_banking_uk.adyen.banks = "aib,bank_of_scotland,danske_bank,first_direct,fir
przelewy24.stripe.banks = "alior_bank,bank_millennium,bank_nowy_bfg_sa,bank_pekao_sa,banki_spbdzielcze,blik,bnp_paribas,boz,citi,credit_agricole,e_transfer_pocztowy24,getin_bank,idea_bank,inteligo,mbank_mtransfer,nest_przelew,noble_pay,pbac_z_ipko,plus_bank,santander_przelew24,toyota_bank,volkswagen_bank"
[connector_customer]
-payout_connector_list = "nomupay,stripe,wise"
+payout_connector_list = "nomupay,stripe,wise,trustly"
# Connector configuration, provided attributes will be used to fulfill API requests.
# Examples provided here are sandbox/test base urls, can be replaced by live or mock
@@ -716,6 +716,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.redsys]
credit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }
debit = { currency = "AUD,BGN,CAD,CHF,COP,CZK,DKK,EUR,GBP,HRK,HUF,ILS,INR,JPY,MYR,NOK,NZD,PEN,PLN,RUB,SAR,SEK,SGD,THB,USD,ZAR", country="ES" }
diff --git a/config/development.toml b/config/development.toml
index 7de7350185..a59f32f5e7 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -540,6 +540,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.plaid]
open_banking_pis = { currency = "EUR,GBP" }
@@ -1115,7 +1118,7 @@ nexixpay = { payment_method = "card" }
redsys = { payment_method = "card" }
[connector_customer]
-payout_connector_list = "nomupay,stripe,wise"
+payout_connector_list = "nomupay,stripe,wise,trustly"
[dummy_connector]
enabled = true
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 51835071e4..ae1062c1bb 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -643,6 +643,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.payu]
debit = { country = "AE, AF, AL, AM, CW, AO, AR, AU, AW, AZ, BA, BB, BG, BH, BI, BM, BN, BO, BR, BS, BW, BY, BZ, CA, CD, LI, CL, CN, CO, CR, CV, CZ, DJ, DK, DO, DZ, EG, ET, AD, FJ, FK, GG, GE, GH, GI, GM, GN, GT, GY, HK, HN, HR, HT, HU, ID, IL, IQ, IS, JM, JO, JP, KG, KH, KM, KR, KW, KY, KZ, LA, LB, LR, LS, MA, MD, MG, MK, MN, MO, MR, MV, MW, MX, MY, MZ, NA, NG, NI, BV, CK, OM, PA, PE, PG, PL, PY, QA, RO, RS, RW, SA, SB, SC, SE, SG, SH, SO, SR, SV, SZ, TH, TJ, TM, TN, TO, TR, TT, TW, TZ, UG, AS, UY, UZ, VE, VN, VU, WS, CM, AI, BJ, PF, YE, ZA, ZM, ZW", currency = "AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BGN, BHD, BIF, BMD, BND, BOB, BRL, BSD, BWP, BYN, BZD, CAD, CDF, CHF, CLP, CNY, COP, CRC, CVE, CZK, DJF, DKK, DOP, DZD, EGP, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, IQD, ISK, JMD, JOD, JPY, KGS, KHR, KMF, KRW, KWD, KYD, KZT, LAK, LBP, LRD, LSL, MAD, MDL, MGA, MKD, MNT, MOP, MRU, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NZD, OMR, PAB, PEN, PGK, PLN, PYG, QAR, RON, RSD, RWF, SAR, SBD, SCR, SEK, SGD, SHP, SOS, SRD, SVC, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UGX, USD, UYU, UZS, VES, VND, VUV, WST, XAF, XCD, XOF, XPF, YER, ZAR, ZMW, ZWL" }
credit = { country = "AE, AF, AL, AM, CW, AO, AR, AU, AW, AZ, BA, BB, BG, BH, BI, BM, BN, BO, BR, BS, BW, BY, BZ, CA, CD, LI, CL, CN, CO, CR, CV, CZ, DJ, DK, DO, DZ, EG, ET, AD, FJ, FK, GG, GE, GH, GI, GM, GN, GT, GY, HK, HN, HR, HT, HU, ID, IL, IQ, IS, JM, JO, JP, KG, KH, KM, KR, KW, KY, KZ, LA, LB, LR, LS, MA, MD, MG, MK, MN, MO, MR, MV, MW, MX, MY, MZ, NA, NG, NI, BV, CK, OM, PA, PE, PG, PL, PY, QA, RO, RS, RW, SA, SB, SC, SE, SG, SH, SO, SR, SV, SZ, TH, TJ, TM, TN, TO, TR, TT, TW, TZ, UG, AS, UY, UZ, VE, VN, VU, WS, CM, AI, BJ, PF, YE, ZA, ZM, ZW", currency = "AED, AFN, ALL, AMD, ANG, AOA, ARS, AUD, AWG, AZN, BAM, BBD, BGN, BHD, BIF, BMD, BND, BOB, BRL, BSD, BWP, BYN, BZD, CAD, CDF, CHF, CLP, CNY, COP, CRC, CVE, CZK, DJF, DKK, DOP, DZD, EGP, ETB, EUR, FJD, FKP, GBP, GEL, GHS, GIP, GMD, GNF, GTQ, GYD, HKD, HNL, HRK, HTG, HUF, IDR, ILS, IQD, ISK, JMD, JOD, JPY, KGS, KHR, KMF, KRW, KWD, KYD, KZT, LAK, LBP, LRD, LSL, MAD, MDL, MGA, MKD, MNT, MOP, MRU, MVR, MWK, MXN, MYR, MZN, NAD, NGN, NIO, NOK, NZD, OMR, PAB, PEN, PGK, PLN, PYG, QAR, RON, RSD, RWF, SAR, SBD, SCR, SEK, SGD, SHP, SOS, SRD, SVC, SZL, THB, TJS, TMT, TND, TOP, TRY, TTD, TWD, TZS, UGX, USD, UYU, UZS, VES, VND, VUV, WST, XAF, XCD, XOF, XPF, YER, ZAR, ZMW, ZWL" }
@@ -1120,7 +1123,7 @@ connector_list = "adyen,archipel,checkout,cybersource,novalnet,stripe,worldpay,w
connector_list = "peachpayments" # Supported connectors for card only mit
[connector_customer]
-payout_connector_list = "nomupay,stripe,wise"
+payout_connector_list = "nomupay,stripe,wise,trustly"
[payment_method_auth]
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs
index 82dfb6a7d4..b90b7cc522 100644
--- a/crates/api_models/src/enums.rs
+++ b/crates/api_models/src/enums.rs
@@ -58,6 +58,7 @@ pub enum PayoutConnectors {
Paypal,
Stripe,
Truelayer,
+ Trustly,
Wise,
Worldpay,
Worldpayxml,
@@ -101,6 +102,7 @@ impl From<PayoutConnectors> for RoutableConnectors {
PayoutConnectors::Paypal => Self::Paypal,
PayoutConnectors::Stripe => Self::Stripe,
PayoutConnectors::Truelayer => Self::Truelayer,
+ PayoutConnectors::Trustly => Self::Trustly,
PayoutConnectors::Wise => Self::Wise,
PayoutConnectors::Worldpay => Self::Worldpay,
PayoutConnectors::Worldpayxml => Self::Worldpayxml,
@@ -125,6 +127,7 @@ impl From<PayoutConnectors> for Connector {
PayoutConnectors::Paypal => Self::Paypal,
PayoutConnectors::Stripe => Self::Stripe,
PayoutConnectors::Truelayer => Self::Truelayer,
+ PayoutConnectors::Trustly => Self::Trustly,
PayoutConnectors::Wise => Self::Wise,
PayoutConnectors::Worldpay => Self::Worldpay,
PayoutConnectors::Worldpayxml => Self::Worldpayxml,
@@ -150,6 +153,7 @@ impl TryFrom<Connector> for PayoutConnectors {
Connector::Paypal => Ok(Self::Paypal),
Connector::Stripe => Ok(Self::Stripe),
Connector::Truelayer => Ok(Self::Truelayer),
+ Connector::Trustly => Ok(Self::Trustly),
Connector::Wise => Ok(Self::Wise),
Connector::Worldpay => Ok(Self::Worldpay),
Connector::Worldpayxml => Ok(Self::Worldpayxml),
diff --git a/crates/api_models/src/payouts.rs b/crates/api_models/src/payouts.rs
index 49d3b29d97..67988a3c1e 100644
--- a/crates/api_models/src/payouts.rs
+++ b/crates/api_models/src/payouts.rs
@@ -284,6 +284,7 @@ pub enum Bank {
Bacs(BacsBankTransfer),
Sepa(SepaBankTransfer),
Pix(PixBankTransfer),
+ Trustly(TrustlyBankTransfer),
}
#[derive(Default, Eq, PartialEq, Clone, Debug, Deserialize, Serialize, ToSchema)]
@@ -411,6 +412,22 @@ pub struct OpenBankingUk {
pub iban: Secret<String>,
}
+#[derive(Default, Eq, PartialEq, Clone, Debug, Deserialize, Serialize, ToSchema)]
+pub struct TrustlyBankTransfer {
+ /// International Bank Account Number (iban) - used in many countries for identifying a bank along with it's customer.
+ #[schema(value_type = String, example = "token_12345")]
+ pub iban: Option<Secret<String>>,
+ /// country code of the customer's bank account.
+ #[schema(value_type = CountryAlpha2, example = "US")]
+ pub country_code: api_enums::CountryAlpha2,
+ /// The account number, identifying the end-user's account in the bank.
+ #[schema(value_type = String, example = "69706212")]
+ pub account_number: Option<Secret<String>>,
+ /// The bank number identifying the end-user's bank in the given clearing house.
+ #[schema(value_type = String, example = "6112")]
+ pub bank_number: Option<Secret<String>>,
+}
+
#[derive(Eq, PartialEq, Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct Passthrough {
@@ -1051,6 +1068,19 @@ impl From<Bank> for payout_method_utils::BankAdditionalData {
tax_id: tax_id.map(From::from),
},
)),
+ Bank::Trustly(TrustlyBankTransfer {
+ iban,
+ country_code,
+ account_number,
+ bank_number,
+ }) => Self::Trustly(Box::new(
+ payout_method_utils::TrustlyBankTransferAdditionalData {
+ iban,
+ country_code,
+ account_number,
+ bank_number,
+ },
+ )),
}
}
}
diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs
index 9ab5786032..308d821e27 100644
--- a/crates/common_enums/src/connector_enums.rs
+++ b/crates/common_enums/src/connector_enums.rs
@@ -181,6 +181,7 @@ pub enum Connector {
Tesouro,
Tokenex,
Tokenio,
+ Trustly,
Truelayer,
Trustpay,
Trustpayments,
@@ -217,13 +218,17 @@ impl Connector {
| (Self::Nomupay, _)
| (Self::Loonio, _)
| (Self::Truelayer, _)
+ | (Self::Trustly, _)
| (Self::Worldpay, Some(PayoutType::Wallet))
| (Self::Worldpayxml, Some(PayoutType::Wallet))
)
}
#[cfg(feature = "payouts")]
pub fn supports_create_recipient(self, payout_method: Option<PayoutType>) -> bool {
- matches!((self, payout_method), (_, Some(PayoutType::Bank)))
+ matches!(
+ (self, payout_method),
+ (_, Some(PayoutType::Bank)) | (Self::Trustly, _)
+ )
}
#[cfg(feature = "payouts")]
pub fn supports_payout_eligibility(self, payout_method: Option<PayoutType>) -> bool {
@@ -394,6 +399,7 @@ impl Connector {
| Self::Tesouro
// | Self::Thunes
| Self::Truelayer
+ | Self::Trustly
| Self::Trustpay
| Self::Trustpayments
// | Self::Tokenio
diff --git a/crates/common_utils/src/payout_method_utils.rs b/crates/common_utils/src/payout_method_utils.rs
index c98ad635c9..bd5c687663 100644
--- a/crates/common_utils/src/payout_method_utils.rs
+++ b/crates/common_utils/src/payout_method_utils.rs
@@ -89,6 +89,8 @@ pub enum BankAdditionalData {
Sepa(Box<SepaBankTransferAdditionalData>),
/// Additional data for pix bank transfer payout method
Pix(Box<PixBankTransferAdditionalData>),
+ /// Additional data for Trustly bank transfer payout method
+ Trustly(Box<TrustlyBankTransferAdditionalData>),
}
/// Masked payout method details for ach bank transfer payout method
@@ -199,6 +201,26 @@ pub struct PixBankTransferAdditionalData {
pub bank_branch: Option<String>,
}
+/// Masked payout method details for Trustly bank transfer payout method
+#[derive(
+ Default, Eq, PartialEq, Clone, Debug, Deserialize, Serialize, FromSqlRow, AsExpression, ToSchema,
+)]
+#[diesel(sql_type = Jsonb)]
+pub struct TrustlyBankTransferAdditionalData {
+ /// International Bank Account Number (iban) - used in many countries for identifying a bank along with it's customer.
+ #[schema(value_type = String, example = "token_12345")]
+ pub iban: Option<Secret<String>>,
+ /// country code of the customer's bank account.
+ #[schema(value_type = CountryAlpha2, example = "US")]
+ pub country_code: common_enums::CountryAlpha2,
+ /// The account number, identifying the end-user's account in the bank.
+ #[schema(value_type = String, example = "69706212")]
+ pub account_number: Option<Secret<String>>,
+ /// The bank number identifying the end-user's bank in the given clearing house.
+ #[schema(value_type = String, example = "6112")]
+ pub bank_number: Option<Secret<String>>,
+}
+
/// Masked payout method details for wallet payout method
#[derive(
Eq, PartialEq, Clone, Debug, Deserialize, Serialize, FromSqlRow, AsExpression, ToSchema,
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index abbdc2c8f2..b811fcc079 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -375,6 +375,8 @@ pub struct ConnectorConfig {
pub trustly: Option<ConnectorTomlConfig>,
#[cfg(feature = "payouts")]
pub truelayer_payout: Option<ConnectorTomlConfig>,
+ #[cfg(feature = "payouts")]
+ pub trustly_payout: Option<ConnectorTomlConfig>,
pub trustpay: Option<ConnectorTomlConfig>,
pub trustpayments: Option<ConnectorTomlConfig>,
pub threedsecureio: Option<ConnectorTomlConfig>,
@@ -443,6 +445,7 @@ impl ConnectorConfig {
PayoutConnectors::Paypal => Ok(connector_data.paypal_payout),
PayoutConnectors::Stripe => Ok(connector_data.stripe_payout),
PayoutConnectors::Truelayer => Ok(connector_data.truelayer_payout),
+ PayoutConnectors::Trustly => Ok(connector_data.trustly_payout),
PayoutConnectors::Wise => Ok(connector_data.wise_payout),
PayoutConnectors::Worldpay => Ok(connector_data.worldpay_payout),
PayoutConnectors::Worldpayxml => Ok(connector_data.worldpayxml_payout),
@@ -618,6 +621,7 @@ impl ConnectorConfig {
Connector::Tokenex => Ok(connector_data.tokenex),
Connector::Tokenio => Ok(connector_data.tokenio),
Connector::Truelayer => Ok(connector_data.truelayer),
+ Connector::Trustly => Ok(connector_data.trustly),
Connector::Trustpay => Ok(connector_data.trustpay),
Connector::Trustpayments => Ok(connector_data.trustpayments),
Connector::Threedsecureio => Ok(connector_data.threedsecureio),
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index fe1d4f13cc..27690e691c 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -7876,6 +7876,20 @@ placeholder = "Enter your Private Key(Base64 encoded)"
required = true
type = "Text"
+[trustly_payout]
+[trustly_payout.connector_auth.BodyKey]
+api_key = "Username"
+key1 = "Password"
+[[trustly_payout.bank_transfer]]
+payment_method_type = "trustly"
+
+[trustly_payout.metadata.private_key]
+name = "private_key"
+label = "Private Key (Base64 encoded)"
+placeholder = "Enter your Private Key(Base64 encoded)"
+required = true
+type = "Text"
+
[tesouro]
[[tesouro.credit]]
payment_method_type = "Mastercard"
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index fc22cbf795..1898c94647 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -7131,6 +7131,20 @@ placeholder = "Enter your Private Key(Base64 encoded)"
required = true
type = "Text"
+[trustly_payout]
+[trustly_payout.connector_auth.BodyKey]
+api_key = "Username"
+key1 = "Password"
+[[trustly_payout.bank_transfer]]
+payment_method_type = "trustly"
+
+[trustly_payout.metadata.private_key]
+name = "private_key"
+label = "Private Key (Base64 encoded)"
+placeholder = "Enter your Private Key(Base64 encoded)"
+required = true
+type = "Text"
+
[revolv3]
[[revolv3.credit]]
payment_method_type = "Mastercard"
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index e2b3277b61..e69c28d096 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -8222,6 +8222,20 @@ placeholder = "Enter your Private Key(Base64 encoded)"
required = true
type = "Text"
+[trustly_payout]
+[trustly_payout.connector_auth.BodyKey]
+api_key = "Username"
+key1 = "Password"
+[[trustly_payout.bank_transfer]]
+payment_method_type = "trustly"
+
+[trustly_payout.metadata.private_key]
+name = "private_key"
+label = "Private Key (Base64 encoded)"
+placeholder = "Enter your Private Key(Base64 encoded)"
+required = true
+type = "Text"
+
[revolv3]
[[revolv3.credit]]
payment_method_type = "Mastercard"
diff --git a/crates/euclid/src/enums.rs b/crates/euclid/src/enums.rs
index 7958a230d2..7645b652f0 100644
--- a/crates/euclid/src/enums.rs
+++ b/crates/euclid/src/enums.rs
@@ -334,6 +334,7 @@ pub enum RoutableConnectors {
Tesouro,
// Taxjar,
Truelayer,
+ Trustly,
Trustpay,
Trustpayments,
// Thunes
@@ -481,6 +482,7 @@ impl TryFrom<Connector> for RoutableConnectors {
Connector::Stripebilling => Ok(Self::Stripebilling),
Connector::Tokenio => Ok(Self::Tokenio),
Connector::Tesouro => Ok(Self::Tesouro),
+ Connector::Trustly => Ok(Self::Trustly),
Connector::Truelayer => Ok(Self::Truelayer),
Connector::Trustpay => Ok(Self::Trustpay),
Connector::Trustpayments => Ok(Self::Trustpayments),
@@ -646,6 +648,7 @@ impl From<RoutableConnectors> for Connector {
RoutableConnectors::Tesouro => Self::Tesouro,
RoutableConnectors::Tokenio => Self::Tokenio,
RoutableConnectors::Truelayer => Self::Truelayer,
+ RoutableConnectors::Trustly => Self::Trustly,
RoutableConnectors::Trustpay => Self::Trustpay,
RoutableConnectors::Trustpayments => Self::Trustpayments,
// RoutableConnectors::Tokenio => Self::Tokenio,
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
index b3f803bc20..d62649173d 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
@@ -6241,6 +6241,10 @@ impl<F> TryFrom<&AdyenRouterData<&PayoutsRouterData<F>>> for AdyenPayoutCreateRe
message: "Bank transfer via Pix is not supported".to_string(),
connector: "Adyen",
})?,
+ payouts::Bank::Trustly(..) => Err(errors::ConnectorError::NotSupported {
+ message: "Bank transfer via Trustly is not supported".to_string(),
+ connector: "Adyen",
+ })?,
};
let bank_data = PayoutBankData { bank: bank_details };
let address: &hyperswitch_domain_models::address::AddressDetails =
diff --git a/crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs b/crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs
index fdca69c8ad..8cf49ac94c 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyenplatform/transformers/payouts.rs
@@ -545,6 +545,10 @@ impl<F> TryFrom<RawPaymentCounterparty<'_, F>>
message: "Bank transfer via Pix is not supported".to_string(),
connector: "Adyenplatform",
})?,
+ payouts::Bank::Trustly(..) => Err(ConnectorError::NotSupported {
+ message: "Bank transfer via Trustly is not supported".to_string(),
+ connector: "Adyenplatform",
+ })?,
};
let counterparty = AdyenPayoutMethodDetails::BankAccount(AdyenBankAccountDetails {
account_holder,
diff --git a/crates/hyperswitch_connectors/src/connectors/stripe/transformers/connect.rs b/crates/hyperswitch_connectors/src/connectors/stripe/transformers/connect.rs
index 58409f2b25..7afcd744ae 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripe/transformers/connect.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripe/transformers/connect.rs
@@ -440,6 +440,13 @@ impl<F> TryFrom<&PayoutsRouterData<F>> for StripeConnectRecipientAccountCreateRe
connector: "stripe",
}
.into()),
+ api_models::payouts::Bank::Trustly(_) => {
+ Err(errors::ConnectorError::NotSupported {
+ message: "Trustly payouts are not supported".to_string(),
+ connector: "stripe",
+ }
+ .into())
+ }
},
api_models::payouts::PayoutMethodData::Wallet(_) => {
Err(errors::ConnectorError::NotSupported {
diff --git a/crates/hyperswitch_connectors/src/connectors/trustly.rs b/crates/hyperswitch_connectors/src/connectors/trustly.rs
index dfbda0dd99..75dfcbe593 100644
--- a/crates/hyperswitch_connectors/src/connectors/trustly.rs
+++ b/crates/hyperswitch_connectors/src/connectors/trustly.rs
@@ -5,18 +5,18 @@ use std::sync::LazyLock;
use common_enums::enums;
use common_utils::{
errors::CustomResult,
- ext_traits::BytesExt,
+ ext_traits::ByteSliceExt,
request::{Method, Request, RequestBuilder, RequestContent},
- types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector},
+ types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
payment_method_data::PaymentMethodData,
router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{
- access_token_auth::AccessTokenAuth,
- payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
refunds::{Execute, RSync},
+ AccessTokenAuth, Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate,
+ Void,
},
router_request_types::{
AccessTokenRequestData, PaymentMethodTokenizationData, PaymentsAuthorizeData,
@@ -31,31 +31,41 @@ use hyperswitch_domain_models::{
RefundSyncRouterData, RefundsRouterData,
},
};
+#[cfg(feature = "payouts")]
+use hyperswitch_domain_models::{
+ router_flow_types::{PoFulfill, PoRecipient, PoSync},
+ types::{PayoutsData, PayoutsResponseData, PayoutsRouterData},
+};
use hyperswitch_interfaces::{
api::{
self, ConnectorCommon, ConnectorCommonExt, ConnectorIntegration, ConnectorSpecifications,
ConnectorValidation,
},
configs::Connectors,
- errors,
events::connector_api_logs::ConnectorEvent,
types::{self, Response},
webhooks,
};
-use masking::{ExposeInterface, Mask};
+#[cfg(feature = "payouts")]
+use hyperswitch_interfaces::{
+ errors::ConnectorError,
+ types::{PayoutFulfillType, PayoutSyncType},
+};
use transformers as trustly;
use crate::{constants::headers, types::ResponseRouterData, utils};
#[derive(Clone)]
pub struct Trustly {
- amount_converter: &'static (dyn AmountConvertor<Output = StringMinorUnit> + Sync),
+ #[cfg(feature = "payouts")]
+ amount_converter: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
}
impl Trustly {
pub fn new() -> &'static Self {
&Self {
- amount_converter: &StringMinorUnitForConnector,
+ #[cfg(feature = "payouts")]
+ amount_converter: &StringMajorUnitForConnector,
}
}
}
@@ -87,7 +97,7 @@ where
&self,
req: &RouterData<Flow, Request, Response>,
_connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
let mut header = vec![(
headers::CONTENT_TYPE.to_string(),
self.get_content_type().to_string().into(),
@@ -120,37 +130,32 @@ impl ConnectorCommon for Trustly {
fn get_auth_header(
&self,
- auth_type: &ConnectorAuthType,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- let auth = trustly::TrustlyAuthType::try_from(auth_type)
- .change_context(errors::ConnectorError::FailedToObtainAuthType)?;
- Ok(vec![(
- headers::AUTHORIZATION.to_string(),
- auth.api_key.expose().into_masked(),
- )])
+ _auth_type: &ConnectorAuthType,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
+ Ok(Vec::new())
}
fn build_error_response(
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
- ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
let response: trustly::TrustlyErrorResponse = res
.response
.parse_struct("TrustlyErrorResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
Ok(ErrorResponse {
status_code: res.status_code,
- code: response.code,
- message: response.message,
- reason: response.reason,
+ code: response.error.code.to_string(),
+ message: response.error.message.clone(),
+ reason: Some(response.error.message.clone()),
attempt_status: None,
connector_transaction_id: None,
- connector_response_reference_id: None,
+ connector_response_reference_id: Some(response.error.error.uuid),
network_advice_code: None,
network_decline_code: None,
network_error_message: None,
@@ -164,9 +169,9 @@ impl ConnectorValidation for Trustly {
&self,
_pm_type: Option<enums::PaymentMethodType>,
pm_data: PaymentMethodData,
- ) -> CustomResult<(), errors::ConnectorError> {
+ ) -> CustomResult<(), ConnectorError> {
match pm_data {
- PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented(
+ PaymentMethodData::Card(_) => Err(ConnectorError::NotImplemented(
"validate_mandate_payment does not support cards".to_string(),
)
.into()),
@@ -180,7 +185,7 @@ impl ConnectorValidation for Trustly {
_is_three_ds: bool,
_status: enums::AttemptStatus,
_connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,
- ) -> CustomResult<(), errors::ConnectorError> {
+ ) -> CustomResult<(), ConnectorError> {
Ok(())
}
}
@@ -198,7 +203,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
&self,
req: &PaymentsAuthorizeRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
self.build_headers(req, connectors)
}
@@ -210,15 +215,15 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
&self,
_req: &PaymentsAuthorizeRouterData,
_connectors: &Connectors,
- ) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ ) -> CustomResult<String, ConnectorError> {
+ Err(ConnectorError::NotImplemented("get_url method".to_string()).into())
}
fn get_request_body(
&self,
req: &PaymentsAuthorizeRouterData,
_connectors: &Connectors,
- ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ ) -> CustomResult<RequestContent, ConnectorError> {
let amount = utils::convert_amount(
self.amount_converter,
req.request.minor_amount,
@@ -234,7 +239,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
&self,
req: &PaymentsAuthorizeRouterData,
connectors: &Connectors,
- ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ ) -> CustomResult<Option<Request>, ConnectorError> {
Ok(Some(
RequestBuilder::new()
.method(Method::Post)
@@ -257,11 +262,11 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
data: &PaymentsAuthorizeRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
- ) -> CustomResult<PaymentsAuthorizeRouterData, errors::ConnectorError> {
+ ) -> CustomResult<PaymentsAuthorizeRouterData, ConnectorError> {
let response: trustly::TrustlyPaymentsResponse = res
.response
.parse_struct("Trustly PaymentsAuthorizeResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -275,7 +280,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
- ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
self.build_error_response(res, event_builder)
}
}
@@ -285,7 +290,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Tru
&self,
req: &PaymentsSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
self.build_headers(req, connectors)
}
@@ -297,15 +302,15 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Tru
&self,
_req: &PaymentsSyncRouterData,
_connectors: &Connectors,
- ) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ ) -> CustomResult<String, ConnectorError> {
+ Err(ConnectorError::NotImplemented("get_url method".to_string()).into())
}
fn build_request(
&self,
req: &PaymentsSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ ) -> CustomResult<Option<Request>, ConnectorError> {
Ok(Some(
RequestBuilder::new()
.method(Method::Get)
@@ -321,11 +326,11 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Tru
data: &PaymentsSyncRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
- ) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
+ ) -> CustomResult<PaymentsSyncRouterData, ConnectorError> {
let response: trustly::TrustlyPaymentsResponse = res
.response
.parse_struct("trustly PaymentsSyncResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -339,7 +344,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Tru
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
- ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
self.build_error_response(res, event_builder)
}
}
@@ -349,7 +354,7 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
&self,
req: &PaymentsCaptureRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
self.build_headers(req, connectors)
}
@@ -361,23 +366,23 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
&self,
_req: &PaymentsCaptureRouterData,
_connectors: &Connectors,
- ) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ ) -> CustomResult<String, ConnectorError> {
+ Err(ConnectorError::NotImplemented("get_url method".to_string()).into())
}
fn get_request_body(
&self,
_req: &PaymentsCaptureRouterData,
_connectors: &Connectors,
- ) -> CustomResult<RequestContent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
+ ) -> CustomResult<RequestContent, ConnectorError> {
+ Err(ConnectorError::NotImplemented("get_request_body method".to_string()).into())
}
fn build_request(
&self,
req: &PaymentsCaptureRouterData,
connectors: &Connectors,
- ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ ) -> CustomResult<Option<Request>, ConnectorError> {
Ok(Some(
RequestBuilder::new()
.method(Method::Post)
@@ -398,11 +403,11 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
data: &PaymentsCaptureRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
- ) -> CustomResult<PaymentsCaptureRouterData, errors::ConnectorError> {
+ ) -> CustomResult<PaymentsCaptureRouterData, ConnectorError> {
let response: trustly::TrustlyPaymentsResponse = res
.response
.parse_struct("Trustly PaymentsCaptureResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -416,7 +421,7 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
- ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
self.build_error_response(res, event_builder)
}
}
@@ -428,7 +433,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Trustly
&self,
req: &RefundsRouterData<Execute>,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
self.build_headers(req, connectors)
}
@@ -440,15 +445,15 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Trustly
&self,
_req: &RefundsRouterData<Execute>,
_connectors: &Connectors,
- ) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ ) -> CustomResult<String, ConnectorError> {
+ Err(ConnectorError::NotImplemented("get_url method".to_string()).into())
}
fn get_request_body(
&self,
req: &RefundsRouterData<Execute>,
_connectors: &Connectors,
- ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ ) -> CustomResult<RequestContent, ConnectorError> {
let refund_amount = utils::convert_amount(
self.amount_converter,
req.request.minor_refund_amount,
@@ -464,7 +469,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Trustly
&self,
req: &RefundsRouterData<Execute>,
connectors: &Connectors,
- ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ ) -> CustomResult<Option<Request>, ConnectorError> {
let request = RequestBuilder::new()
.method(Method::Post)
.url(&types::RefundExecuteType::get_url(self, req, connectors)?)
@@ -484,11 +489,11 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Trustly
data: &RefundsRouterData<Execute>,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
- ) -> CustomResult<RefundsRouterData<Execute>, errors::ConnectorError> {
+ ) -> CustomResult<RefundsRouterData<Execute>, ConnectorError> {
let response: trustly::RefundResponse = res
.response
.parse_struct("trustly RefundResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -502,7 +507,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Trustly
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
- ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
self.build_error_response(res, event_builder)
}
}
@@ -512,7 +517,7 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Trustly {
&self,
req: &RefundSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
self.build_headers(req, connectors)
}
@@ -524,15 +529,15 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Trustly {
&self,
_req: &RefundSyncRouterData,
_connectors: &Connectors,
- ) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ ) -> CustomResult<String, ConnectorError> {
+ Err(ConnectorError::NotImplemented("get_url method".to_string()).into())
}
fn build_request(
&self,
req: &RefundSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ ) -> CustomResult<Option<Request>, ConnectorError> {
Ok(Some(
RequestBuilder::new()
.method(Method::Get)
@@ -551,11 +556,11 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Trustly {
data: &RefundSyncRouterData,
event_builder: Option<&mut ConnectorEvent>,
res: Response,
- ) -> CustomResult<RefundSyncRouterData, errors::ConnectorError> {
+ ) -> CustomResult<RefundSyncRouterData, ConnectorError> {
let response: trustly::RefundResponse = res
.response
.parse_struct("trustly RefundSyncResponse")
- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
RouterData::try_from(ResponseRouterData {
@@ -569,7 +574,252 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Trustly {
&self,
res: Response,
event_builder: Option<&mut ConnectorEvent>,
- ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+impl api::Payouts for Trustly {}
+#[cfg(feature = "payouts")]
+impl api::PayoutRecipient for Trustly {}
+#[cfg(feature = "payouts")]
+impl api::PayoutFulfill for Trustly {}
+#[cfg(feature = "payouts")]
+impl api::PayoutSync for Trustly {}
+
+#[cfg(feature = "payouts")]
+impl ConnectorIntegration<PoRecipient, PayoutsData, PayoutsResponseData> for Trustly {
+ fn get_url(
+ &self,
+ _req: &PayoutsRouterData<PoRecipient>,
+ connectors: &Connectors,
+ ) -> CustomResult<String, ConnectorError> {
+ Ok(connectors.trustly.base_url.clone())
+ }
+
+ fn get_headers(
+ &self,
+ req: &PayoutsRouterData<PoRecipient>,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PayoutsRouterData<PoRecipient>,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, ConnectorError> {
+ let amount = utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount,
+ req.request.source_currency,
+ )?;
+
+ let connector_router_data = trustly::TrustlyRouterData::from((amount, req));
+ let connector_req = trustly::RegisterAccountRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &PayoutsRouterData<PoRecipient>,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, ConnectorError> {
+ let request = RequestBuilder::new()
+ .method(Method::Post)
+ .url(&types::PayoutRecipientType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::PayoutRecipientType::get_headers(
+ self, req, connectors,
+ )?)
+ .set_body(types::PayoutRecipientType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build();
+
+ Ok(Some(request))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PayoutsRouterData<PoRecipient>,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PayoutsRouterData<PoRecipient>, ConnectorError> {
+ let response: trustly::RegisterAccountResponse = res
+ .response
+ .parse_struct("RegisterAccountResponse")
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
+
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+#[cfg(feature = "payouts")]
+impl ConnectorIntegration<PoFulfill, PayoutsData, PayoutsResponseData> for Trustly {
+ fn get_url(
+ &self,
+ _req: &PayoutsRouterData<PoFulfill>,
+ connectors: &Connectors,
+ ) -> CustomResult<String, ConnectorError> {
+ Ok(connectors.trustly.base_url.clone())
+ }
+
+ fn get_headers(
+ &self,
+ req: &PayoutsRouterData<PoFulfill>,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PayoutsRouterData<PoFulfill>,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, ConnectorError> {
+ let amount = utils::convert_amount(
+ self.amount_converter,
+ req.request.minor_amount,
+ req.request.source_currency,
+ )?;
+
+ let connector_router_data = trustly::TrustlyRouterData::from((amount, req));
+ let connector_req = trustly::AccountPayoutRequest::try_from(&connector_router_data)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &PayoutsRouterData<PoFulfill>,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, ConnectorError> {
+ let request = RequestBuilder::new()
+ .method(Method::Post)
+ .url(&PayoutFulfillType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(PayoutFulfillType::get_headers(self, req, connectors)?)
+ .set_body(PayoutFulfillType::get_request_body(self, req, connectors)?)
+ .build();
+
+ Ok(Some(request))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PayoutsRouterData<PoFulfill>,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PayoutsRouterData<PoFulfill>, ConnectorError> {
+ let response: trustly::AccountPayoutResponse = res
+ .response
+ .parse_struct("AccountPayoutResponse")
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
+
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
+
+#[cfg(feature = "payouts")]
+impl ConnectorIntegration<PoSync, PayoutsData, PayoutsResponseData> for Trustly {
+ fn get_url(
+ &self,
+ _req: &PayoutsRouterData<PoSync>,
+ connectors: &Connectors,
+ ) -> CustomResult<String, ConnectorError> {
+ Ok(connectors.trustly.base_url.clone())
+ }
+
+ fn get_headers(
+ &self,
+ req: &PayoutsRouterData<PoSync>,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn build_request(
+ &self,
+ req: &PayoutsRouterData<PoSync>,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, ConnectorError> {
+ let request = RequestBuilder::new()
+ .method(Method::Post)
+ .url(&PayoutSyncType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(PayoutSyncType::get_headers(self, req, connectors)?)
+ .set_body(PayoutSyncType::get_request_body(self, req, connectors)?)
+ .build();
+
+ Ok(Some(request))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PayoutsRouterData<PoSync>,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, ConnectorError> {
+ let connector_req = trustly::TrustlyPayoutSyncRequest::try_from(req)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PayoutsRouterData<PoSync>,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PayoutsRouterData<PoSync>, ConnectorError> {
+ let response: trustly::TrustlyPayoutSyncResponse = res
+ .response
+ .parse_struct("TrustlyPayoutSyncResponse")
+ .change_context(ConnectorError::ResponseDeserializationFailed)?;
+
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, ConnectorError> {
self.build_error_response(res, event_builder)
}
}
@@ -579,23 +829,23 @@ impl webhooks::IncomingWebhook for Trustly {
fn get_webhook_object_reference_id(
&self,
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
- ) -> CustomResult<api_models::webhooks::ObjectReferenceId, errors::ConnectorError> {
- Err(report!(errors::ConnectorError::WebhooksNotImplemented))
+ ) -> CustomResult<api_models::webhooks::ObjectReferenceId, ConnectorError> {
+ Err(report!(ConnectorError::WebhooksNotImplemented))
}
fn get_webhook_event_type(
&self,
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
_context: Option<&webhooks::WebhookContext>,
- ) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, errors::ConnectorError> {
- Err(report!(errors::ConnectorError::WebhooksNotImplemented))
+ ) -> CustomResult<api_models::webhooks::IncomingWebhookEvent, ConnectorError> {
+ Err(report!(ConnectorError::WebhooksNotImplemented))
}
fn get_webhook_resource_object(
&self,
_request: &webhooks::IncomingWebhookRequestDetails<'_>,
- ) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, errors::ConnectorError> {
- Err(report!(errors::ConnectorError::WebhooksNotImplemented))
+ ) -> CustomResult<Box<dyn masking::ErasedMaskSerialize>, ConnectorError> {
+ Err(report!(ConnectorError::WebhooksNotImplemented))
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/trustly/transformers.rs b/crates/hyperswitch_connectors/src/connectors/trustly/transformers.rs
index 7ece67f8c9..e1299e57a7 100644
--- a/crates/hyperswitch_connectors/src/connectors/trustly/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/trustly/transformers.rs
@@ -1,28 +1,46 @@
+use std::collections::BTreeMap;
+
+#[cfg(feature = "payouts")]
+use api_models::payouts::{Bank, PayoutMethodData};
+use base64::{engine::general_purpose, Engine as _};
use common_enums::enums;
-use common_utils::types::StringMinorUnit;
+#[cfg(feature = "payouts")]
+use common_enums::{CountryAlpha2, PayoutStatus};
+use common_utils::{id_type::CustomerId, pii, types::StringMajorUnit};
+use error_stack::ResultExt;
+#[cfg(feature = "payouts")]
+use hyperswitch_domain_models::types::{PayoutsResponseData, PayoutsRouterData};
use hyperswitch_domain_models::{
payment_method_data::PaymentMethodData,
- router_data::{ConnectorAuthType, RouterData},
+ router_data::{ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::refunds::{Execute, RSync},
router_request_types::ResponseId,
router_response_types::{PaymentsResponseData, RefundsResponseData},
types::{PaymentsAuthorizeRouterData, RefundsRouterData},
};
-use hyperswitch_interfaces::errors;
-use masking::Secret;
+use hyperswitch_interfaces::errors::ConnectorError;
+use masking::{ExposeInterface, Secret};
+use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa, sign::Signer};
use serde::{Deserialize, Serialize};
use crate::types::{RefundsResponseRouterData, ResponseRouterData};
+#[cfg(feature = "payouts")]
+use crate::{
+ types::PayoutsResponseRouterData,
+ utils::{
+ self, get_unimplemented_payment_method_error_message, AddressData,
+ PayoutFulfillRequestData, PayoutsData, RouterData as _,
+ },
+};
//TODO: Fill the struct with respective fields
pub struct TrustlyRouterData<T> {
- pub amount: StringMinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
+ pub amount: StringMajorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
pub router_data: T,
}
-impl<T> From<(StringMinorUnit, T)> for TrustlyRouterData<T> {
- fn from((amount, item): (StringMinorUnit, T)) -> Self {
- //Todo : use utils to convert the amount to the type of amount that a connector accepts
+impl<T> From<(StringMajorUnit, T)> for TrustlyRouterData<T> {
+ fn from((amount, item): (StringMajorUnit, T)) -> Self {
Self {
amount,
router_data: item,
@@ -33,7 +51,7 @@ impl<T> From<(StringMinorUnit, T)> for TrustlyRouterData<T> {
//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Serialize, PartialEq)]
pub struct TrustlyPaymentsRequest {
- amount: StringMinorUnit,
+ amount: StringMajorUnit,
card: TrustlyCard,
}
@@ -47,37 +65,57 @@ pub struct TrustlyCard {
}
impl TryFrom<&TrustlyRouterData<&PaymentsAuthorizeRouterData>> for TrustlyPaymentsRequest {
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = error_stack::Report<ConnectorError>;
fn try_from(
item: &TrustlyRouterData<&PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
match item.router_data.request.payment_method_data.clone() {
- PaymentMethodData::Card(_) => Err(errors::ConnectorError::NotImplemented(
+ PaymentMethodData::Card(_) => Err(ConnectorError::NotImplemented(
"Card payment method not implemented".to_string(),
)
.into()),
- _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()),
+ _ => Err(ConnectorError::NotImplemented("Payment method".to_string()).into()),
}
}
}
//TODO: Fill the struct with respective fields
// Auth Struct
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
pub struct TrustlyAuthType {
- pub(super) api_key: Secret<String>,
+ pub(super) username: Secret<String>,
+ pub(super) password: Secret<String>,
}
impl TryFrom<&ConnectorAuthType> for TrustlyAuthType {
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = error_stack::Report<ConnectorError>;
fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
match auth_type {
- ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
- api_key: api_key.to_owned(),
+ ConnectorAuthType::BodyKey { api_key, key1 } => Ok(Self {
+ username: api_key.to_owned(),
+ password: key1.to_owned(),
}),
- _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
+ _ => Err(ConnectorError::FailedToObtainAuthType.into()),
}
}
}
+
+#[cfg(feature = "payouts")]
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyMetadata {
+ private_key: Secret<String>,
+}
+
+#[cfg(feature = "payouts")]
+impl TryFrom<&Option<pii::SecretSerdeValue>> for TrustlyMetadata {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(meta_data: &Option<pii::SecretSerdeValue>) -> Result<Self, Self::Error> {
+ let metadata: Self = utils::to_connector_meta_from_secret::<Self>(meta_data.clone())
+ .change_context(ConnectorError::InvalidConnectorConfig { config: "metadata" })?;
+ Ok(metadata)
+ }
+}
+
// PaymentsResponse
//TODO: Append the remaining status flags
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
@@ -109,7 +147,7 @@ pub struct TrustlyPaymentsResponse {
impl<F, T> TryFrom<ResponseRouterData<F, TrustlyPaymentsResponse, T, PaymentsResponseData>>
for RouterData<F, T, PaymentsResponseData>
{
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = error_stack::Report<ConnectorError>;
fn try_from(
item: ResponseRouterData<F, TrustlyPaymentsResponse, T, PaymentsResponseData>,
) -> Result<Self, Self::Error> {
@@ -136,11 +174,11 @@ impl<F, T> TryFrom<ResponseRouterData<F, TrustlyPaymentsResponse, T, PaymentsRes
// Type definition for RefundRequest
#[derive(Default, Debug, Serialize)]
pub struct TrustlyRefundRequest {
- pub amount: StringMinorUnit,
+ pub amount: StringMajorUnit,
}
impl<F> TryFrom<&TrustlyRouterData<&RefundsRouterData<F>>> for TrustlyRefundRequest {
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = error_stack::Report<ConnectorError>;
fn try_from(item: &TrustlyRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
Ok(Self {
amount: item.amount.to_owned(),
@@ -178,7 +216,7 @@ pub struct RefundResponse {
}
impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = error_stack::Report<ConnectorError>;
fn try_from(
item: RefundsResponseRouterData<Execute, RefundResponse>,
) -> Result<Self, Self::Error> {
@@ -193,7 +231,7 @@ impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRout
}
impl TryFrom<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouterData<RSync> {
- type Error = error_stack::Report<errors::ConnectorError>;
+ type Error = error_stack::Report<ConnectorError>;
fn try_from(
item: RefundsResponseRouterData<RSync, RefundResponse>,
) -> Result<Self, Self::Error> {
@@ -207,14 +245,729 @@ impl TryFrom<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouter
}
}
-//TODO: Fill the struct with respective fields
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
pub struct TrustlyErrorResponse {
- pub status_code: u16,
- pub code: String,
+ pub version: String,
+ pub error: TrustlyErrorResponseError,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyErrorResponseError {
+ pub name: String,
+ pub code: i64,
pub message: String,
- pub reason: Option<String>,
- pub network_advice_code: Option<String>,
- pub network_decline_code: Option<String>,
- pub network_error_message: Option<String>,
+ pub error: TrustlyErrorResponseErrorDetails,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyErrorResponseErrorDetails {
+ pub uuid: String,
+}
+
+fn process_error_response(error_response: TrustlyErrorResponse, http_code: u16) -> ErrorResponse {
+ ErrorResponse {
+ code: error_response.error.code.to_string(),
+ message: error_response.error.message.clone(),
+ reason: Some(error_response.error.message.clone()),
+ status_code: http_code,
+ attempt_status: None,
+ connector_transaction_id: None,
+ connector_response_reference_id: Some(error_response.error.error.uuid),
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_metadata: None,
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+enum TrustlyMethod {
+ RegisterAccount,
+ AccountPayout,
+ GetWithdrawals,
+}
+
+impl TrustlyMethod {
+ fn as_str(&self) -> &'static str {
+ match self {
+ Self::RegisterAccount => "RegisterAccount",
+ Self::AccountPayout => "AccountPayout",
+ Self::GetWithdrawals => "GetWithdrawals",
+ }
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct RegisterAccountRequest {
+ method: TrustlyMethod,
+ params: RegisterAccountParams,
+ version: String,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct RegisterAccountParams {
+ data: RegisterAccountData,
+ signature: Secret<String>,
+ #[serde(rename = "UUID")]
+ uuid: String,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+#[serde_with::skip_serializing_none]
+#[serde(rename_all = "PascalCase")]
+pub struct RegisterAccountData {
+ account_number: Secret<String>,
+ bank_number: Secret<String>,
+ clearing_house: String,
+ end_user_i_d: CustomerId,
+ firstname: Secret<String>,
+ lastname: Secret<String>,
+ username: Secret<String>,
+ password: Secret<String>,
+ attributes: Option<RegisterAccountAttributes>,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+#[serde_with::skip_serializing_none]
+pub struct RegisterAccountAttributes {
+ address_country: Option<CountryAlpha2>,
+ address_line1: Option<Secret<String>>,
+ address_line2: Option<Secret<String>>,
+ address_city: Option<String>,
+ address_postal_code: Option<Secret<String>>,
+ mobile_phone: Option<Secret<String>>,
+ email: Option<pii::Email>,
+}
+
+#[cfg(feature = "payouts")]
+fn trustly_serialize<T: Serialize>(data: &T) -> String {
+ let value = serde_json::to_value(data).unwrap_or_default();
+ serialize_value(&value)
+}
+
+enum Algorithm {
+ SHA256,
+}
+
+impl Algorithm {
+ fn message_digest(&self) -> MessageDigest {
+ match self {
+ Self::SHA256 => MessageDigest::sha256(),
+ }
+ }
+
+ fn prefix(&self) -> &'static str {
+ // Trustly expects the signature header like "alg=RS256;"
+ "alg=RS256;"
+ }
+}
+
+fn serialize_value(value: &serde_json::Value) -> String {
+ match value {
+ serde_json::Value::Object(map) => {
+ let sorted: BTreeMap<_, _> = map.iter().collect();
+ sorted
+ .iter()
+ .filter(|(_, v)| !v.is_null())
+ .map(|(k, v)| format!("{}{}", k, serialize_data(v)))
+ .collect()
+ }
+ serde_json::Value::Array(arr) => arr.iter().map(serialize_data).collect(),
+ serde_json::Value::String(s) => s.clone(),
+ serde_json::Value::Number(n) => n.to_string(),
+ serde_json::Value::Bool(b) => b.to_string(),
+ serde_json::Value::Null => String::new(),
+ }
+}
+
+fn generate_trustly_signature<T: Serialize>(
+ method: &TrustlyMethod,
+ uuid: &str,
+ data: &T,
+ private_key: &str,
+) -> Result<String, ConnectorError> {
+ let algorithm = Algorithm::SHA256;
+ let pem = utils::base64_decode(private_key.to_string())
+ .map_err(|_| ConnectorError::RequestEncodingFailed)?;
+ let rsa = Rsa::private_key_from_pem(&pem).map_err(|_| ConnectorError::RequestEncodingFailed)?;
+ let private_key = PKey::from_rsa(rsa).map_err(|_| ConnectorError::RequestEncodingFailed)?;
+
+ let plaintext = format!("{}{}{}", method.as_str(), uuid, trustly_serialize(data));
+
+ let mut signer = Signer::new(algorithm.message_digest(), &private_key)
+ .map_err(|_| ConnectorError::RequestEncodingFailed)?;
+ signer
+ .update(plaintext.as_bytes())
+ .map_err(|_| ConnectorError::RequestEncodingFailed)?;
+ let signature = signer
+ .sign_to_vec()
+ .map_err(|_| ConnectorError::RequestEncodingFailed)?;
+
+ Ok(format!(
+ "{}{}",
+ algorithm.prefix(),
+ general_purpose::STANDARD.encode(&signature)
+ ))
+}
+
+fn serialize_data(value: &serde_json::Value) -> String {
+ match value {
+ serde_json::Value::Object(map) => {
+ // BTreeMap keeps keys sorted (matches PHP's ksort)
+ let sorted: BTreeMap<_, _> = map.iter().collect();
+ sorted
+ .iter()
+ .map(|(k, v)| format!("{}{}", k, serialize_data(v)))
+ .collect()
+ }
+ serde_json::Value::Array(arr) => arr.iter().map(serialize_data).collect(),
+ serde_json::Value::String(s) => s.clone(),
+ serde_json::Value::Number(n) => n.to_string(),
+ serde_json::Value::Bool(b) => b.to_string(),
+ serde_json::Value::Null => String::new(),
+ }
+}
+
+#[cfg(feature = "payouts")]
+fn get_customer_details(
+ customer_details: Option<&hyperswitch_domain_models::router_request_types::CustomerDetails>,
+ billing_details: Option<&hyperswitch_domain_models::address::Address>,
+) -> Result<(String, String), ConnectorError> {
+ if let Some(customer) = customer_details {
+ if let Some(name) = &customer.name {
+ let n = name.clone().expose();
+ let parts: Vec<&str> = n.splitn(2, ' ').collect();
+ if let [first, second] = parts.as_slice() {
+ return Ok((first.to_string(), second.to_string()));
+ }
+ }
+ }
+
+ if let Some(billing) = billing_details {
+ if let Some(address) = &billing.address {
+ let first_name = address
+ .first_name
+ .clone()
+ .ok_or(ConnectorError::MissingRequiredField {
+ field_name: "first_name",
+ })?
+ .expose();
+ let last_name = address
+ .last_name
+ .clone()
+ .ok_or(ConnectorError::MissingRequiredField {
+ field_name: "last_name",
+ })?
+ .expose();
+
+ return Ok((first_name, last_name));
+ }
+ }
+
+ Err(ConnectorError::MissingRequiredField {
+ field_name: "customer's first name / last name",
+ })
+}
+
+#[cfg(feature = "payouts")]
+impl<F> TryFrom<&TrustlyRouterData<&PayoutsRouterData<F>>> for RegisterAccountRequest {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(item: &TrustlyRouterData<&PayoutsRouterData<F>>) -> Result<Self, Self::Error> {
+ let payout_method_data = item.router_data.get_payout_method_data()?;
+ match payout_method_data {
+ PayoutMethodData::Bank(Bank::Trustly(trustly_data)) => {
+ let (account_number, bank_number) = if let Some(iban) = trustly_data.iban {
+ (iban, Secret::new(String::new()))
+ } else {
+ (
+ trustly_data.account_number.ok_or(
+ ConnectorError::MissingRequiredField {
+ field_name: "account_number",
+ },
+ )?,
+ trustly_data
+ .bank_number
+ .ok_or(ConnectorError::MissingRequiredField {
+ field_name: "bank_number",
+ })?,
+ )
+ };
+
+ let customer_details = item.router_data.request.customer_details.clone();
+ let billing_details = item.router_data.get_optional_billing();
+ let (first_name, last_name) =
+ get_customer_details(customer_details.as_ref(), billing_details)?;
+
+ let attributes = if billing_details.is_some()
+ || customer_details.and_then(|details| details.email).is_some()
+ {
+ Some(RegisterAccountAttributes {
+ address_city: item.router_data.get_optional_billing_city(),
+ address_country: item.router_data.get_optional_billing_country(),
+ address_line1: item.router_data.get_optional_billing_line1(),
+ address_line2: item.router_data.get_optional_billing_line2(),
+ address_postal_code: item.router_data.get_optional_billing_zip(),
+ email: item.router_data.get_optional_billing_email(),
+ mobile_phone: billing_details.and_then(|details| hyperswitch_domain_models::address::Address::get_phone_with_country_code(details).ok()),
+ })
+ } else {
+ None
+ };
+
+ let uuid = uuid::Uuid::new_v4().to_string();
+ let private_key =
+ TrustlyMetadata::try_from(&item.router_data.connector_meta_data)?.private_key;
+ let auth_details =
+ TrustlyAuthType::try_from(&item.router_data.connector_auth_type)?;
+ let register_account_data = RegisterAccountData {
+ account_number,
+ bank_number,
+ clearing_house: common_enums::Country::from_alpha2(trustly_data.country_code)
+ .to_string()
+ .to_uppercase(),
+ end_user_i_d: item.router_data.get_customer_id()?,
+ firstname: Secret::new(first_name),
+ lastname: Secret::new(last_name),
+ username: auth_details.username,
+ password: auth_details.password,
+ attributes,
+ };
+
+ let signature = generate_trustly_signature(
+ &TrustlyMethod::RegisterAccount,
+ uuid.as_str(),
+ &register_account_data,
+ &private_key.expose(),
+ )?;
+
+ Ok(Self {
+ method: TrustlyMethod::RegisterAccount,
+ params: RegisterAccountParams {
+ data: register_account_data,
+ signature: Secret::new(signature),
+ uuid,
+ },
+ version: "1.1".to_string(),
+ })
+ }
+ PayoutMethodData::Card(_)
+ | PayoutMethodData::Wallet(_)
+ | PayoutMethodData::Bank(_)
+ | PayoutMethodData::BankRedirect(_)
+ | PayoutMethodData::Passthrough(_) => Err(ConnectorError::NotImplemented(
+ get_unimplemented_payment_method_error_message("Trustly"),
+ ))?,
+ }
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(untagged)]
+pub enum RegisterAccountResponse {
+ Success(RegisterAccountResponseSuccess),
+ Error(TrustlyErrorResponse),
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct RegisterAccountResponseSuccess {
+ pub result: RegisterAccountResponseResult,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct RegisterAccountResponseResult {
+ data: RegisterAccountResponseResultData,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+pub struct RegisterAccountResponseResultData {
+ accountid: Secret<String>,
+ clearinghouse: String,
+ bank: String,
+}
+
+#[cfg(feature = "payouts")]
+impl<F> TryFrom<PayoutsResponseRouterData<F, RegisterAccountResponse>> for PayoutsRouterData<F> {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(
+ item: PayoutsResponseRouterData<F, RegisterAccountResponse>,
+ ) -> Result<Self, Self::Error> {
+ match item.response {
+ RegisterAccountResponse::Success(response) => {
+ let account_id = response.result.data.accountid;
+ let payout_connector_metadata = Some(Secret::new(serde_json::json!({
+ "account_id": account_id,
+ })));
+
+ Ok(Self {
+ response: Ok(PayoutsResponseData {
+ status: Some(PayoutStatus::RequiresCreation),
+ connector_payout_id: None,
+ payout_eligible: None,
+ should_add_next_step_to_process_tracker: false,
+ error_code: None,
+ error_message: None,
+ payout_connector_metadata,
+ }),
+ ..item.data
+ })
+ }
+ RegisterAccountResponse::Error(error_response) => {
+ let response = Err(process_error_response(error_response, item.http_code));
+ Ok(Self {
+ response,
+ ..item.data
+ })
+ }
+ }
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct AccountPayoutRequest {
+ method: TrustlyMethod,
+ params: AccountPayoutParams,
+ version: String,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct AccountPayoutParams {
+ signature: Secret<String>,
+ #[serde(rename = "UUID")]
+ uuid: String,
+ data: AccountPayoutData,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct AccountPayoutData {
+ account_i_d: Secret<String>,
+ amount: StringMajorUnit,
+ attributes: Option<AccountPayoutAttributes>,
+ currency: common_enums::Currency,
+ end_user_i_d: CustomerId,
+ message_i_d: String,
+ notification_u_r_l: String,
+ password: Secret<String>,
+ username: Secret<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct AccountPayoutAttributes {
+ shopper_statement: String,
+}
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyAccountId {
+ account_id: Secret<String>,
+}
+
+#[cfg(feature = "payouts")]
+impl<F> TryFrom<&TrustlyRouterData<&PayoutsRouterData<F>>> for AccountPayoutRequest {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(item: &TrustlyRouterData<&PayoutsRouterData<F>>) -> Result<Self, Self::Error> {
+ let payout_method_data = item.router_data.get_payout_method_data()?;
+ match payout_method_data {
+ PayoutMethodData::Bank(Bank::Trustly(_trustly_data)) => {
+ let notification_url = item.router_data.request.get_webhook_url()?;
+
+ let metadata = item
+ .router_data
+ .request
+ .payout_connector_metadata
+ .clone()
+ .map(|secret| secret.expose().clone());
+ let account_id: TrustlyAccountId =
+ utils::to_payout_connector_meta(metadata.clone())?;
+
+ let auth_details =
+ TrustlyAuthType::try_from(&item.router_data.connector_auth_type)?;
+
+ let private_key =
+ TrustlyMetadata::try_from(&item.router_data.connector_meta_data)?.private_key;
+ let uuid = uuid::Uuid::new_v4().to_string();
+ let account_payout_data = AccountPayoutData {
+ account_i_d: account_id.account_id,
+ amount: item.amount.clone(),
+ attributes: Some(AccountPayoutAttributes {
+ shopper_statement: item.router_data.description.clone().ok_or(
+ ConnectorError::MissingRequiredField {
+ field_name: "description",
+ },
+ )?,
+ }),
+ currency: item.router_data.request.destination_currency,
+ end_user_i_d: item.router_data.get_customer_id()?,
+ message_i_d: item
+ .router_data
+ .request
+ .payout_id
+ .get_string_repr()
+ .to_string(),
+ notification_u_r_l: notification_url,
+ password: auth_details.password.clone(),
+ username: auth_details.username.clone(),
+ };
+
+ let signature = generate_trustly_signature(
+ &TrustlyMethod::AccountPayout,
+ uuid.as_str(),
+ &account_payout_data,
+ &private_key.expose(),
+ )?;
+
+ Ok(Self {
+ method: TrustlyMethod::AccountPayout,
+ params: AccountPayoutParams {
+ data: account_payout_data,
+ signature: Secret::new(signature),
+ uuid,
+ },
+ version: "1.1".to_string(),
+ })
+ }
+ PayoutMethodData::Card(_)
+ | PayoutMethodData::Wallet(_)
+ | PayoutMethodData::Bank(_)
+ | PayoutMethodData::BankRedirect(_)
+ | PayoutMethodData::Passthrough(_) => Err(ConnectorError::NotImplemented(
+ get_unimplemented_payment_method_error_message("Trustly"),
+ ))?,
+ }
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+enum PayoutResult {
+ #[serde(rename = "0")]
+ Failed,
+ #[serde(rename = "1")]
+ Pending,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(untagged)]
+pub enum AccountPayoutResponse {
+ Success(AccountPayoutResponseSuccess),
+ Error(TrustlyErrorResponse),
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct AccountPayoutResponseSuccess {
+ version: String,
+ result: AccountPayoutResponseResult,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct AccountPayoutResponseResult {
+ data: AccountPayoutResponseData,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct AccountPayoutResponseData {
+ orderid: String,
+ result: PayoutResult,
+}
+
+#[cfg(feature = "payouts")]
+impl<F> TryFrom<PayoutsResponseRouterData<F, AccountPayoutResponse>> for PayoutsRouterData<F> {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(
+ item: PayoutsResponseRouterData<F, AccountPayoutResponse>,
+ ) -> Result<Self, Self::Error> {
+ match item.response {
+ AccountPayoutResponse::Success(success_response) => {
+ let response = success_response.result.data;
+ let payout_status = match response.result {
+ PayoutResult::Failed => PayoutStatus::Failed,
+ PayoutResult::Pending => PayoutStatus::Initiated,
+ };
+
+ Ok(Self {
+ response: Ok(PayoutsResponseData {
+ status: Some(payout_status),
+ connector_payout_id: Some(response.orderid),
+ payout_eligible: None,
+ should_add_next_step_to_process_tracker: false,
+ error_code: None,
+ error_message: None,
+ payout_connector_metadata: None,
+ }),
+ ..item.data
+ })
+ }
+ AccountPayoutResponse::Error(error_response) => {
+ let response = Err(process_error_response(error_response, item.http_code));
+ Ok(Self {
+ response,
+ ..item.data
+ })
+ }
+ }
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyPayoutSyncRequest {
+ method: TrustlyMethod,
+ params: PayoutSyncRequestParams,
+ version: String,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct PayoutSyncRequestParams {
+ #[serde(rename = "UUID")]
+ uuid: String,
+ data: PayoutSyncRequestData,
+ signature: Secret<String>,
+}
+
+#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "PascalCase")]
+pub struct PayoutSyncRequestData {
+ order_id: Secret<String>,
+ password: Secret<String>,
+ username: Secret<String>,
+}
+
+#[cfg(feature = "payouts")]
+impl<F> TryFrom<&PayoutsRouterData<F>> for TrustlyPayoutSyncRequest {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(item: &PayoutsRouterData<F>) -> Result<Self, Self::Error> {
+ let auth_details = TrustlyAuthType::try_from(&item.connector_auth_type)?;
+ let data = PayoutSyncRequestData {
+ order_id: Secret::new(item.request.get_connector_payout_id()?),
+ password: auth_details.password.clone(),
+ username: auth_details.username.clone(),
+ };
+ let private_key = TrustlyMetadata::try_from(&item.connector_meta_data)?.private_key;
+
+ let uuid = uuid::Uuid::new_v4().to_string();
+ let signature = generate_trustly_signature(
+ &TrustlyMethod::GetWithdrawals,
+ uuid.as_str(),
+ &data,
+ &private_key.expose(),
+ )?;
+
+ Ok(Self {
+ method: TrustlyMethod::GetWithdrawals,
+ params: PayoutSyncRequestParams {
+ uuid,
+ data,
+ signature: Secret::new(signature),
+ },
+ version: "1.1".to_string(),
+ })
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+#[serde(untagged)]
+pub enum TrustlyPayoutSyncResponse {
+ Success(TrustlyPayoutSyncResponseSuccess),
+ Error(TrustlyErrorResponse),
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyPayoutSyncResponseSuccess {
+ result: TrustlyPayoutSyncResponseResult,
+ version: String,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyPayoutSyncResponseResult {
+ uuid: String,
+ method: String,
+ data: Vec<TrustlyPayoutSyncResponseData>,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq)]
+pub struct TrustlyPayoutSyncResponseData {
+ reference: String,
+ orderid: String,
+ transferstate: TrustlyPayoutStatus,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
+enum TrustlyPayoutStatus {
+ Confirmed,
+ Executing,
+ Executed,
+ Pending,
+ Queued,
+ Preparing,
+ Prepared,
+ Bounced,
+ Error,
+ Failed,
+ Returned,
+}
+
+impl From<TrustlyPayoutStatus> for PayoutStatus {
+ fn from(item: TrustlyPayoutStatus) -> Self {
+ match item {
+ TrustlyPayoutStatus::Confirmed => Self::Success,
+ TrustlyPayoutStatus::Failed
+ | TrustlyPayoutStatus::Error
+ | TrustlyPayoutStatus::Bounced
+ | TrustlyPayoutStatus::Returned => Self::Failed,
+ TrustlyPayoutStatus::Executing | TrustlyPayoutStatus::Executed => Self::Pending,
+ TrustlyPayoutStatus::Pending
+ | TrustlyPayoutStatus::Queued
+ | TrustlyPayoutStatus::Preparing
+ | TrustlyPayoutStatus::Prepared => Self::Initiated,
+ }
+ }
+}
+
+#[cfg(feature = "payouts")]
+impl<F> TryFrom<PayoutsResponseRouterData<F, TrustlyPayoutSyncResponse>> for PayoutsRouterData<F> {
+ type Error = error_stack::Report<ConnectorError>;
+ fn try_from(
+ item: PayoutsResponseRouterData<F, TrustlyPayoutSyncResponse>,
+ ) -> Result<Self, Self::Error> {
+ match item.response {
+ TrustlyPayoutSyncResponse::Success(response) => {
+ if let Some(first) = response.result.data.first() {
+ Ok(Self {
+ response: Ok(PayoutsResponseData {
+ status: Some(PayoutStatus::from(first.transferstate.clone())),
+ connector_payout_id: Some(first.orderid.clone()),
+ payout_eligible: None,
+ should_add_next_step_to_process_tracker: false,
+ error_code: None,
+ error_message: None,
+ payout_connector_metadata: None,
+ }),
+ ..item.data
+ })
+ } else {
+ Ok(Self {
+ response: Ok(PayoutsResponseData {
+ status: None,
+ connector_payout_id: None,
+ payout_eligible: None,
+ should_add_next_step_to_process_tracker: false,
+ error_code: None,
+ error_message: None,
+ payout_connector_metadata: None,
+ }),
+ ..item.data
+ })
+ }
+ }
+ TrustlyPayoutSyncResponse::Error(error_response) => {
+ let response = Err(process_error_response(error_response, item.http_code));
+ Ok(Self {
+ response,
+ ..item.data
+ })
+ }
+ }
+ }
}
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index 97c5309f49..0aec118d1f 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -4402,7 +4402,6 @@ macro_rules! default_imp_for_payouts {
}
default_imp_for_payouts!(
- connectors::Trustly,
connectors::Worldpaymodular,
connectors::Paysafe,
connectors::Affirm,
@@ -4514,7 +4513,6 @@ default_imp_for_payouts!(
connectors::Threedsecureio,
connectors::Tokenex,
connectors::Tokenio,
- // connectors::Truelayer,
connectors::Trustpay,
connectors::Trustpayments,
connectors::Tsys,
@@ -4704,7 +4702,6 @@ macro_rules! default_imp_for_payouts_retrieve {
#[cfg(feature = "payouts")]
default_imp_for_payouts_retrieve!(
- connectors::Trustly,
connectors::Paysafe,
connectors::Vgs,
connectors::Aci,
@@ -5020,7 +5017,6 @@ macro_rules! default_imp_for_payouts_fulfill {
#[cfg(feature = "payouts")]
default_imp_for_payouts_fulfill!(
- connectors::Trustly,
connectors::Worldpaymodular,
connectors::Paysafe,
connectors::Affirm,
@@ -5605,7 +5601,6 @@ default_imp_for_payouts_recipient!(
connectors::Tokenex,
connectors::Tokenio,
connectors::Truelayer,
- connectors::Trustly,
connectors::Trustpay,
connectors::Trustpayments,
connectors::Tsys,
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index a2c09ebb14..14f8927a1b 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -263,6 +263,7 @@ Never share your secret api keys. Keep them guarded and secure.
common_utils::payout_method_utils::BacsBankTransferAdditionalData,
common_utils::payout_method_utils::SepaBankTransferAdditionalData,
common_utils::payout_method_utils::PixBankTransferAdditionalData,
+ common_utils::payout_method_utils::TrustlyBankTransferAdditionalData,
common_utils::payout_method_utils::PaypalAdditionalData,
common_utils::payout_method_utils::InteracAdditionalData,
common_utils::payout_method_utils::OpenBankingUkAdditionalData,
@@ -763,6 +764,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payouts::BacsBankTransfer,
api_models::payouts::SepaBankTransfer,
api_models::payouts::PixBankTransfer,
+ api_models::payouts::TrustlyBankTransfer,
api_models::payouts::PayoutsCreateRequest,
api_models::payouts::PayoutUpdateRequest,
api_models::payouts::PayoutConfirmRequest,
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 9e71633d7d..3d309157aa 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -205,6 +205,7 @@ Never share your secret api keys. Keep them guarded and secure.
common_utils::payout_method_utils::BacsBankTransferAdditionalData,
common_utils::payout_method_utils::SepaBankTransferAdditionalData,
common_utils::payout_method_utils::PixBankTransferAdditionalData,
+ common_utils::payout_method_utils::TrustlyBankTransferAdditionalData,
common_utils::payout_method_utils::PaypalAdditionalData,
common_utils::payout_method_utils::InteracAdditionalData,
common_utils::payout_method_utils::OpenBankingUkAdditionalData,
@@ -716,6 +717,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payouts::BacsBankTransfer,
api_models::payouts::SepaBankTransfer,
api_models::payouts::PixBankTransfer,
+ api_models::payouts::TrustlyBankTransfer,
api_models::payouts::PayoutRequest,
api_models::payouts::PayoutAttemptResponse,
api_models::payouts::PayoutActionRequest,
diff --git a/crates/router/src/core/connector_validation.rs b/crates/router/src/core/connector_validation.rs
index dc5ea44cda..7167125a33 100644
--- a/crates/router/src/core/connector_validation.rs
+++ b/crates/router/src/core/connector_validation.rs
@@ -536,6 +536,10 @@ impl ConnectorAuthTypeAndMetadataValidation<'_> {
truelayer::transformers::TruelayerAuthType::try_from(self.auth_type)?;
Ok(())
}
+ api_enums::Connector::Trustly => {
+ trustly::transformers::TrustlyAuthType::try_from(self.auth_type)?;
+ Ok(())
+ }
api_enums::Connector::Trustpay => {
trustpay::transformers::TrustpayAuthType::try_from(self.auth_type)?;
Ok(())
diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs
index 0adeccd8a0..8652b416da 100644
--- a/crates/router/src/core/payment_methods/vault.rs
+++ b/crates/router/src/core/payment_methods/vault.rs
@@ -694,6 +694,7 @@ pub struct TokenizedBankSensitiveValues {
pub iban: Option<masking::Secret<String>>,
pub pix_key: Option<masking::Secret<String>>,
pub tax_id: Option<masking::Secret<String>>,
+ pub bank_number: Option<masking::Secret<String>>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
@@ -720,6 +721,7 @@ impl Vaultable for api::BankPayout {
iban: None,
pix_key: None,
tax_id: None,
+ bank_number: None,
},
Self::Bacs(b) => TokenizedBankSensitiveValues {
bank_account_number: Some(b.bank_account_number.to_owned()),
@@ -729,6 +731,7 @@ impl Vaultable for api::BankPayout {
iban: None,
pix_key: None,
tax_id: None,
+ bank_number: None,
},
Self::Sepa(b) => TokenizedBankSensitiveValues {
bank_account_number: None,
@@ -738,6 +741,7 @@ impl Vaultable for api::BankPayout {
iban: Some(b.iban.to_owned()),
pix_key: None,
tax_id: None,
+ bank_number: None,
},
Self::Pix(bank_details) => TokenizedBankSensitiveValues {
bank_account_number: Some(bank_details.bank_account_number.to_owned()),
@@ -747,6 +751,17 @@ impl Vaultable for api::BankPayout {
iban: None,
pix_key: Some(bank_details.pix_key.to_owned()),
tax_id: bank_details.tax_id.to_owned(),
+ bank_number: None,
+ },
+ Self::Trustly(bank_details) => TokenizedBankSensitiveValues {
+ bank_account_number: bank_details.account_number.to_owned(),
+ bank_routing_number: None,
+ bic: None,
+ bank_sort_code: None,
+ iban: bank_details.iban.to_owned(),
+ pix_key: None,
+ tax_id: None,
+ bank_number: bank_details.bank_number.to_owned(),
},
};
@@ -789,6 +804,13 @@ impl Vaultable for api::BankPayout {
bank_city: None,
bank_branch: bank_details.bank_branch.to_owned(),
},
+ Self::Trustly(bank_details) => TokenizedBankInsensitiveValues {
+ customer_id,
+ bank_name: None,
+ bank_country_code: Some(bank_details.country_code),
+ bank_city: None,
+ bank_branch: None,
+ },
};
bank_insensitive_data
@@ -822,8 +844,10 @@ impl Vaultable for api::BankPayout {
// PIX
bank_sensitive_data.pix_key,
bank_sensitive_data.tax_id,
+ // TRUSTLY
+ bank_insensitive_data.bank_country_code,
) {
- (Some(ban), Some(brn), None, None, None, None, None) => {
+ (Some(ban), Some(brn), None, None, None, None, None, None) => {
Self::Ach(payouts::AchBankTransfer {
bank_account_number: ban,
bank_routing_number: brn,
@@ -832,7 +856,7 @@ impl Vaultable for api::BankPayout {
bank_city: bank_insensitive_data.bank_city,
})
}
- (Some(ban), None, Some(bsc), None, None, None, None) => {
+ (Some(ban), None, Some(bsc), None, None, None, None, None) => {
Self::Bacs(payouts::BacsBankTransfer {
bank_account_number: ban,
bank_sort_code: bsc,
@@ -841,7 +865,7 @@ impl Vaultable for api::BankPayout {
bank_city: bank_insensitive_data.bank_city,
})
}
- (None, None, None, Some(iban), bic, None, None) => {
+ (None, None, None, Some(iban), bic, None, None, None) => {
Self::Sepa(payouts::SepaBankTransfer {
iban,
bic,
@@ -850,7 +874,7 @@ impl Vaultable for api::BankPayout {
bank_city: bank_insensitive_data.bank_city,
})
}
- (Some(ban), None, None, None, None, Some(pix_key), tax_id) => {
+ (Some(ban), None, None, None, None, Some(pix_key), tax_id, None) => {
Self::Pix(payouts::PixBankTransfer {
bank_account_number: ban,
bank_branch: bank_insensitive_data.bank_branch,
@@ -859,6 +883,14 @@ impl Vaultable for api::BankPayout {
tax_id,
})
}
+ (account_number, None, None, iban, None, None, None, Some(country_code)) => {
+ Self::Trustly(payouts::TrustlyBankTransfer {
+ iban,
+ account_number,
+ bank_number: bank_sensitive_data.bank_number,
+ country_code,
+ })
+ }
_ => Err(errors::VaultError::ResponseDeserializationFailed)?,
};
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index c53f0e1229..a29a9cc8fd 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -1310,10 +1310,10 @@ pub async fn create_recipient(
is_eligible: recipient_create_data.payout_eligible,
unified_code: None,
unified_message: None,
- payout_connector_metadata: payout_data
- .payout_attempt
+ payout_connector_metadata: recipient_create_data
.payout_connector_metadata
- .to_owned(),
+ .clone()
+ .or(payout_data.payout_attempt.payout_connector_metadata.clone()),
};
payout_data.payout_attempt = db
.update_payout_attempt(
@@ -1350,10 +1350,10 @@ pub async fn create_recipient(
is_eligible: recipient_create_data.payout_eligible,
unified_code: None,
unified_message: None,
- payout_connector_metadata: payout_data
- .payout_attempt
+ payout_connector_metadata: recipient_create_data
.payout_connector_metadata
- .to_owned(),
+ .clone()
+ .or(payout_data.payout_attempt.payout_connector_metadata.clone()),
};
payout_data.payout_attempt = db
.update_payout_attempt(
diff --git a/crates/router/src/types/api/connector_mapping.rs b/crates/router/src/types/api/connector_mapping.rs
index 641700d0d9..cdf96668ca 100644
--- a/crates/router/src/types/api/connector_mapping.rs
+++ b/crates/router/src/types/api/connector_mapping.rs
@@ -473,6 +473,9 @@ impl ConnectorData {
enums::Connector::Truelayer => {
Ok(ConnectorEnum::Old(Box::new(connector::Truelayer::new())))
}
+ enums::Connector::Trustly => {
+ Ok(ConnectorEnum::Old(Box::new(connector::Trustly::new())))
+ }
enums::Connector::Trustpay => {
Ok(ConnectorEnum::Old(Box::new(connector::Trustpay::new())))
}
diff --git a/crates/router/src/types/api/feature_matrix.rs b/crates/router/src/types/api/feature_matrix.rs
index 5fed169a6d..44289616c7 100644
--- a/crates/router/src/types/api/feature_matrix.rs
+++ b/crates/router/src/types/api/feature_matrix.rs
@@ -390,6 +390,9 @@ impl FeatureMatrixConnectorData {
enums::Connector::Truelayer => {
Ok(ConnectorEnum::Old(Box::new(connector::Truelayer::new())))
}
+ enums::Connector::Trustly => {
+ Ok(ConnectorEnum::Old(Box::new(connector::Trustly::new())))
+ }
enums::Connector::Trustpay => {
Ok(ConnectorEnum::Old(Box::new(connector::Trustpay::new())))
}
diff --git a/crates/router/src/types/api/payouts.rs b/crates/router/src/types/api/payouts.rs
index a823dd54c4..ee856888d8 100644
--- a/crates/router/src/types/api/payouts.rs
+++ b/crates/router/src/types/api/payouts.rs
@@ -6,7 +6,7 @@ pub use api_models::payouts::{
PayoutListFilterConstraints, PayoutListFilters, PayoutListFiltersV2, PayoutListResponse,
PayoutMethodData, PayoutMethodDataResponse, PayoutRequest, PayoutRetrieveBody,
PayoutRetrieveRequest, PayoutsManualUpdateRequest, PixBankTransfer,
- RequiredFieldsOverrideRequest, SepaBankTransfer, Wallet as WalletPayout,
+ RequiredFieldsOverrideRequest, SepaBankTransfer, TrustlyBankTransfer, Wallet as WalletPayout,
};
pub use hyperswitch_domain_models::router_flow_types::payouts::{
PoCancel, PoCreate, PoEligibility, PoFulfill, PoQuote, PoRecipient, PoRecipientAccount, PoSync,
diff --git a/crates/router/src/types/connector_transformers.rs b/crates/router/src/types/connector_transformers.rs
index a0f835d0c7..68d9834254 100644
--- a/crates/router/src/types/connector_transformers.rs
+++ b/crates/router/src/types/connector_transformers.rs
@@ -168,6 +168,7 @@ impl ForeignTryFrom<api_enums::Connector> for euclid::enums::RoutableConnectors
}
api_enums::Connector::Tokenio => Self::Tokenio,
api_enums::Connector::Truelayer => Self::Truelayer,
+ api_enums::Connector::Trustly => Self::Trustly,
api_enums::Connector::Trustpay => Self::Trustpay,
api_enums::Connector::Trustpayments => Self::Trustpayments,
api_enums::Connector::Tsys => Self::Tsys,
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 51d2657b2c..aaa4895aa1 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -1344,6 +1344,7 @@ impl ForeignFrom<&api_models::payouts::Bank> for api_enums::PaymentMethodType {
api_models::payouts::Bank::Bacs(_) => Self::Bacs,
api_models::payouts::Bank::Sepa(_) => Self::SepaBankTransfer,
api_models::payouts::Bank::Pix(_) => Self::Pix,
+ api_models::payouts::Bank::Trustly(_) => Self::Trustly,
}
}
}
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 13fbcddddc..de7120f130 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -457,6 +457,9 @@ open_banking_uk = { currency = "GBP,EUR" }
[payout_method_filters.truelayer]
open_banking_uk = { currency = "GBP,EUR,PLN" }
+[payout_method_filters.trustly]
+trustly = { currency = "BGN,GBP,EUR,PLN,CZK,DKK,HRK,HUF,NOK,PLN,RON,SEK" }
+
[pm_filters.adyen]
boleto = { country = "BR", currency = "BRL" }
sofort = { country = "AT,BE,DE,ES,CH,NL", currency = "CHF,EUR" }