@@ -73,7 +73,9 @@ pub struct OrderAmount {
73
73
74
74
#[ derive( Default , Debug , Serialize , Eq , PartialEq ) ]
75
75
pub struct PurchaseUnitRequest {
76
- reference_id : String ,
76
+ reference_id : Option < String > , //reference for an item in purchase_units
77
+ invoice_id : Option < String > , //The API caller-provided external invoice number for this order. Appears in both the payer's transaction history and the emails that the payer receives.
78
+ custom_id : Option < String > , //Used to reconcile client transactions with PayPal transactions.
77
79
amount : OrderAmount ,
78
80
}
79
81
@@ -260,10 +262,13 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalP
260
262
currency_code : item. router_data . request . currency ,
261
263
value : item. amount . to_owned ( ) ,
262
264
} ;
263
- let reference_id = item. router_data . attempt_id . clone ( ) ;
265
+ let connector_request_reference_id =
266
+ item. router_data . connector_request_reference_id . clone ( ) ;
264
267
265
268
let purchase_units = vec ! [ PurchaseUnitRequest {
266
- reference_id,
269
+ reference_id: Some ( connector_request_reference_id. clone( ) ) ,
270
+ custom_id: Some ( connector_request_reference_id. clone( ) ) ,
271
+ invoice_id: Some ( connector_request_reference_id) ,
267
272
amount,
268
273
} ] ;
269
274
let card = item. router_data . request . get_card ( ) ?;
@@ -304,9 +309,14 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalP
304
309
currency_code : item. router_data . request . currency ,
305
310
value : item. amount . to_owned ( ) ,
306
311
} ;
307
- let reference_id = item. router_data . attempt_id . clone ( ) ;
312
+
313
+ let connector_req_reference_id =
314
+ item. router_data . connector_request_reference_id . clone ( ) ;
315
+
308
316
let purchase_units = vec ! [ PurchaseUnitRequest {
309
- reference_id,
317
+ reference_id: Some ( connector_req_reference_id. clone( ) ) ,
318
+ custom_id: Some ( connector_req_reference_id. clone( ) ) ,
319
+ invoice_id: Some ( connector_req_reference_id) ,
310
320
amount,
311
321
} ] ;
312
322
let payment_source =
@@ -367,9 +377,13 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalP
367
377
currency_code : item. router_data . request . currency ,
368
378
value : item. amount . to_owned ( ) ,
369
379
} ;
370
- let reference_id = item. router_data . attempt_id . clone ( ) ;
380
+ let connector_req_reference_id =
381
+ item. router_data . connector_request_reference_id . clone ( ) ;
382
+
371
383
let purchase_units = vec ! [ PurchaseUnitRequest {
372
- reference_id,
384
+ reference_id: Some ( connector_req_reference_id. clone( ) ) ,
385
+ custom_id: Some ( connector_req_reference_id. clone( ) ) ,
386
+ invoice_id: Some ( connector_req_reference_id) ,
373
387
amount,
374
388
} ] ;
375
389
let payment_source =
@@ -655,7 +669,8 @@ pub struct PaymentsCollection {
655
669
656
670
#[ derive( Default , Debug , Clone , Serialize , Deserialize ) ]
657
671
pub struct PurchaseUnitItem {
658
- pub reference_id : String ,
672
+ pub reference_id : Option < String > ,
673
+ pub invoice_id : Option < String > ,
659
674
pub payments : PaymentsCollection ,
660
675
}
661
676
@@ -680,11 +695,17 @@ pub struct PaypalLinks {
680
695
rel : String ,
681
696
}
682
697
698
+ #[ derive( Default , Debug , Clone , Serialize , Deserialize ) ]
699
+ pub struct RedirectPurchaseUnitItem {
700
+ pub invoice_id : String ,
701
+ }
702
+
683
703
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
684
704
pub struct PaypalRedirectResponse {
685
705
id : String ,
686
706
intent : PaypalPaymentIntent ,
687
707
status : PaypalOrderStatus ,
708
+ purchase_units : Vec < RedirectPurchaseUnitItem > ,
688
709
links : Vec < PaypalLinks > ,
689
710
}
690
711
@@ -712,6 +733,7 @@ pub struct PaypalPaymentsSyncResponse {
712
733
id : String ,
713
734
status : PaypalPaymentStatus ,
714
735
amount : OrderAmount ,
736
+ invoice_id : Option < String > ,
715
737
supplementary_data : PaypalSupplementaryData ,
716
738
}
717
739
@@ -792,7 +814,7 @@ impl<F, T>
792
814
capture_id: Some ( id) ,
793
815
psync_flow: item. response. intent. clone( )
794
816
} ) ,
795
- types:: ResponseId :: ConnectorTransactionId ( item. response . id ) ,
817
+ types:: ResponseId :: ConnectorTransactionId ( item. response . id . clone ( ) ) ,
796
818
) ,
797
819
798
820
PaypalPaymentIntent :: Authorize => (
@@ -801,7 +823,7 @@ impl<F, T>
801
823
capture_id: None ,
802
824
psync_flow: item. response. intent. clone( )
803
825
} ) ,
804
- types:: ResponseId :: ConnectorTransactionId ( item. response . id ) ,
826
+ types:: ResponseId :: ConnectorTransactionId ( item. response . id . clone ( ) ) ,
805
827
) ,
806
828
807
829
PaypalPaymentIntent :: Authenticate => {
@@ -836,7 +858,10 @@ impl<F, T>
836
858
mandate_reference : None ,
837
859
connector_metadata : Some ( connector_meta) ,
838
860
network_txn_id : None ,
839
- connector_response_reference_id : None ,
861
+ connector_response_reference_id : purchase_units
862
+ . invoice_id
863
+ . clone ( )
864
+ . or ( Some ( item. response . id ) ) ,
840
865
} ) ,
841
866
..item. data
842
867
} )
@@ -925,19 +950,22 @@ impl<F, T>
925
950
capture_id: None ,
926
951
psync_flow: item. response. intent
927
952
} ) ;
953
+ let purchase_units = item. response . purchase_units . first ( ) ;
928
954
929
955
Ok ( Self {
930
956
status,
931
957
response : Ok ( types:: PaymentsResponseData :: TransactionResponse {
932
- resource_id : types:: ResponseId :: ConnectorTransactionId ( item. response . id ) ,
958
+ resource_id : types:: ResponseId :: ConnectorTransactionId ( item. response . id . clone ( ) ) ,
933
959
redirection_data : Some ( services:: RedirectForm :: from ( (
934
960
link. ok_or ( errors:: ConnectorError :: ResponseDeserializationFailed ) ?,
935
961
services:: Method :: Get ,
936
962
) ) ) ,
937
963
mandate_reference : None ,
938
964
connector_metadata : Some ( connector_meta) ,
939
965
network_txn_id : None ,
940
- connector_response_reference_id : None ,
966
+ connector_response_reference_id : Some (
967
+ purchase_units. map_or ( item. response . id , |item| item. invoice_id . clone ( ) ) ,
968
+ ) ,
941
969
} ) ,
942
970
..item. data
943
971
} )
@@ -1075,13 +1103,21 @@ impl<F, T>
1075
1103
status : storage_enums:: AttemptStatus :: from ( item. response . status ) ,
1076
1104
response : Ok ( types:: PaymentsResponseData :: TransactionResponse {
1077
1105
resource_id : types:: ResponseId :: ConnectorTransactionId (
1078
- item. response . supplementary_data . related_ids . order_id ,
1106
+ item. response
1107
+ . supplementary_data
1108
+ . related_ids
1109
+ . order_id
1110
+ . clone ( ) ,
1079
1111
) ,
1080
1112
redirection_data : None ,
1081
1113
mandate_reference : None ,
1082
1114
connector_metadata : None ,
1083
1115
network_txn_id : None ,
1084
- connector_response_reference_id : None ,
1116
+ connector_response_reference_id : item
1117
+ . response
1118
+ . invoice_id
1119
+ . clone ( )
1120
+ . or ( Some ( item. response . supplementary_data . related_ids . order_id ) ) ,
1085
1121
} ) ,
1086
1122
..item. data
1087
1123
} )
@@ -1133,6 +1169,7 @@ pub struct PaypalCaptureResponse {
1133
1169
id : String ,
1134
1170
status : PaypalPaymentStatus ,
1135
1171
amount : Option < OrderAmount > ,
1172
+ invoice_id : Option < String > ,
1136
1173
final_capture : bool ,
1137
1174
}
1138
1175
@@ -1174,11 +1211,14 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<PaypalCaptureResponse>>
1174
1211
mandate_reference : None ,
1175
1212
connector_metadata : Some ( serde_json:: json!( PaypalMeta {
1176
1213
authorize_id: connector_payment_id. authorize_id,
1177
- capture_id: Some ( item. response. id) ,
1214
+ capture_id: Some ( item. response. id. clone ( ) ) ,
1178
1215
psync_flow: PaypalPaymentIntent :: Capture
1179
1216
} ) ) ,
1180
1217
network_txn_id : None ,
1181
- connector_response_reference_id : None ,
1218
+ connector_response_reference_id : item
1219
+ . response
1220
+ . invoice_id
1221
+ . or ( Some ( item. response . id ) ) ,
1182
1222
} ) ,
1183
1223
amount_captured : Some ( amount_captured) ,
1184
1224
..item. data
@@ -1193,11 +1233,11 @@ pub enum PaypalCancelStatus {
1193
1233
}
1194
1234
1195
1235
#[ derive( Debug , Serialize , Deserialize , PartialEq ) ]
1196
- #[ serde( rename_all = "camelCase" ) ]
1197
1236
pub struct PaypalPaymentsCancelResponse {
1198
1237
id : String ,
1199
1238
status : PaypalCancelStatus ,
1200
1239
amount : Option < OrderAmount > ,
1240
+ invoice_id : Option < String > ,
1201
1241
}
1202
1242
1203
1243
impl < F , T >
@@ -1220,12 +1260,15 @@ impl<F, T>
1220
1260
Ok ( Self {
1221
1261
status,
1222
1262
response : Ok ( types:: PaymentsResponseData :: TransactionResponse {
1223
- resource_id : types:: ResponseId :: ConnectorTransactionId ( item. response . id ) ,
1263
+ resource_id : types:: ResponseId :: ConnectorTransactionId ( item. response . id . clone ( ) ) ,
1224
1264
redirection_data : None ,
1225
1265
mandate_reference : None ,
1226
1266
connector_metadata : None ,
1227
1267
network_txn_id : None ,
1228
- connector_response_reference_id : None ,
1268
+ connector_response_reference_id : item
1269
+ . response
1270
+ . invoice_id
1271
+ . or ( Some ( item. response . id ) ) ,
1229
1272
} ) ,
1230
1273
..item. data
1231
1274
} )
@@ -1408,6 +1451,7 @@ pub struct PaypalSellerPayableBreakdown {
1408
1451
pub struct PaypalCardWebhooks {
1409
1452
pub supplementary_data : PaypalSupplementaryData ,
1410
1453
pub amount : OrderAmount ,
1454
+ pub invoice_id : Option < String > ,
1411
1455
}
1412
1456
1413
1457
#[ derive( Deserialize , Debug , Serialize ) ]
@@ -1528,6 +1572,7 @@ impl TryFrom<(PaypalCardWebhooks, PaypalWebhookEventType)> for PaypalPaymentsSyn
1528
1572
status : PaypalPaymentStatus :: try_from ( webhook_event) ?,
1529
1573
amount : webhook_body. amount ,
1530
1574
supplementary_data : webhook_body. supplementary_data ,
1575
+ invoice_id : webhook_body. invoice_id ,
1531
1576
} )
1532
1577
}
1533
1578
}
0 commit comments