Extract pay_u

This commit is contained in:
eraden 2022-04-29 20:37:41 +02:00
parent d4a497a3f2
commit 7ff5df7319
6 changed files with 36 additions and 197 deletions

69
Cargo.lock generated
View File

@ -488,9 +488,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.56"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
[[package]]
name = "argon2"
@ -566,9 +566,9 @@ dependencies = [
[[package]]
name = "base-x"
version = "0.2.8"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74"
[[package]]
name = "base64"
@ -790,7 +790,7 @@ dependencies = [
"num-integer",
"num-traits",
"serde",
"time 0.1.44",
"time 0.1.43",
"winapi",
]
@ -1296,7 +1296,7 @@ dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"wasi 0.10.2+wasi-snapshot-preview1",
"wasm-bindgen",
]
@ -1448,9 +1448,9 @@ dependencies = [
[[package]]
name = "http"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03"
checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb"
dependencies = [
"bytes",
"fnv",
@ -1476,9 +1476,9 @@ checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "httparse"
version = "1.7.0"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6330e8a36bd8c859f3fa6d9382911fbb7147ec39807f63b923933a247240b9ba"
checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c"
[[package]]
name = "httpdate"
@ -1694,9 +1694,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.123"
version = "0.2.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb691a747a7ab48abc15c5b42066eaafde10dc427e3b6ee2a1cf43db04c763bd"
checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
[[package]]
name = "libgit2-sys"
@ -1712,9 +1712,9 @@ dependencies = [
[[package]]
name = "libz-sys"
version = "1.1.5"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f35facd4a5673cb5a48822be2be1d4236c1c99cb4113cab7061ac720d5bf859"
checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e"
dependencies = [
"cc",
"libc",
@ -2118,9 +2118,9 @@ dependencies = [
[[package]]
name = "password-hash"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa26fd5c3cd6e6bb83dd9c0cef40fbeb77d7596339ca46c18a6f66919bb07769"
checksum = "e029e94abc8fb0065241c308f1ac6bc8d20f450e8f7c5f0b25cd9b8d526ba294"
dependencies = [
"base64ct",
"rand_core",
@ -2136,16 +2136,16 @@ checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
[[package]]
name = "pay_u"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4610a8df1fb636e9b9869a4faa7f0a981e40e2c83560e4d25e5c449ca6e37174"
dependencies = [
"chrono",
"derive_more",
"dotenv",
"log",
"reqwest",
"serde",
"serde_json",
"thiserror",
"tokio",
]
[[package]]
@ -2258,9 +2258,9 @@ dependencies = [
[[package]]
name = "pin-project-lite"
version = "0.2.8"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "pin-utils"
@ -3033,9 +3033,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.91"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d"
checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52"
dependencies = [
"proc-macro2",
"quote",
@ -3118,12 +3118,11 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.44"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
@ -3185,9 +3184,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.5.1"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
dependencies = [
"tinyvec_macros",
]
@ -3200,9 +3199,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.17.0"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
checksum = "0f48b6d60512a392e34dbf7fd456249fd2de3c83669ab642e021903f4015185b"
dependencies = [
"bytes",
"libc",
@ -3330,9 +3329,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.20"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b"
checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c"
dependencies = [
"proc-macro2",
"quote",
@ -3452,9 +3451,9 @@ dependencies = [
[[package]]
name = "unicode-bidi"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f"
checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]]
name = "unicode-normalization"
@ -3582,9 +3581,9 @@ dependencies = [
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasi"

View File

@ -1,2 +1,2 @@
[workspace]
members = ["api","pay_u"]
members = ["api"]

View File

@ -65,7 +65,4 @@ jemallocator = { version = "0.3.2", features = [] }
sendgrid = { version = "0.17.4", features = ["async"] }
pay_u = { path = "../pay_u", version = '0.1', features = ["single-client"] }
[dev-dependencies]
pay_u = { path = "../pay_u", version = "0.1", features = ["single-client"] }
pay_u = { version = '0.1', features = ["single-client"] }

View File

@ -1,28 +0,0 @@
[package]
name = "pay_u"
description = "PayU Rest API wrapper"
version = "0.1.8"
edition = "2021"
license = "MIT"
[features]
single-client = []
default = ['single-client']
[dependencies]
reqwest = { version = "0.11.10", features = ["default", "native-tls", "json"] }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = { version = "1.0.79" }
chrono = { version = "0.4.19", features = ["serde"] }
thiserror = { version = "1.0.30" }
log = { version = "0.4.16" }
derive_more = { version = "0.99.17" }
[dev-dependencies]
tokio = { version = "1.17.0", features = ["full"] }
dotenv = { version = "0.15.0" }

View File

@ -1,10 +0,0 @@
MIT License
Copyright (c) 2022 Adrian Woźniak
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,119 +0,0 @@
# Unofficial Payu client
<img src="https://poland.payu.com/wp-content/themes/global-website/assets/src/images/payu-logo.svg">
This client support integration with the REST API 2.1 protocol.
It presents various methods of implementing online payments via different PayU services and is dedicated primarily to developers wanting to implement the PayU payment services.
## Install
```bash
cargo add pay_u
```
## Usage
```rust
async fn usage() {
use pay_u::*;
let client_id = ClientId::new(std::env::var("PAYU_CLIENT_ID").unwrap());
let client_secret = ClientSecret::new(std::env::var("PAYU_CLIENT_SECRET").unwrap());
let merchant_id = std::env::var("PAYU_CLIENT_MERCHANT_ID").unwrap().parse::<i32>().map(MerchantPosId::from).unwrap();
let mut client = Client::new(client_id, client_secret, merchant_id);
client.authorize().await.expect("Invalid credentials");
let _res = client.create_order(
req::OrderCreate::build(
Buyer::new("john.doe@example.com", "654111654", "John", "Doe", "pl"),
"127.0.0.1",
"PLN",
"Some description"
)
.expect("All required fields must be valid")
// Endpoint which will be requested by PayU with payment status update
.with_notify_url("https://your.eshop.com/notify")
// payment description (MANDATORY)
.with_description("RTV market")
// add list of products
.with_products(
[
Product::new("Wireless Mouse for Laptop", 15000, 1),
Product::new("HDMI cable", 6000, 1),
]
.into_iter(),
)
// add additional product
.with_product(Product::new("HDMI cable", 6000, 1)),
)
.await;
// partial refund
let _res = client
.refund(
OrderId::new("H9LL64F37H160126GUEST000P01"),
RefundRequest::new("Refund", Some(1000)),
)
.await;
// Full refund
let _res = client
.refund(
OrderId::new("H9LL64F37H160126GUEST000P01"),
RefundRequest::new("Refund", None),
)
.await;
// Order details
let _res = client.order_details(OrderId::new("H9LL64F37H160126GUEST000P01")).await;
// Transactions
let _res = client.order_transactions(OrderId::new("H9LL64F37H160126GUEST000P01")).await;
}
```
### 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::req::OrderCreate = shopping_cart.into();
let pay_u::res::CreateOrder { 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>,
payment: Data<Addr<PaymentManager>>
) -> HttpResponse {
let status = notify.status();
// Create additional field which will always be unique like UUID
// Do not use record primary key!
let ext_order_id = String::from(notify.ext_order_id());
let order_id = path.into_inner();
payment.do_send(payment_manager::Update {
status,
ext_order_id
});
HttpResponse::Ok().body("")
}
```
### Releases
0.1.8 - Additional documentation, move requests to module
0.1.7 - Added credit and more create order request options like additional description, visible description.
## Bugs
Please report bugs here: https://todo.sr.ht/~tsumanu/payu-rs