Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support additional_emails field on the Customer type #31

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>,
sjmiller609 marked this conversation as resolved.
Show resolved Hide resolved
/// 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
Loading