1
+ use common_utils:: pii;
1
2
use error_stack:: { IntoReport , ResultExt } ;
2
3
use masking:: { ExposeInterface , Secret } ;
3
4
use serde:: { Deserialize , Serialize } ;
@@ -77,8 +78,19 @@ pub enum BraintreePaymentsRequest {
77
78
78
79
#[ derive( Debug , Deserialize ) ]
79
80
pub struct BraintreeMeta {
80
- merchant_account_id : Option < Secret < String > > ,
81
- merchant_config_currency : Option < types:: storage:: enums:: Currency > ,
81
+ merchant_account_id : Secret < String > ,
82
+ merchant_config_currency : types:: storage:: enums:: Currency ,
83
+ }
84
+
85
+ impl TryFrom < & Option < pii:: SecretSerdeValue > > for BraintreeMeta {
86
+ type Error = error_stack:: Report < errors:: ConnectorError > ;
87
+ fn try_from ( meta_data : & Option < pii:: SecretSerdeValue > ) -> Result < Self , Self :: Error > {
88
+ let metadata: Self = utils:: to_connector_meta_from_secret :: < Self > ( meta_data. clone ( ) )
89
+ . change_context ( errors:: ConnectorError :: InvalidConfig {
90
+ field_name : "merchant connector account metadata" ,
91
+ } ) ?;
92
+ Ok ( metadata)
93
+ }
82
94
}
83
95
84
96
#[ derive( Debug , Serialize ) ]
@@ -96,10 +108,13 @@ impl TryFrom<&BraintreeRouterData<&types::PaymentsAuthorizeRouterData>>
96
108
item : & BraintreeRouterData < & types:: PaymentsAuthorizeRouterData > ,
97
109
) -> Result < Self , Self :: Error > {
98
110
let metadata: BraintreeMeta =
99
- utils:: to_connector_meta_from_secret ( item. router_data . connector_meta_data . clone ( ) ) ?;
111
+ utils:: to_connector_meta_from_secret ( item. router_data . connector_meta_data . clone ( ) )
112
+ . change_context ( errors:: ConnectorError :: InvalidConfig {
113
+ field_name : "merchant connector account metadata" ,
114
+ } ) ?;
100
115
utils:: validate_currency (
101
116
item. router_data . request . currency ,
102
- metadata. merchant_config_currency ,
117
+ Some ( metadata. merchant_config_currency ) ,
103
118
) ?;
104
119
105
120
match item. router_data . request . payment_method_data . clone ( ) {
@@ -140,26 +155,28 @@ impl TryFrom<&BraintreeRouterData<&types::PaymentsCompleteAuthorizeRouterData>>
140
155
fn try_from (
141
156
item : & BraintreeRouterData < & types:: PaymentsCompleteAuthorizeRouterData > ,
142
157
) -> Result < Self , Self :: Error > {
143
- match item. router_data . request . payment_method_data . clone ( ) {
144
- Some ( api :: PaymentMethodData :: Card ( _ ) ) => {
158
+ match item. router_data . payment_method {
159
+ api_models :: enums :: PaymentMethod :: Card => {
145
160
Ok ( Self :: Card ( CardPaymentRequest :: try_from ( item) ?) )
146
161
}
147
- Some ( api_models:: payments:: PaymentMethodData :: CardRedirect ( _) )
148
- | Some ( api_models:: payments:: PaymentMethodData :: Wallet ( _) )
149
- | Some ( api_models:: payments:: PaymentMethodData :: PayLater ( _) )
150
- | Some ( api_models:: payments:: PaymentMethodData :: BankRedirect ( _) )
151
- | Some ( api_models:: payments:: PaymentMethodData :: BankDebit ( _) )
152
- | Some ( api_models:: payments:: PaymentMethodData :: BankTransfer ( _) )
153
- | Some ( api_models:: payments:: PaymentMethodData :: Crypto ( _) )
154
- | Some ( api_models:: payments:: PaymentMethodData :: MandatePayment )
155
- | Some ( api_models:: payments:: PaymentMethodData :: Reward )
156
- | Some ( api_models:: payments:: PaymentMethodData :: Upi ( _) )
157
- | Some ( api_models:: payments:: PaymentMethodData :: Voucher ( _) )
158
- | Some ( api_models:: payments:: PaymentMethodData :: GiftCard ( _) )
159
- | None => Err ( errors:: ConnectorError :: NotImplemented (
160
- utils:: get_unimplemented_payment_method_error_message ( "complete authorize flow" ) ,
161
- )
162
- . into ( ) ) ,
162
+ api_models:: enums:: PaymentMethod :: CardRedirect
163
+ | api_models:: enums:: PaymentMethod :: PayLater
164
+ | api_models:: enums:: PaymentMethod :: Wallet
165
+ | api_models:: enums:: PaymentMethod :: BankRedirect
166
+ | api_models:: enums:: PaymentMethod :: BankTransfer
167
+ | api_models:: enums:: PaymentMethod :: Crypto
168
+ | api_models:: enums:: PaymentMethod :: BankDebit
169
+ | api_models:: enums:: PaymentMethod :: Reward
170
+ | api_models:: enums:: PaymentMethod :: Upi
171
+ | api_models:: enums:: PaymentMethod :: Voucher
172
+ | api_models:: enums:: PaymentMethod :: GiftCard => {
173
+ Err ( errors:: ConnectorError :: NotImplemented (
174
+ utils:: get_unimplemented_payment_method_error_message (
175
+ "complete authorize flow" ,
176
+ ) ,
177
+ )
178
+ . into ( ) )
179
+ }
163
180
}
164
181
}
165
182
}
@@ -249,7 +266,6 @@ impl<F>
249
266
* client_token_data,
250
267
item. data . get_payment_method_token ( ) ?,
251
268
item. data . request . payment_method_data . clone ( ) ,
252
- item. data . request . amount ,
253
269
) ?) ,
254
270
mandate_reference : None ,
255
271
connector_metadata : None ,
@@ -428,7 +444,6 @@ impl<F>
428
444
* client_token_data,
429
445
item. data . get_payment_method_token ( ) ?,
430
446
item. data . request . payment_method_data . clone ( ) ,
431
- item. data . request . amount ,
432
447
) ?) ,
433
448
mandate_reference : None ,
434
449
connector_metadata : None ,
@@ -586,23 +601,22 @@ impl<F> TryFrom<BraintreeRouterData<&types::RefundsRouterData<F>>> for Braintree
586
601
item : BraintreeRouterData < & types:: RefundsRouterData < F > > ,
587
602
) -> Result < Self , Self :: Error > {
588
603
let metadata: BraintreeMeta =
589
- utils:: to_connector_meta_from_secret ( item. router_data . connector_meta_data . clone ( ) ) ?;
604
+ utils:: to_connector_meta_from_secret ( item. router_data . connector_meta_data . clone ( ) )
605
+ . change_context ( errors:: ConnectorError :: InvalidConfig {
606
+ field_name : "merchant connector account metadata" ,
607
+ } ) ?;
590
608
591
609
utils:: validate_currency (
592
610
item. router_data . request . currency ,
593
- metadata. merchant_config_currency ,
611
+ Some ( metadata. merchant_config_currency ) ,
594
612
) ?;
595
613
let query = REFUND_TRANSACTION_MUTATION . to_string ( ) ;
596
614
let variables = BraintreeRefundVariables {
597
615
input : BraintreeRefundInput {
598
616
transaction_id : item. router_data . request . connector_transaction_id . clone ( ) ,
599
617
refund : RefundInputData {
600
618
amount : item. amount ,
601
- merchant_account_id : metadata. merchant_account_id . ok_or (
602
- errors:: ConnectorError :: MissingRequiredField {
603
- field_name : "merchant_account_id" ,
604
- } ,
605
- ) ?,
619
+ merchant_account_id : metadata. merchant_account_id ,
606
620
} ,
607
621
} ,
608
622
} ;
@@ -695,9 +709,16 @@ pub struct BraintreeRSyncRequest {
695
709
impl TryFrom < & types:: RefundSyncRouterData > for BraintreeRSyncRequest {
696
710
type Error = error_stack:: Report < errors:: ConnectorError > ;
697
711
fn try_from ( item : & types:: RefundSyncRouterData ) -> Result < Self , Self :: Error > {
698
- let metadata: BraintreeMeta =
699
- utils:: to_connector_meta_from_secret ( item. connector_meta_data . clone ( ) ) ?;
700
- utils:: validate_currency ( item. request . currency , metadata. merchant_config_currency ) ?;
712
+ let metadata: BraintreeMeta = utils:: to_connector_meta_from_secret (
713
+ item. connector_meta_data . clone ( ) ,
714
+ )
715
+ . change_context ( errors:: ConnectorError :: InvalidConfig {
716
+ field_name : "merchant connector account metadata" ,
717
+ } ) ?;
718
+ utils:: validate_currency (
719
+ item. request . currency ,
720
+ Some ( metadata. merchant_config_currency ) ,
721
+ ) ?;
701
722
let refund_id = item. request . get_connector_refund_id ( ) ?;
702
723
let query = format ! ( "query {{ search {{ refunds(input: {{ id: {{is: \" {}\" }} }}, first: 1) {{ edges {{ node {{ id status createdAt amount {{ value currencyCode }} orderId }} }} }} }} }}" , refund_id) ;
703
724
@@ -1250,6 +1271,13 @@ pub struct BraintreeThreeDsResponse {
1250
1271
pub liability_shift_possible : bool ,
1251
1272
}
1252
1273
1274
+ #[ derive( Debug , Deserialize ) ]
1275
+ #[ serde( rename_all = "camelCase" ) ]
1276
+ pub struct BraintreeThreeDsErrorResponse {
1277
+ pub code : String ,
1278
+ pub message : String ,
1279
+ }
1280
+
1253
1281
#[ derive( Debug , Deserialize ) ]
1254
1282
pub struct BraintreeRedirectionResponse {
1255
1283
pub authentication_response : String ,
@@ -1263,11 +1291,7 @@ impl TryFrom<BraintreeMeta> for BraintreeClientTokenRequest {
1263
1291
variables : VariableClientTokenInput {
1264
1292
input : InputClientTokenData {
1265
1293
client_token : ClientTokenInput {
1266
- merchant_account_id : metadata. merchant_account_id . ok_or (
1267
- errors:: ConnectorError :: MissingRequiredField {
1268
- field_name : "merchant_account_id" ,
1269
- } ,
1270
- ) ?,
1294
+ merchant_account_id : metadata. merchant_account_id ,
1271
1295
} ,
1272
1296
} ,
1273
1297
} ,
@@ -1304,11 +1328,7 @@ impl
1304
1328
} ,
1305
1329
transaction : TransactionBody {
1306
1330
amount : item. amount . to_owned ( ) ,
1307
- merchant_account_id : metadata. merchant_account_id . ok_or (
1308
- errors:: ConnectorError :: MissingRequiredField {
1309
- field_name : "merchant_account_id" ,
1310
- } ,
1311
- ) ?,
1331
+ merchant_account_id : metadata. merchant_account_id ,
1312
1332
} ,
1313
1333
} ,
1314
1334
} ,
@@ -1324,10 +1344,13 @@ impl TryFrom<&BraintreeRouterData<&types::PaymentsCompleteAuthorizeRouterData>>
1324
1344
item : & BraintreeRouterData < & types:: PaymentsCompleteAuthorizeRouterData > ,
1325
1345
) -> Result < Self , Self :: Error > {
1326
1346
let metadata: BraintreeMeta =
1327
- utils:: to_connector_meta_from_secret ( item. router_data . connector_meta_data . clone ( ) ) ?;
1347
+ utils:: to_connector_meta_from_secret ( item. router_data . connector_meta_data . clone ( ) )
1348
+ . change_context ( errors:: ConnectorError :: InvalidConfig {
1349
+ field_name : "merchant connector account metadata" ,
1350
+ } ) ?;
1328
1351
utils:: validate_currency (
1329
1352
item. router_data . request . currency ,
1330
- metadata. merchant_config_currency ,
1353
+ Some ( metadata. merchant_config_currency ) ,
1331
1354
) ?;
1332
1355
let payload_data =
1333
1356
utils:: PaymentsCompleteAuthorizeRequestData :: get_redirect_response_payload (
@@ -1360,11 +1383,7 @@ impl TryFrom<&BraintreeRouterData<&types::PaymentsCompleteAuthorizeRouterData>>
1360
1383
payment_method_id : three_ds_data. nonce ,
1361
1384
transaction : TransactionBody {
1362
1385
amount : item. amount . to_owned ( ) ,
1363
- merchant_account_id : metadata. merchant_account_id . ok_or (
1364
- errors:: ConnectorError :: MissingRequiredField {
1365
- field_name : "merchant_account_id" ,
1366
- } ,
1367
- ) ?,
1386
+ merchant_account_id : metadata. merchant_account_id ,
1368
1387
} ,
1369
1388
} ,
1370
1389
} ,
@@ -1376,7 +1395,6 @@ fn get_braintree_redirect_form(
1376
1395
client_token_data : ClientTokenResponse ,
1377
1396
payment_method_token : types:: PaymentMethodToken ,
1378
1397
card_details : api_models:: payments:: PaymentMethodData ,
1379
- amount : i64 ,
1380
1398
) -> Result < services:: RedirectForm , error_stack:: Report < errors:: ConnectorError > > {
1381
1399
Ok ( services:: RedirectForm :: Braintree {
1382
1400
client_token : client_token_data
@@ -1409,7 +1427,6 @@ fn get_braintree_redirect_form(
1409
1427
errors:: ConnectorError :: NotImplemented ( "given payment method" . to_owned ( ) ) ,
1410
1428
) ?,
1411
1429
} ,
1412
- amount,
1413
1430
} )
1414
1431
}
1415
1432
0 commit comments