mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(connector): [Trustpay] add webhooks (payment and refund events) (#746)
Co-authored-by: Sangamesh <sangamesh.kulkarni@juspay.in> Co-authored-by: sai harsha <sai.harsha@sai.harsha-MacBookPro> Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
		| @ -38,24 +38,27 @@ async fn payments_incoming_webhook_flow<W: api::OutgoingWebhookType>( | ||||
|         payments::CallConnectorAction::Trigger | ||||
|     }; | ||||
|  | ||||
|     let payments_response = payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>( | ||||
|         &state, | ||||
|         merchant_account.clone(), | ||||
|         payments::operations::PaymentStatus, | ||||
|         api::PaymentsRetrieveRequest { | ||||
|             resource_id: api::PaymentIdType::ConnectorTransactionId( | ||||
|                 webhook_details.object_reference_id, | ||||
|             ), | ||||
|             merchant_id: Some(merchant_account.merchant_id.clone()), | ||||
|             force_sync: true, | ||||
|             connector: None, | ||||
|             param: None, | ||||
|         }, | ||||
|         services::AuthFlow::Merchant, | ||||
|         consume_or_trigger_flow, | ||||
|     ) | ||||
|     .await | ||||
|     .change_context(errors::WebhooksFlowError::PaymentsCoreFailed)?; | ||||
|     let payments_response = match webhook_details.object_reference_id { | ||||
|         api_models::webhooks::ObjectReferenceId::PaymentId(id) => { | ||||
|             payments::payments_core::<api::PSync, api::PaymentsResponse, _, _, _>( | ||||
|                 &state, | ||||
|                 merchant_account.clone(), | ||||
|                 payments::operations::PaymentStatus, | ||||
|                 api::PaymentsRetrieveRequest { | ||||
|                     resource_id: id, | ||||
|                     merchant_id: Some(merchant_account.merchant_id.clone()), | ||||
|                     force_sync: true, | ||||
|                     connector: None, | ||||
|                     param: None, | ||||
|                 }, | ||||
|                 services::AuthFlow::Merchant, | ||||
|                 consume_or_trigger_flow, | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::WebhooksFlowError::PaymentsCoreFailed)? | ||||
|         } | ||||
|         _ => Err(errors::WebhooksFlowError::PaymentsCoreFailed).into_report()?, | ||||
|     }; | ||||
|  | ||||
|     match payments_response { | ||||
|         services::ApplicationResponse::Json(payments_response) => { | ||||
| @ -101,16 +104,32 @@ async fn refunds_incoming_webhook_flow<W: api::OutgoingWebhookType>( | ||||
| ) -> CustomResult<(), errors::WebhooksFlowError> { | ||||
|     let db = &*state.store; | ||||
|     //find refund by connector refund id | ||||
|     let refund = db | ||||
|         .find_refund_by_merchant_id_connector_refund_id_connector( | ||||
|             &merchant_account.merchant_id, | ||||
|             &webhook_details.object_reference_id, | ||||
|             connector_name, | ||||
|             merchant_account.storage_scheme, | ||||
|         ) | ||||
|         .await | ||||
|         .change_context(errors::WebhooksFlowError::ResourceNotFound) | ||||
|         .attach_printable_lazy(|| "Failed fetching the refund")?; | ||||
|     let refund = match webhook_details.object_reference_id { | ||||
|         api_models::webhooks::ObjectReferenceId::RefundId( | ||||
|             api_models::webhooks::RefundIdType::ConnectorRefundId(id), | ||||
|         ) => db | ||||
|             .find_refund_by_merchant_id_connector_refund_id_connector( | ||||
|                 &merchant_account.merchant_id, | ||||
|                 &id, | ||||
|                 connector_name, | ||||
|                 merchant_account.storage_scheme, | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::WebhooksFlowError::ResourceNotFound) | ||||
|             .attach_printable_lazy(|| "Failed fetching the refund")?, | ||||
|         api_models::webhooks::ObjectReferenceId::RefundId( | ||||
|             api_models::webhooks::RefundIdType::RefundId(id), | ||||
|         ) => db | ||||
|             .find_refund_by_merchant_id_refund_id( | ||||
|                 &merchant_account.merchant_id, | ||||
|                 &id, | ||||
|                 merchant_account.storage_scheme, | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::WebhooksFlowError::ResourceNotFound) | ||||
|             .attach_printable_lazy(|| "Failed fetching the refund")?, | ||||
|         _ => Err(errors::WebhooksFlowError::RefundsCoreFailed).into_report()?, | ||||
|     }; | ||||
|     let refund_id = refund.refund_id.to_owned(); | ||||
|     //if source verified then update refund status else trigger refund sync | ||||
|     let updated_refund = if source_verified { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 saiharsha-juspay
					saiharsha-juspay