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",
"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",

View File

@ -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"] }

View File

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

View File

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

View File

@ -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"

View File

@ -48,11 +48,23 @@ async fn usage() {
}
```
### Notification with Actix
### Actix integration
```rust
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")]
async fn handle_notification(path: Path<i32>, Json(notify): Json<pay_u::notify::StatusUpdate>) -> HttpResponse {
let status = notify.status();