|
1
|
//! Plan, cloud entitlement, and the hosted checkout / portal links. |
|
2
|
|
|
3
|
use crate::{ |
|
4
|
client::Client, |
|
5
|
error::Result, |
|
6
|
models::{Billing, BillingUrl}, |
|
7
|
}; |
|
8
|
|
|
9
|
impl Client { |
|
10
|
/// `GET /api/v1/billing` |
|
11
|
pub async fn billing(&self) -> Result<Billing> { |
|
12
|
self.get("billing").await |
|
13
|
} |
|
14
|
|
|
15
|
/// `POST /api/v1/billing/checkout` — a Stripe Checkout URL to open in a |
|
16
|
/// browser. Purchases deliberately happen on the web, never in the client. |
|
17
|
pub async fn billing_checkout(&self, plan: &str) -> Result<String> { |
|
18
|
let body = serde_json::json!({ "plan": plan }); |
|
19
|
let response: BillingUrl = self.post("billing/checkout", &body).await?; |
|
20
|
Ok(response.url) |
|
21
|
} |
|
22
|
|
|
23
|
/// `POST /api/v1/billing/portal` — the Stripe customer portal URL. |
|
24
|
pub async fn billing_portal(&self) -> Result<String> { |
|
25
|
let response: BillingUrl = self.post("billing/portal", &serde_json::json!({})).await?; |
|
26
|
Ok(response.url) |
|
27
|
} |
|
28
|
} |