Skip to content

Commit

Permalink
Merge pull request #541 from belyakov-am/feat/checkout-session-retrie…
Browse files Browse the repository at this point in the history
…ve-line-items

Add `retrieve_line_items` function for `CheckoutSession`
  • Loading branch information
arlyon committed Apr 30, 2024
2 parents 031353a + 5c74b3b commit 2a6a974
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/resources/checkout_session_ext.rs
Expand Up @@ -2,6 +2,31 @@ use crate::client::{Client, Response};
use crate::ids::CheckoutSessionId;
use crate::params::Expand;
use crate::resources::CheckoutSession;
use crate::{CheckoutSessionItem, List};

/// The parameters for `CheckoutSession::retrieve_line_items`.
#[derive(Clone, Debug, serde::Serialize, Default)]
pub struct RetrieveCheckoutSessionLineItems {
/// A cursor for use in pagination.
///
/// `ending_before` is an object ID that defines your place in the list.
/// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<CheckoutSessionId>,

/// A limit on the number of objects to be returned.
///
/// Limit can range between 1 and 100, and the default is 10.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,

/// A cursor for use in pagination.
///
/// `starting_after` is an object ID that defines your place in the list.
/// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<CheckoutSessionId>,
}

impl CheckoutSession {
/// Retrieves a Session object.
Expand All @@ -21,4 +46,15 @@ impl CheckoutSession {
pub fn expire(client: &Client, id: &CheckoutSessionId) -> Response<CheckoutSession> {
client.post(&format!("/checkout/sessions/{}/expire", id))
}

/// Retrieves a Checkout Session's line items
///
/// For more details see <https://docs.stripe.com/api/checkout/sessions/line_items>
pub fn retrieve_line_items(
client: &Client,
id: &CheckoutSessionId,
params: &RetrieveCheckoutSessionLineItems,
) -> Response<List<CheckoutSessionItem>> {
client.get_query(&format!("/checkout/sessions/{}/line_items", id), &params)
}
}

0 comments on commit 2a6a974

Please sign in to comment.