Actix integration info

This commit is contained in:
eraden 2022-04-24 16:36:38 +02:00
parent 8e07c95eba
commit 58414f3fe2
6 changed files with 21 additions and 7 deletions

8
Cargo.lock generated
View File

@ -613,7 +613,7 @@ dependencies = [
"oauth2", "oauth2",
"parking_lot 0.12.0", "parking_lot 0.12.0",
"password-hash", "password-hash",
"pay_u 0.1.2", "pay_u 0.1.3",
"pretty_env_logger", "pretty_env_logger",
"rand_core", "rand_core",
"sendgrid", "sendgrid",
@ -2135,9 +2135,9 @@ checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
[[package]] [[package]]
name = "pay_u" name = "pay_u"
version = "0.1.2" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20aa37e1a7272d03e52e25dc66a9d5fb965f299123b415b7172256631d99a30a" checksum = "4eca87ee08eda0742042079ef48c3eb478a3f43dd535b499c88c72e532f6cfb6"
dependencies = [ dependencies = [
"chrono", "chrono",
"log", "log",
@ -2149,7 +2149,7 @@ dependencies = [
[[package]] [[package]]
name = "pay_u" name = "pay_u"
version = "0.1.3" version = "0.1.4"
dependencies = [ dependencies = [
"chrono", "chrono",
"dotenv", "dotenv",

View File

@ -65,4 +65,4 @@ jemallocator = { version = "0.3.2", features = [] }
sendgrid = { version = "0.17.4", features = ["async"] } sendgrid = { version = "0.17.4", features = ["async"] }
pay_u = { version = '0.1', features = ["single-client"] } pay_u = { version = '0.1.3', features = ["single-client"] }

View File

@ -15,6 +15,7 @@ impl PaymentManager {
ClientSecret: Into<String>, ClientSecret: Into<String>,
{ {
let mut client = pay_u::Client::new(client_id, client_secret, merchant_pos_id); let mut client = pay_u::Client::new(client_id, client_secret, merchant_pos_id);
client
Self { client } Self { client }
} }
} }

View File

@ -40,6 +40,7 @@ pub enum Error {
#[get("/")] #[get("/")]
async fn landing() -> HttpResponse { async fn landing() -> HttpResponse {
HttpResponse::SeeOther().append_header((actix_web::http::header::LOCATION, ""));
HttpResponse::NotImplemented().body("") HttpResponse::NotImplemented().body("")
} }

View File

@ -1,7 +1,7 @@
[package] [package]
name = "pay_u" name = "pay_u"
description = "PayU Rest API wrapper" description = "PayU Rest API wrapper"
version = "0.1.3" version = "0.1.4"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"

View File

@ -48,11 +48,23 @@ async fn usage() {
} }
``` ```
### Notification with Actix ### Actix integration
```rust ```rust
use actix_web::{*, web::*}; use actix_web::{*, web::*};
#[post("/checkout")]
async fn checkout(session: Data<Session>, db: Data<Database>, payu: Data<Arc<Mutex<pay_u::Client>>>) -> 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")] #[post("/pay_u/{own_order_id}/notify")]
async fn handle_notification(path: Path<i32>, Json(notify): Json<pay_u::notify::StatusUpdate>) -> HttpResponse { async fn handle_notification(path: Path<i32>, Json(notify): Json<pay_u::notify::StatusUpdate>) -> HttpResponse {
let status = notify.status(); let status = notify.status();