Skip to content

Commit

Permalink
Support additional_emails field on Customer
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmiller609 committed Jan 17, 2024
1 parent 1928b7f commit 07b687e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Versioning].

## [Unreleased] <!-- #release:date -->

* Support `additional_emails` field on `Customer`.

## [0.8.1] - 2024-01-12

* Fix bug causing deserialization errors when `get_customer_costs` responses
Expand Down
8 changes: 8 additions & 0 deletions src/client/customers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub struct CreateCustomerRequest<'a> {
pub name: &'a str,
/// A valid email for the customer, to be used for notifications.
pub email: &'a str,
/// Additional email addresses for this customer.
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_emails: Option<Vec<&'a str>>,
/// The customer's timezone as an identifier from the IANA timezone
/// database.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -102,6 +105,9 @@ pub struct UpdateCustomerRequest<'a> {
/// A valid email for the customer, to be used for notifications.
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<&'a str>,
/// Additional email addresses for this customer.
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_emails: Option<Vec<&'a str>>,
/// The external payments or invoicing solution connected to the customer.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(flatten)]
Expand Down Expand Up @@ -152,6 +158,8 @@ pub struct Customer {
pub name: String,
/// A valid email for the customer, to be used for notifications.
pub email: String,
/// Additional email addresses for this customer.
pub additional_emails: Vec<String>,
/// The customer's timezone as an identifier from the IANA timezone
/// database.
pub timezone: String,
Expand Down
33 changes: 33 additions & 0 deletions tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ async fn test_customers() {
assert_eq!(customer.billing_address, None);
assert_eq!(customer.shipping_address, None);
assert_eq!(customer.tax_id, None);
let empty_emails: Vec<String> = vec![];
assert_eq!(customer.additional_emails, empty_emails);

// Test fetching the customer by ID.
let customer = client.get_customer(&customer.id).await.unwrap();
Expand Down Expand Up @@ -242,6 +244,37 @@ async fn test_customers() {
assert_eq!(customer.email, "[email protected]");
let customer = client.get_customer(&customer.id).await.unwrap();
assert_eq!(customer.email, "[email protected]");
let empty_emails: Vec<String> = vec![];
assert_eq!(customer.additional_emails, empty_emails);

// Test updating additional_emails by ID
let customer = client
.update_customer(
&customer.id,
&UpdateCustomerRequest {
additional_emails: Some(vec![
"[email protected]",
"[email protected]",
]),
..Default::default()
},
)
.await
.unwrap();
assert!(customer
.additional_emails
.contains(&"[email protected]".to_string()));
assert!(customer
.additional_emails
.contains(&"[email protected]".to_string()));
let customer = client.get_customer(&customer.id).await.unwrap();
assert!(customer
.additional_emails
.contains(&"[email protected]".to_string()));
assert!(customer
.additional_emails
.contains(&"[email protected]".to_string()));
assert_eq!(customer.email, "[email protected]");

// Test updating the customer by external ID.
let customer = client
Expand Down

0 comments on commit 07b687e

Please sign in to comment.