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