Skip to main content

pakasir_sdk/
lib.rs

1// Copyright 2026 H0llyW00dzZ
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Unofficial Rust SDK for the [Pakasir](https://pakasir.com) payment gateway.
16//!
17//! The crate covers the REST surface of the API plus a few helpers most
18//! integrations end up writing anyway:
19//!
20//! - [`Client`] – async HTTP client with retries, jittered backoff, and
21//!   `Retry-After` handling.
22//! - [`TransactionService`] – create / cancel / detail.
23//! - [`SimulationService`] – sandbox payment simulation.
24//! - [`WebhookParser`] – parse and validate webhook payloads.
25//! - [`build_payment_url`] – build the hosted checkout redirect URL.
26//! - [`QrGenerator`] – render QRIS strings (or anything else) to PNG bytes.
27//!
28//! Error messages are localized through [`Language`] (English by default,
29//! Indonesian when the client is configured for it).
30//!
31//! # Quick start
32//!
33//! ```no_run
34//! use pakasir_sdk::{Client, PaymentMethod, TransactionService};
35//! use pakasir_sdk::transaction::CreateRequest;
36//!
37//! # async fn run() -> Result<(), pakasir_sdk::Error> {
38//! let client = Client::builder("your-project-slug", "your-api-key").build();
39//! let transactions = TransactionService::new(client);
40//!
41//! let response = transactions
42//!     .create(
43//!         PaymentMethod::Qris,
44//!         &CreateRequest {
45//!             order_id: "INV123456".into(),
46//!             amount: 99_000,
47//!         },
48//!     )
49//!     .await?;
50//!
51//! println!("payment number: {}", response.payment.payment_number);
52//! println!("total payment:  {}", response.payment.total_payment);
53//! # Ok(())
54//! # }
55//! ```
56//!
57//! # Modules
58//!
59//! | Module          | What it does                                                  |
60//! |-----------------|---------------------------------------------------------------|
61//! | [`client`]      | HTTP transport, retry policy, builder.                        |
62//! | [`constants`]   | SDK metadata, API paths, payment / status enums.              |
63//! | [`error`]       | The crate-wide [`Error`] enum and [`Result`] alias.           |
64//! | [`i18n`]        | Language selector and message catalog.                        |
65//! | [`payment_url`] | Hosted checkout redirect URL builder.                         |
66//! | [`qr`]          | QR PNG generation.                                            |
67//! | [`simulation`]  | Sandbox payment simulation.                                   |
68//! | [`timefmt`]     | Small RFC 3339 parsing helper.                                |
69//! | [`transaction`] | Transaction service.                                          |
70//! | [`webhook`]     | Webhook parser and event validation.                          |
71//!
72//! The gRPC server layer from the original implementation is not part of
73//! this crate.
74
75pub mod client;
76pub mod constants;
77pub mod error;
78pub mod i18n;
79pub mod payment_url;
80#[cfg(feature = "qr")]
81pub mod qr;
82#[cfg(feature = "simulation")]
83pub mod simulation;
84pub mod timefmt;
85pub mod transaction;
86#[cfg(feature = "webhook")]
87pub mod webhook;
88
89pub use client::{Client, ClientBuilder};
90pub use constants::{
91    PaymentMethod, SDK_NAME, SDK_REPOSITORY, SDK_VERSION, TransactionStatus, user_agent,
92};
93pub use error::{Error, Result};
94pub use i18n::Language;
95pub use payment_url::{Options as PaymentUrlOptions, UrlBuildError, build as build_payment_url};
96#[cfg(feature = "qr")]
97pub use qr::{Options as QrOptions, QrError, QrGenerator, RecoveryLevel};
98#[cfg(feature = "simulation")]
99pub use simulation::SimulationService;
100pub use transaction::TransactionService;
101#[cfg(feature = "webhook")]
102pub use webhook::{Event as WebhookEvent, Parser as WebhookParser, WebhookError};