square_api_client/api/
apple_pay_api.rs

1//! Apple Pay support APIs
2//!
3//! The Apple Pay APIs provides an easy way for platform developers to bulk activate Web Apple Pay
4//! with Square for merchants using their platform.
5
6use crate::{
7    config::Configuration,
8    http::client::HttpClient,
9    models::{errors::ApiError, RegisterDomainRequest, RegisterDomainResponse},
10};
11
12const DEFAULT_URI: &str = "/apple-pay/domains";
13
14/// Apple Pay support APIs
15pub struct ApplePayApi {
16    /// App config information
17    config: Configuration,
18    /// HTTP Client for requests to the Apple Pay API endpoints
19    client: HttpClient,
20}
21
22impl ApplePayApi {
23    /// Instantiates a new `ApplePayApi`
24    pub fn new(config: Configuration, client: HttpClient) -> Self {
25        Self { config, client }
26    }
27
28    /// Activates a domain for use with Apple Pay on the Web and Square.
29    ///
30    /// A validation is performed on this domain by Apple to ensure that it is properly set up as an
31    /// Apple Pay enabled domain.
32    ///
33    /// This endpoint provides an easy way for platform developers to bulk activate Apple Pay on the
34    /// Web with Square for merchants using their platform.
35    ///
36    /// Note: The SqPaymentForm library is deprecated as of May 13, 2021, and will only receive
37    /// critical security updates until it is retired on October 31, 2022. You must migrate your
38    /// payment form code to the Web Payments SDK to continue using your domain for Apple Pay. For
39    /// more information on migrating to the Web Payments SDK, see [Migrate to the Web Payments
40    /// SDK](https://developer.squareup.com/docs/web-payments/migrate).
41    ///
42    /// To learn more about the Web Payments SDK and how to add Apple Pay, see [Take an Apple Pay
43    /// Payment](https://developer.squareup.com/docs/web-payments/apple-pay).
44    pub async fn register_domain(
45        &self,
46        body: &RegisterDomainRequest,
47    ) -> Result<RegisterDomainResponse, ApiError> {
48        let response = self.client.post(&self.url(), body).await?;
49
50        response.deserialize().await
51    }
52
53    /// Constructs the basic entity URL including domain and entity path. Any additional path
54    /// elements (e.g. path parameters) will need to be appended to this URL.
55    fn url(&self) -> String {
56        format!("{}{}", &self.config.get_base_url(), DEFAULT_URI)
57    }
58}