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