Allow to check creds, update docs
This commit is contained in:
parent
a7294249d3
commit
8e07c95eba
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -613,6 +613,7 @@ dependencies = [
|
||||
"oauth2",
|
||||
"parking_lot 0.12.0",
|
||||
"password-hash",
|
||||
"pay_u 0.1.2",
|
||||
"pretty_env_logger",
|
||||
"rand_core",
|
||||
"sendgrid",
|
||||
@ -2135,6 +2136,20 @@ checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
|
||||
[[package]]
|
||||
name = "pay_u"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20aa37e1a7272d03e52e25dc66a9d5fb965f299123b415b7172256631d99a30a"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"log",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pay_u"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dotenv",
|
||||
|
@ -64,3 +64,5 @@ async-trait = { version = "0.1.53", features = [] }
|
||||
jemallocator = { version = "0.3.2", features = [] }
|
||||
|
||||
sendgrid = { version = "0.17.4", features = ["async"] }
|
||||
|
||||
pay_u = { version = '0.1', features = ["single-client"] }
|
||||
|
@ -2,4 +2,5 @@ pub mod cart_manager;
|
||||
pub mod database;
|
||||
pub mod email_manager;
|
||||
pub mod order_manager;
|
||||
pub mod payment_manager;
|
||||
pub mod token_manager;
|
||||
|
20
api/src/actors/payment_manager.rs
Normal file
20
api/src/actors/payment_manager.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use pay_u::MerchantPosId;
|
||||
|
||||
pub struct PaymentManager {
|
||||
client: pay_u::Client,
|
||||
}
|
||||
|
||||
impl PaymentManager {
|
||||
pub fn new<ClientId, ClientSecret>(
|
||||
client_id: ClientId,
|
||||
client_secret: ClientSecret,
|
||||
merchant_pos_id: MerchantPosId,
|
||||
) -> Self
|
||||
where
|
||||
ClientId: Into<String>,
|
||||
ClientSecret: Into<String>,
|
||||
{
|
||||
let mut client = pay_u::Client::new(client_id, client_secret, merchant_pos_id);
|
||||
Self { client }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "pay_u"
|
||||
description = "PayU Rest API wrapper"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
||||
|
@ -14,6 +14,7 @@ async fn usage() {
|
||||
let client_secret = std::env::var("PAYU_CLIENT_SECRET").unwrap();
|
||||
let merchant_id = std::env::var("PAYU_CLIENT_MERCHANT_ID").unwrap().parse().unwrap();
|
||||
let mut client = Client::new(client_id, client_secret, merchant_id);
|
||||
client.authorize().await.expect("Invalid credentials");
|
||||
|
||||
let _res = client.create_order(
|
||||
OrderCreateRequest::new(
|
||||
@ -47,6 +48,26 @@ async fn usage() {
|
||||
}
|
||||
```
|
||||
|
||||
### Notification with Actix
|
||||
|
||||
```rust
|
||||
use actix_web::{*, web::*};
|
||||
|
||||
#[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();
|
||||
let order_id = path.into_inner();
|
||||
match handle_update(order_id, status, notify) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
// ALWAYS SEND OK!
|
||||
log::error!("{e:?}");
|
||||
}
|
||||
};
|
||||
HttpResponse::Ok().body("")
|
||||
}
|
||||
```
|
||||
|
||||
## Bugs
|
||||
|
||||
Please report bugs here: https://todo.sr.ht/~tsumanu/payu-rs
|
||||
|
@ -853,7 +853,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Get or refresh token
|
||||
pub(crate) async fn authorize(&mut self) -> Result<bool> {
|
||||
pub async fn authorize(&mut self) -> Result<bool> {
|
||||
use chrono::{Duration, Utc};
|
||||
if Utc::now() - Duration::seconds(1) < self.bearer_expires_at {
|
||||
return Ok(true);
|
||||
|
Loading…
Reference in New Issue
Block a user