checkout-redesign │ ~/src/tally review · working tree at 87e0e5c │ 3 files · +36 −27
Files 3 │ crates/api/src/checkout.rs +7 −2 ─────────────────────────────────────────────────────────
│
crates/api/src/ │ ⋯ use crate::{AppState, Error}; ───────────────────────────────────────────────────────
checkout.rs +7 −2 │ 6 #[derive(Deserialize)]
│ 7 pub struct CheckoutRequest {
web/src/checkout/ │ 8 pub invoice_id: i64,
CheckoutPage.tsx +20 −16 │ 9 - pub card_token: String,
messages.ts +9 −9 │ 9 + pub card_token: Option<String>,
│ 10 + pub saved_card_id: Option<i64>,
│ 11 }
│ 12
│ 13 #[derive(Serialize)]
│
│ ⋯ pub async fn checkout( ──────────────────────────────────────────────────────────────
│ 21 Json(request): Json<CheckoutRequest>,
│ 22 ) -> Result<Json<CheckoutResponse>, Error> {
│ 23 let invoice = state.invoices.get(request.invoice_id).await?;
│ 24 + let card = match request.saved_card_id {
│ 25 + Some(id) => state.cards.for_client(invoice.client_id, id).await?.token,
│▌ 26 + None => request.card_token.ok_or(Error::MissingCard)?,
│ ▎ a comment for the agent on this line
│ 27 + };
│ 28 let payment = state
│ 29 .payments
│ 25 - .charge(&request.card_token, invoice.total_cents, &invoice.currency)
│ 30 + .charge(&card, invoice.total_cents, &invoice.currency)
│ 31 .await?;
│ 32 Ok(Json(CheckoutResponse {
│ 33 payment_id: payment.id,
│
│
│ web/src/checkout/CheckoutPage.tsx +20 −16 ────────────────────────────────────────────────
enter save ctrl+j newline esc cancel