Skip to content

Commit

Permalink
Merge pull request #33 from morukele/terminal
Browse files Browse the repository at this point in the history
changed all &str to String
  • Loading branch information
morukele authored Oct 31, 2023
2 parents a94d333 + 218af6b commit 23ccf7c
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 104 deletions.
4 changes: 2 additions & 2 deletions examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() {
let client = PaystackClient::new(&api_key);

let body = InitializeTransactionBodyBuilder::default()
.amount("10000")
.email("email@example.com")
.amount("10000".to_string())
.email("email@example.com".to_string())
.currency(Some(Currency::NGN))
.channels(Some(vec![
Channel::ApplePay,
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/subaccounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'a> SubaccountEndpoints<'a> {
/// - body: subaccount to create.
pub async fn create_subaccount(
&self,
body: CreateSubaccountBody<'a>,
body: CreateSubaccountBody,
) -> PaystackResult<CreateSubaccountResponse> {
let url = format!("{}/subaccount", BASE_URL);

Expand Down Expand Up @@ -124,7 +124,7 @@ impl<'a> SubaccountEndpoints<'a> {
pub async fn update_subaccount(
&self,
id_or_code: &str,
body: CreateSubaccountBody<'a>,
body: CreateSubaccountBody,
) -> PaystackResult<CreateSubaccountResponse> {
let url = format!("{}/subaccount/{}", BASE_URL, id_or_code);

Expand Down
5 changes: 5 additions & 0 deletions src/endpoints/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! ========
//! The Terminal API allows you to build delightful in-person payment experiences.

use crate::SendEventBody;

/// A Struct to hold all the functions of the terminal API route
#[derive(Debug, Clone)]
pub struct TerminalEndpoints<'a> {
Expand All @@ -15,4 +17,7 @@ impl<'a> TerminalEndpoints<'a> {
pub fn new(key: &'a str) -> TerminalEndpoints<'a> {
TerminalEndpoints { api_key: key }
}

/// Send an event from your application to the Paystack Terminal
pub async fn send_event(terminal_id: &str, event_body: SendEventBody) {}
}
4 changes: 2 additions & 2 deletions src/endpoints/transaction_splits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> TransactionSplitEndpoints<'a> {
/// This method takes a TransactionSplit object as a parameter.
pub async fn create_transaction_split(
&self,
split_body: CreateTransactionSplitBody<'a>,
split_body: CreateTransactionSplitBody,
) -> PaystackResult<TransactionSplitResponse> {
let url = format!("{}/split", BASE_URL);

Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'a> TransactionSplitEndpoints<'a> {
pub async fn update_transaction_split(
&self,
split_id: &str,
body: UpdateTransactionSplitBody<'a>,
body: UpdateTransactionSplitBody,
) -> PaystackResult<TransactionSplitResponse> {
let url = format!("{}/split/{}", BASE_URL, split_id);

Expand Down
6 changes: 3 additions & 3 deletions src/endpoints/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> TransactionEndpoints<'a> {
/// It takes a Transaction type as its parameter
pub async fn initialize_transaction(
&self,
transaction_body: InitializeTransactionBody<'a>,
transaction_body: InitializeTransactionBody,
) -> PaystackResult<TransactionResponse> {
let url = format!("{}/transaction/initialize", BASE_URL);

Expand Down Expand Up @@ -135,7 +135,7 @@ impl<'a> TransactionEndpoints<'a> {
/// This function takes a Charge Struct as parameter
pub async fn charge_authorization(
&self,
charge: ChargeBody<'a>,
charge: ChargeBody,
) -> PaystackResult<TransactionStatusResponse> {
let url = format!("{}/transaction/charge_authorization", BASE_URL);

Expand Down Expand Up @@ -268,7 +268,7 @@ impl<'a> TransactionEndpoints<'a> {
/// NB: it must be created with the PartialDebitTransaction Builder.
pub async fn partial_debit(
&self,
transaction_body: PartialDebitTransactionBody<'a>,
transaction_body: PartialDebitTransactionBody,
) -> PaystackResult<TransactionStatusResponse> {
let url = format!("{}/transaction/partial_debit", BASE_URL);

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
//! let client = PaystackClient::new(&api_key);
//!
//! let body = InitializeTransactionBodyBuilder::default()
//! .amount("10000")
//! .email("email@example.com")
//! .amount("10000".to_string())
//! .email("email@example.com".to_string())
//! .currency(Some(Currency::NGN))
//! .channels(Some(vec![
//! Channel::ApplePay,
Expand Down
16 changes: 8 additions & 8 deletions src/models/charge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ use serde::Serialize;
/// This struct is used to create a charge body for creating a Charge Authorization using the Paystack API.
/// The struct is constructed using the `ChargeBodyBuilder`
#[derive(Serialize, Debug, Builder)]
pub struct ChargeBody<'a> {
pub struct ChargeBody {
/// Customer's email address
email: &'a str,
email: String,
/// Amount should be in the smallest unit of the currency e.g. kobo if in NGN and cents if in USD
amount: &'a str,
amount: String,
/// Valid authorization code to charge
authorization_code: &'a str,
authorization_code: String,
/// Unique transaction reference. Only `-`, `.`, `=` and alphanumeric characters allowed.
#[builder(default = "None")]
reference: Option<&'a str>,
reference: Option<String>,
/// Currency in which amount should be charged.
#[builder(default = "None")]
currency: Option<Currency>,
Expand All @@ -28,21 +28,21 @@ pub struct ChargeBody<'a> {
/// when displayed on the dashboard.
/// Sample: {"custom_fields":[{"display_name":"Cart ID","variable_name": "cart_id","value": "8393"}]}
#[builder(default = "None")]
metadata: Option<&'a str>,
metadata: Option<String>,
/// Send us 'card' or 'bank' or 'card','bank' as an array to specify what options to show the user paying
#[builder(default = "None")]
channel: Option<Vec<Channel>>,
/// The code for the subaccount that owns the payment. e.g. `ACCT_8f4s1eq7ml6rlzj`
#[builder(default = "None")]
subaccount: Option<&'a str>,
subaccount: Option<String>,
/// A flat fee to charge the subaccount for this transaction in the subunit of the supported currency.
/// This overrides the split percentage set when the subaccount was created.
/// Ideally, you will need to use this if you are splitting in flat rates (since subaccount creation only allows for percentage split).
#[builder(default = "None")]
transaction_charge: Option<u32>,
/// Who bears Paystack charges? account or subaccount (defaults to account).
#[builder(default = "None")]
bearer: Option<&'a str>,
bearer: Option<String>,
/// If you are making a scheduled charge call, it is a good idea to queue them so the processing system does not
/// get overloaded causing transaction processing errors.
/// Send queue:true to take advantage of our queued charging.
Expand Down
2 changes: 1 addition & 1 deletion src/models/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::fmt;
/// ```
///
/// The example demonstrates the usage of the `Currency` enum from the Paystack crate,
/// creating instances of each variant and printing their debug representation.
/// creating instances of each variant and printing a debug representation.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub enum Currency {
/// Nigerian Naira
Expand Down
2 changes: 2 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod generic;
pub mod split;
pub mod status;
pub mod subaccounts;
pub mod terminal;
pub mod transaction_split;
pub mod transactions;

Expand All @@ -20,5 +21,6 @@ pub use generic::*;
pub use split::*;
pub use status::*;
pub use subaccounts::*;
pub use terminal::*;
pub use transaction_split::*;
pub use transactions::*;
18 changes: 9 additions & 9 deletions src/models/subaccounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ use serde::{Deserialize, Serialize};

/// This struct is used to create the body for creating a subaccount on your integration.
#[derive(Serialize, Debug, Builder, Default)]
pub struct CreateSubaccountBody<'a> {
pub struct CreateSubaccountBody {
/// Name of business for subaccount
business_name: &'a str,
business_name: String,
/// Bank Code for the bank.
/// You can get the list of Bank Codes by calling the List Banks endpoint.
settlement_bank: &'a str,
settlement_bank: String,
/// Bank Account Number
account_number: &'a str,
account_number: String,
/// The default percentage charged when receiving on behalf of this subaccount
percentage_charge: f32,
/// A description for this subaccount
description: &'a str,
description: String,
/// A contact email for the subaccount
#[builder(default = "None")]
primary_contact_email: Option<&'a str>,
primary_contact_email: Option<String>,
/// A name for the contact person for this subaccount
#[builder(default = "None")]
primary_contact_name: Option<&'a str>,
primary_contact_name: Option<String>,
/// A phone number to call for this subaccount
#[builder(default = "None")]
primary_contact_phone: Option<&'a str>,
primary_contact_phone: Option<String>,
/// Stringified JSON object.
/// Add a custom_fields attribute which has an array of objects if you would like the fields to be
/// added to your transaction when displayed on the dashboard.
/// Sample: {"custom_fields":[{"display_name":"Cart ID","variable_name": "cart_id","value": "8393"}]}
#[builder(default = "None")]
metadata: Option<&'a str>,
metadata: Option<String>,
}

/// This struct represents the subaccount.
Expand Down
87 changes: 87 additions & 0 deletions src/models/terminal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//! Terminal Models
//! ====================
//! This file contains the models and enums for working with the terminal endpoint.

use serde::{Deserialize, Serialize};
use std::fmt;

// This struct is used to create an event body for sending an event to the paystack Terminal using the Paystack API.
/// This struct should be created using the `SendEventBodyBuilder`
/// The Builder derivation allows for the automatic implementation of the builder
#[derive(Deserialize, Serialize)]
pub struct SendEventBody {
event_type: EventType,
action: ActionType,
data: EventData,
}

///
#[derive(Deserialize, Serialize)]
pub struct EventData {
id: String,
reference: Option<String>,
}

///
#[derive(Deserialize, Serialize)]
pub enum ActionType {
///
Process,
///
View,
///
Print,
}

impl fmt::Display for ActionType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let action = match self {
ActionType::Process => "process",
ActionType::View => "view",
ActionType::Print => "print",
};
write!(f, "{}", action)
}
}

/// Represents the different terminal event types supported by the Paystack API.
///
/// The `EventType` enum defines the possible even types that can be sent to Paystack Terminal.
/// The paystack API currently supports `Invoice` and `Transaction`. This list will be periodically updated as the API evolves. Feel free to open a PR if you catch the change before us.
///
/// # Variants
///
/// - `Invoice`: Invoice event.
/// - `Transaction`: Transaction event.
///
/// # Examples
///
/// ```
/// use paystack::EventType;
///
/// let invoice_event = EventType::Invoice;
/// let terminal_event = EventType::Transaction;
///
/// println!("{:?}", invoice_event); // Prints: invoice
/// ```
/// The example demonstrates the usage of the `EventType` enum from the Paystack crate, creating instances of each variant and printing a debug representation.
///
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[non_exhaustive]
pub enum EventType {
/// Invoice event
#[default]
Invoice,
/// Transaction event
Transaction,
}

impl fmt::Display for EventType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let terminal_type = match self {
EventType::Invoice => "invoice",
EventType::Transaction => "transaction",
};
write!(f, "{}", terminal_type)
}
}
10 changes: 5 additions & 5 deletions src/models/transaction_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use serde::Serialize;
/// This struct is used to create a split payment on your integration.
/// The struct is constructed using the `CreateTransactionSplitBodyBuilder`
#[derive(Serialize, Debug, Default, Builder)]
pub struct CreateTransactionSplitBody<'a> {
pub struct CreateTransactionSplitBody {
/// Name of the transaction split
name: &'a str,
name: String,
/// The type of transaction split you want to create
#[serde(rename = "type")]
split_type: SplitType,
Expand All @@ -21,15 +21,15 @@ pub struct CreateTransactionSplitBody<'a> {
/// Any of subaccount
bearer_type: BearerType,
/// Subaccount code
bearer_subaccount: &'a str,
bearer_subaccount: String,
}

/// This struct is used to update a transaction split details on your integration.
/// The struct is constructed using the `UpdateTransactionSplitBodyBuilder`
#[derive(Serialize, Debug, Builder, Default)]
pub struct UpdateTransactionSplitBody<'a> {
pub struct UpdateTransactionSplitBody {
/// Name of the transaction split
name: &'a str,
name: String,
/// True or False
active: bool,
/// Any of subaccount
Expand Down
Loading

0 comments on commit 23ccf7c

Please sign in to comment.