1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! # Midtransclient for Rust
//!
//! Unofficial Rust API client/library for Midtrans Payment API
//!
//! ## Usage
//!
//! Midtrans have [2 different products](https://docs.midtrans.com/en/welcome/index.html) (Snap & Core API) of payment that you can use:
//!
//! - [Snap](#22A-snap) - Customizable payment popup will appear on **your web/app** (no redirection). [doc ref](https://snap-docs.midtrans.com/)
//! - [Snap Redirect](#22B-snap-redirect) - Customer need to be redirected to payment url **hosted by midtrans**. [doc ref](https://snap-docs.midtrans.com/)
//! - [Core API (VT-Direct)](#22C-core-api-vt-direct) - Basic backend implementation, you can customize the frontend embedded on **your web/app** as you like (no redirection). [doc ref](https://api-docs.midtrans.com/)
//!
//! Choose one that you think best for your unique needs.
//!
//! ## Examples
//!
//! ### Core API Simple Charge
//!
//! ```no_run
//! use std::env;
//! use midtransclient::{MidtransError, CoreApi};
//! use serde_json::json;
//!
//! fn main() -> Result<(), MidtransError> {
//! // Get MIDTRANS_SERVER_KEY and MIDTRANS_CLIENT_KEY from environment variables
//! // or you just can type it directly
//! // You can find it in Merchant Portal -> Settings -> Access keys
//! let server_key = env::var("MIDTRANS_SERVER_KEY").expect("SERVER_KEY NOT FOUND");
//! let client_key = env::var("MIDTRANS_CLIENT_KEY").expect("CLIENT_KEY NOT FOUND");
//!
//! // Create Core API instance
//! let core = CoreApi::new(false, server_key)
//! .client_key(client_key)
//! .build()?;
//!
//! // Prepare CORE API parameter
//! // ( refer to: https://docs.midtrans.com/en/core-api/bank-transfer?id=sample-request-and-request-body )
//! // charge bank_transfer parameter example
//! let parameters = json!({
//! "payment_type": "bank_transfer",
//! "transaction_details": {
//! "gross_amount": 24145,
//! "order_id": "test-transaction-321"
//! },
//! "bank_transfer": {
//! "bank": "bni"
//! }
//! }).to_string();
//!
//! // charge transaction
//! let charge_response = core.charge(¶meters)?;
//! println!("Charge Response: {:#?}", charge_response);
//!
//! // Charge Response: {
//! // "transaction_status": String("pending"),
//! // "va_numbers": Array [Object {
//! // "bank": String("bca"),
//! // "va_number": String("28276362079")
//! // }],
//! // "transaction_time": String("2022-11-18 21:01:24"),
//! // "status_message": String("Success, Bank Transfer transaction is created"),
//! // "fraud_status": String("accept"),
//! // "merchant_id": String("G738628276"),
//! // "transaction_id": String("73ebe57c-ffb0-42a6-93fa-c5022a7f316e"),
//! // "status_code": String("201"),
//! // "order_id": String("test-transaction-321"),
//! // "currency": String("IDR"),
//! // "payment_type": String("bank_transfer"),
//! // "gross_amount": String("24145.00")
//! // }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Snap Simple
//!
//! ```no_run
//! use std::env;
//! use midtransclient::{MidtransError, Snap};
//! use serde_json::json;
//!
//! fn main() -> Result<(), MidtransError> {
//! // Get MIDTRANS_SERVER_KEY and MIDTRANS_CLIENT_KEY from environment variables
//! // or you just can type it directly
//! // You can find it in Merchant Portal -> Settings -> Access keys
//! let server_key = env::var("MIDTRANS_SERVER_KEY").expect("SERVER_KEY NOT FOUND");
//! let client_key = env::var("MIDTRANS_CLIENT_KEY").expect("CLIENT_KEY NOT FOUND");
//!
//! // Create Core API instance
//! let snap = Snap::new(false, server_key)
//! .client_key(client_key)
//! .build()?;
//!
//! // Prepare SNAP API parameter ( refer to: https://snap-docs.midtrans.com )
//! // this is full parameter including optionals parameter.
//! let parameters = json!({
//! "transaction_details": {
//! "order_id": "test-transaction-123",
//! "gross_amount": 200000
//! }, "credit_card":{
//! "secure" : true
//! }
//! }).to_string();
//!
//! let transaction = snap.create_transaction(¶meters)?;
//! println!("Create Transaction Response: {:#?}", transaction);
//!
//! // Create Transaction Response: {
//! // "redirect_url": String("https://app.sandbox.midtrans.com/snap/v3/redirection/1115ee78-9e17-4089-9992-a6f39e355fa7"),
//! // "token": String("1115ee78-9e17-4089-9992-a6f39e355fa7"),
//! // "status_code": String("201"),
//! // }
//!
//! Ok(())
//! }
//! ```
pub use ApiConfig;
pub use CoreApi;
pub use Snap;
pub use MidtransClient;
pub use MidtransError;
pub use Transactions;