main
|
Last change
on this file since 3d81505 was a4ca79c, checked in by Georgi Paunkov <paunkovgeorgi@…>, 5 days ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
897 bytes
|
| Line | |
|---|
| 1 | use sqlx::PgPool;
|
|---|
| 2 | use tauri::State;
|
|---|
| 3 | use crate::commands::auth::ActiveSessions;
|
|---|
| 4 |
|
|---|
| 5 | #[tauri::command]
|
|---|
| 6 | pub async fn create_payment(
|
|---|
| 7 | token: String,
|
|---|
| 8 | order_id: i32,
|
|---|
| 9 | amount: rust_decimal::Decimal,
|
|---|
| 10 | method: String,
|
|---|
| 11 | pool: State<'_, PgPool>,
|
|---|
| 12 | sessions: State<'_, ActiveSessions>,
|
|---|
| 13 | ) -> Result<(), String> {
|
|---|
| 14 | {
|
|---|
| 15 | let lock = sessions.0.lock().map_err(|_| "Системска грешка".to_string())?;
|
|---|
| 16 | if !lock.contains_key(&token) {
|
|---|
| 17 | return Err("Критична грешка: Неовластена наплата без сесија!".to_string());
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | sqlx::query(
|
|---|
| 22 | "
|
|---|
| 23 | INSERT INTO payment (order_id, amount, method)
|
|---|
| 24 | VALUES ($1, $2, $3)
|
|---|
| 25 | "
|
|---|
| 26 | )
|
|---|
| 27 | .bind(order_id)
|
|---|
| 28 | .bind(amount)
|
|---|
| 29 | .bind(method)
|
|---|
| 30 | .execute(pool.inner())
|
|---|
| 31 | .await
|
|---|
| 32 | .map_err(|e| e.to_string())?;
|
|---|
| 33 |
|
|---|
| 34 | Ok(())
|
|---|
| 35 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.