paypal_rust/resources/
webhooks.rs1use std::borrow::Cow;
2
3use reqwest::Method;
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6
7use crate::client::endpoint::Endpoint;
8use crate::client::error::PayPalError;
9use crate::client::paypal::Client;
10use crate::resources::enums::verification_status::VerificationStatus;
11
12pub struct Webhook;
13
14impl Webhook {
15 pub async fn verify(
17 client: &Client,
18 dto: VerifyWebhookSignatureDto,
19 ) -> Result<VerifyWebhookSignatureResponse, PayPalError> {
20 client.post(&VerifyWebhookSignature::new(dto)).await
21 }
22}
23
24#[skip_serializing_none]
25#[derive(Clone, Debug, Serialize)]
26pub struct VerifyWebhookSignatureDto {
27 pub auth_algo: String,
30
31 pub cert_url: String,
34
35 pub transmission_id: String,
37
38 pub transmission_sig: String,
40
41 pub transmission_time: String,
44
45 pub webhook_event: serde_json::Value,
48
49 pub webhook_id: String,
51}
52
53#[derive(Clone, Debug, Deserialize)]
54pub struct VerifyWebhookSignatureResponse {
55 pub verification_status: VerificationStatus,
57}
58
59#[derive(Debug)]
60struct VerifyWebhookSignature {
61 pub body: VerifyWebhookSignatureDto,
62}
63
64impl VerifyWebhookSignature {
65 pub const fn new(body: VerifyWebhookSignatureDto) -> Self {
66 Self { body }
67 }
68}
69
70impl Endpoint for VerifyWebhookSignature {
71 type QueryParams = ();
72 type RequestBody = VerifyWebhookSignatureDto;
73 type ResponseBody = VerifyWebhookSignatureResponse;
74
75 fn path(&self) -> Cow<str> {
76 Cow::Borrowed("v1/notifications/verify-webhook-signature")
77 }
78
79 fn request_body(&self) -> Option<Self::RequestBody> {
80 Some(self.body.clone())
81 }
82
83 fn request_method(&self) -> Method {
84 Method::POST
85 }
86}