mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(connector): add webhook support for worldline connector (#721)
This commit is contained in:
		| @ -298,16 +298,6 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>( | ||||
|         body: &body, | ||||
|     }; | ||||
|  | ||||
|     let source_verified = connector | ||||
|         .verify_webhook_source( | ||||
|             &*state.store, | ||||
|             &request_details, | ||||
|             &merchant_account.merchant_id, | ||||
|         ) | ||||
|         .await | ||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|         .attach_printable("There was an issue in incoming webhook source verification")?; | ||||
|  | ||||
|     let decoded_body = connector | ||||
|         .decode_webhook_body( | ||||
|             &*state.store, | ||||
| @ -325,63 +315,78 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>( | ||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|         .attach_printable("Could not find event type in incoming webhook body")?; | ||||
|  | ||||
|     let process_webhook_further = utils::lookup_webhook_event( | ||||
|         &*state.store, | ||||
|         connector_name, | ||||
|         &merchant_account.merchant_id, | ||||
|         &event_type, | ||||
|     ) | ||||
|     .await; | ||||
|  | ||||
|     if process_webhook_further { | ||||
|         let object_ref_id = connector | ||||
|             .get_webhook_object_reference_id(&request_details) | ||||
|     if !matches!( | ||||
|         event_type, | ||||
|         api_models::webhooks::IncomingWebhookEvent::EndpointVerification | ||||
|     ) { | ||||
|         let source_verified = connector | ||||
|             .verify_webhook_source( | ||||
|                 &*state.store, | ||||
|                 &request_details, | ||||
|                 &merchant_account.merchant_id, | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Could not find object reference id in incoming webhook body")?; | ||||
|             .attach_printable("There was an issue in incoming webhook source verification")?; | ||||
|  | ||||
|         let event_object = connector | ||||
|             .get_webhook_resource_object(&request_details) | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Could not find resource object in incoming webhook body")?; | ||||
|         let process_webhook_further = utils::lookup_webhook_event( | ||||
|             &*state.store, | ||||
|             connector_name, | ||||
|             &merchant_account.merchant_id, | ||||
|             &event_type, | ||||
|         ) | ||||
|         .await; | ||||
|  | ||||
|         let webhook_details = api::IncomingWebhookDetails { | ||||
|             object_reference_id: object_ref_id, | ||||
|             resource_object: Encode::<serde_json::Value>::encode_to_vec(&event_object) | ||||
|         if process_webhook_further { | ||||
|             let object_ref_id = connector | ||||
|                 .get_webhook_object_reference_id(&request_details) | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable( | ||||
|                     "There was an issue when encoding the incoming webhook body to bytes", | ||||
|                 )?, | ||||
|         }; | ||||
|                 .attach_printable("Could not find object reference id in incoming webhook body")?; | ||||
|  | ||||
|         let flow_type: api::WebhookFlow = event_type.to_owned().into(); | ||||
|         match flow_type { | ||||
|             api::WebhookFlow::Payment => payments_incoming_webhook_flow::<W>( | ||||
|                 state.clone(), | ||||
|                 merchant_account, | ||||
|                 webhook_details, | ||||
|                 source_verified, | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Incoming webhook flow for payments failed")?, | ||||
|             let event_object = connector | ||||
|                 .get_webhook_resource_object(&request_details) | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("Could not find resource object in incoming webhook body")?; | ||||
|  | ||||
|             api::WebhookFlow::Refund => refunds_incoming_webhook_flow::<W>( | ||||
|                 state.clone(), | ||||
|                 merchant_account, | ||||
|                 webhook_details, | ||||
|                 connector_name, | ||||
|                 source_verified, | ||||
|                 event_type, | ||||
|             ) | ||||
|             .await | ||||
|             .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|             .attach_printable("Incoming webhook flow for refunds failed")?, | ||||
|             let webhook_details = api::IncomingWebhookDetails { | ||||
|                 object_reference_id: object_ref_id, | ||||
|                 resource_object: Encode::<serde_json::Value>::encode_to_vec(&event_object) | ||||
|                     .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                     .attach_printable( | ||||
|                         "There was an issue when encoding the incoming webhook body to bytes", | ||||
|                     )?, | ||||
|             }; | ||||
|  | ||||
|             api::WebhookFlow::ReturnResponse => {} | ||||
|             let flow_type: api::WebhookFlow = event_type.to_owned().into(); | ||||
|             match flow_type { | ||||
|                 api::WebhookFlow::Payment => payments_incoming_webhook_flow::<W>( | ||||
|                     state.clone(), | ||||
|                     merchant_account, | ||||
|                     webhook_details, | ||||
|                     source_verified, | ||||
|                 ) | ||||
|                 .await | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("Incoming webhook flow for payments failed")?, | ||||
|  | ||||
|             _ => Err(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .into_report() | ||||
|                 .attach_printable("Unsupported Flow Type received in incoming webhooks")?, | ||||
|                 api::WebhookFlow::Refund => refunds_incoming_webhook_flow::<W>( | ||||
|                     state.clone(), | ||||
|                     merchant_account, | ||||
|                     webhook_details, | ||||
|                     connector_name, | ||||
|                     source_verified, | ||||
|                     event_type, | ||||
|                 ) | ||||
|                 .await | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("Incoming webhook flow for refunds failed")?, | ||||
|  | ||||
|                 api::WebhookFlow::ReturnResponse => {} | ||||
|  | ||||
|                 _ => Err(errors::ApiErrorResponse::InternalServerError) | ||||
|                     .into_report() | ||||
|                     .attach_printable("Unsupported Flow Type received in incoming webhooks")?, | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Arjun Karthik
					Arjun Karthik