diff --git a/Cargo.lock b/Cargo.lock index ed48d89..cf8fac4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -613,7 +613,7 @@ dependencies = [ "oauth2", "parking_lot 0.12.0", "password-hash", - "pay_u 0.1.2", + "pay_u 0.1.3", "pretty_env_logger", "rand_core", "sendgrid", @@ -2135,9 +2135,9 @@ checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" [[package]] name = "pay_u" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20aa37e1a7272d03e52e25dc66a9d5fb965f299123b415b7172256631d99a30a" +checksum = "4eca87ee08eda0742042079ef48c3eb478a3f43dd535b499c88c72e532f6cfb6" dependencies = [ "chrono", "log", @@ -2149,7 +2149,7 @@ dependencies = [ [[package]] name = "pay_u" -version = "0.1.3" +version = "0.1.4" dependencies = [ "chrono", "dotenv", diff --git a/api/Cargo.toml b/api/Cargo.toml index d76f275..9d049b3 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -65,4 +65,4 @@ jemallocator = { version = "0.3.2", features = [] } sendgrid = { version = "0.17.4", features = ["async"] } -pay_u = { version = '0.1', features = ["single-client"] } +pay_u = { version = '0.1.3', features = ["single-client"] } diff --git a/api/src/actors/payment_manager.rs b/api/src/actors/payment_manager.rs index fe53476..426dd12 100644 --- a/api/src/actors/payment_manager.rs +++ b/api/src/actors/payment_manager.rs @@ -15,6 +15,7 @@ impl PaymentManager { ClientSecret: Into, { let mut client = pay_u::Client::new(client_id, client_secret, merchant_pos_id); + client Self { client } } } diff --git a/api/src/routes/public.rs b/api/src/routes/public.rs index 145364d..e843990 100644 --- a/api/src/routes/public.rs +++ b/api/src/routes/public.rs @@ -40,6 +40,7 @@ pub enum Error { #[get("/")] async fn landing() -> HttpResponse { + HttpResponse::SeeOther().append_header((actix_web::http::header::LOCATION, "")); HttpResponse::NotImplemented().body("") } diff --git a/pay_u/Cargo.toml b/pay_u/Cargo.toml index 828dc98..a977a26 100644 --- a/pay_u/Cargo.toml +++ b/pay_u/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pay_u" description = "PayU Rest API wrapper" -version = "0.1.3" +version = "0.1.4" edition = "2021" license = "MIT" diff --git a/pay_u/README.md b/pay_u/README.md index 3c73bc0..01723a0 100644 --- a/pay_u/README.md +++ b/pay_u/README.md @@ -48,11 +48,23 @@ async fn usage() { } ``` -### Notification with Actix +### Actix integration ```rust use actix_web::{*, web::*}; +#[post("/checkout")] +async fn checkout(session: Data, db: Data, payu: Data>>) -> HttpResponse { + let user_id = session.user_required()?; + let payu = payu.into_inner(); + let shopping_cart = db.send(LoadShoppingCart { user_id }).await??; + let shopping_cart_id = shopping_cart.id; + let create_order_req: pay_u::OrderCreateRequest = shopping_cart.into(); + let pay_u::CreateOrderResult { redirect_uri, order_id, .. } = payu.create_order(create_order_req).await?; + db.send(database::CreateOrder { shopping_cart_id, order_id }).await??; + HttpResponse::SeeOther().append_header((actix_web::http::header::LOCATION, redirect_uri)).body("") +} + #[post("/pay_u/{own_order_id}/notify")] async fn handle_notification(path: Path, Json(notify): Json) -> HttpResponse { let status = notify.status();