Crates.io | zarinpal |
lib.rs | zarinpal |
version | 0.1.2 |
source | src |
created_at | 2023-10-01 15:46:36.661306 |
updated_at | 2023-10-06 12:42:54.077048 |
description | Zarinpal Payment Gateway Api. |
homepage | |
repository | https://github.com/immmdreza/zarinpal |
max_upload_size | |
id | 989289 |
size | 60,356 |
This's a rust implementation of zarinpal payment gateway api client.
cargo add zarinpal
Here's how you can get started with the crate
use zarinpal::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Default merchant_id to be used in every request.
let zarinpal = Zarinpal::new("merchant_id")?;
Ok(())
}
// ~~~ sniff ~~~
let request = zarinpal
.request_payment(10000, "example.com".parse()?, "Test payment")
.build()
.await?;
// ~~~ sniff ~~~
let verified = zarinpal
.verify_payment(request.authority(), 10000)
.build()
.await?;
// ~~~ sniff ~~~
let request_2 = zarinpal
.request_payment(10000, "example.com".parse()?, "Test payment")
.metadata(
Metadata::builder()
.mobile("98912345678")
.email("test@example.com")
.build(),
)
.build()
.await?;
// ~~~ sniff ~~~
let request_3 = zarinpal
.request_payment(10000, "example.com".parse()?, "Test payment")
.currency(Currency::IRT) // Tomans
.build()
.await?;
// ~~~ sniff ~~~
let request_4 = zarinpal
.request_payment(10000, "example.com".parse()?, "Test payment")
.wages([
Wage::builder()
.iban("...")
.amount(5000)
.description("To my first friend")
.build(),
Wage::builder()
.iban("...")
.amount(5000)
.description("To my second friend")
.build(),
])
.build()
.await?;
Revert a list of 100 recent unverified payments.
// ~~~ sniff ~~~
let unverified_payments = zarinpal.unverified_requests().build().await?;
for unverified in unverified_payments.authorities() {
println!("{}", unverified.authority())
}
Happy making money 🔥