@@ -272,18 +272,10 @@ pub struct JpmorganPaymentsResponse {
272
272
#[ serde( rename_all = "camelCase" ) ]
273
273
pub struct Merchant {
274
274
merchant_id : Option < String > ,
275
- merchant_software : MerchantSoftware ,
275
+ merchant_software : JpmorganMerchantSoftware ,
276
276
merchant_category_code : Option < String > ,
277
277
}
278
278
279
- #[ derive( Default , Debug , Serialize , Deserialize ) ]
280
- #[ serde( rename_all = "camelCase" ) ]
281
- pub struct MerchantSoftware {
282
- company_name : Secret < String > ,
283
- product_name : Secret < String > ,
284
- version : Option < Secret < String > > ,
285
- }
286
-
287
279
#[ derive( Default , Debug , Deserialize , Serialize ) ]
288
280
#[ serde( rename_all = "camelCase" ) ]
289
281
pub struct PaymentMethodType {
@@ -522,18 +514,31 @@ pub struct TransactionData {
522
514
pub struct JpmorganRefundRequest {
523
515
pub merchant : MerchantRefundReq ,
524
516
pub amount : MinorUnit ,
517
+ pub currency : common_enums:: Currency ,
525
518
}
526
519
527
520
#[ derive( Default , Debug , Serialize , Deserialize ) ]
528
521
#[ serde( rename_all = "camelCase" ) ]
529
522
pub struct MerchantRefundReq {
530
- pub merchant_software : MerchantSoftware ,
523
+ pub merchant_software : JpmorganMerchantSoftware ,
531
524
}
532
525
533
526
impl < F > TryFrom < & JpmorganRouterData < & RefundsRouterData < F > > > for JpmorganRefundRequest {
534
527
type Error = error_stack:: Report < errors:: ConnectorError > ;
535
- fn try_from ( _item : & JpmorganRouterData < & RefundsRouterData < F > > ) -> Result < Self , Self :: Error > {
536
- Err ( errors:: ConnectorError :: NotImplemented ( "Refunds" . to_string ( ) ) . into ( ) )
528
+ fn try_from ( item : & JpmorganRouterData < & RefundsRouterData < F > > ) -> Result < Self , Self :: Error > {
529
+ let merchant_software = JpmorganMerchantSoftware {
530
+ company_name : String :: from ( "JPMC" ) . into ( ) ,
531
+ product_name : String :: from ( "Hyperswitch" ) . into ( ) ,
532
+ } ;
533
+ let merchant = MerchantRefundReq { merchant_software } ;
534
+ let amount = item. amount ;
535
+ let currency = item. router_data . request . currency ;
536
+
537
+ Ok ( Self {
538
+ merchant,
539
+ amount,
540
+ currency,
541
+ } )
537
542
}
538
543
}
539
544
@@ -552,7 +557,6 @@ pub struct JpmorganRefundResponse {
552
557
pub remaining_refundable_amount : Option < i64 > ,
553
558
}
554
559
555
- #[ allow( dead_code) ]
556
560
#[ derive( Debug , Serialize , Default , Deserialize , Clone ) ]
557
561
pub enum RefundStatus {
558
562
Succeeded ,
@@ -571,24 +575,23 @@ impl From<RefundStatus> for common_enums::RefundStatus {
571
575
}
572
576
}
573
577
574
- #[ derive( Default , Debug , Clone , Serialize , Deserialize ) ]
575
- pub struct RefundResponse {
576
- id : String ,
577
- status : RefundStatus ,
578
- }
579
-
580
- pub fn refund_status_from_transaction_state (
581
- transaction_state : JpmorganTransactionState ,
582
- ) -> common_enums:: RefundStatus {
583
- match transaction_state {
584
- JpmorganTransactionState :: Voided | JpmorganTransactionState :: Closed => {
585
- common_enums:: RefundStatus :: Success
586
- }
587
- JpmorganTransactionState :: Declined | JpmorganTransactionState :: Error => {
588
- common_enums:: RefundStatus :: Failure
589
- }
590
- JpmorganTransactionState :: Pending | JpmorganTransactionState :: Authorized => {
591
- common_enums:: RefundStatus :: Pending
578
+ impl From < ( JpmorganResponseStatus , JpmorganTransactionState ) > for RefundStatus {
579
+ fn from (
580
+ ( response_status, transaction_state) : ( JpmorganResponseStatus , JpmorganTransactionState ) ,
581
+ ) -> Self {
582
+ match response_status {
583
+ JpmorganResponseStatus :: Success => match transaction_state {
584
+ JpmorganTransactionState :: Voided | JpmorganTransactionState :: Closed => {
585
+ Self :: Succeeded
586
+ }
587
+ JpmorganTransactionState :: Declined | JpmorganTransactionState :: Error => {
588
+ Self :: Failed
589
+ }
590
+ JpmorganTransactionState :: Pending | JpmorganTransactionState :: Authorized => {
591
+ Self :: Processing
592
+ }
593
+ } ,
594
+ JpmorganResponseStatus :: Denied | JpmorganResponseStatus :: Error => Self :: Failed ,
592
595
}
593
596
}
594
597
}
@@ -607,9 +610,11 @@ impl TryFrom<RefundsResponseRouterData<Execute, JpmorganRefundResponse>>
607
610
. transaction_id
608
611
. clone ( )
609
612
. ok_or ( errors:: ConnectorError :: ResponseHandlingFailed ) ?,
610
- refund_status : refund_status_from_transaction_state (
613
+ refund_status : RefundStatus :: from ( (
614
+ item. response . response_status ,
611
615
item. response . transaction_state ,
612
- ) ,
616
+ ) )
617
+ . into ( ) ,
613
618
} ) ,
614
619
..item. data
615
620
} )
@@ -638,9 +643,11 @@ impl TryFrom<RefundsResponseRouterData<RSync, JpmorganRefundSyncResponse>>
638
643
Ok ( Self {
639
644
response : Ok ( RefundsResponseData {
640
645
connector_refund_id : item. response . transaction_id . clone ( ) ,
641
- refund_status : refund_status_from_transaction_state (
646
+ refund_status : RefundStatus :: from ( (
647
+ item. response . response_status ,
642
648
item. response . transaction_state ,
643
- ) ,
649
+ ) )
650
+ . into ( ) ,
644
651
} ) ,
645
652
..item. data
646
653
} )
0 commit comments