-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cf984ae
Showing
13 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Rust | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Rust Cache | ||
uses: Swatinem/rust-cache@v2.2.1 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
/.vscode | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "multisafepay-rust-sdk" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Rick Arendsen"] | ||
readme = "README.md" | ||
repository = "https://github.com/rikkertthedeveloper/multisafepay-rust-sdk" | ||
keywords = ["multisafepay", "ecommerce"] | ||
|
||
[dependencies] | ||
minreq = { version = "2.8.0", features = ["https"] } | ||
|
||
[dev-dependencies] | ||
pretty_assertions = "1" | ||
|
||
[profile.release] | ||
panic = "unwind" | ||
opt-level = 3 | ||
|
||
[profile.production] | ||
inherits = "release" | ||
lto = true | ||
codegen-units = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<p align="center"> | ||
<img src="https://camo.githubusercontent.com/517483ae0eaba9884f397e9af1c4adc7bbc231575ac66cc54292e00400edcd10/68747470733a2f2f7777772e6d756c7469736166657061792e636f6d2f66696c6561646d696e2f74656d706c6174652f696d672f6d756c7469736166657061792d6c6f676f2d69636f6e2e737667" width="400px" position="center"> | ||
</p> | ||
|
||
<h1 align="center"> | ||
<b> | ||
<span style="color: #009fff">Rust Software</span> | ||
<span style="color: #00005a">Development Kit</span> | ||
</b> | ||
</h1> | ||
|
||
## Introduction to MultiSafePay | ||
MultiSafepay is a Dutch payment services provider, which takes care of contracts, processing transactions, and collecting payment for a range of local and international payment methods. Start selling online today and manage all your transactions in one place! | ||
|
||
## Installation | ||
The MultiSafePay Rust SDK makes use of the "Cargo" toolchain included within rust itself, in order to locally build the library. Run the `cargo build --release` command in your terminal. | ||
|
||
## Tests | ||
The tests within this project can be ran with the `cargo test` command. This project has built-in tests for all classes associated with the libary. | ||
|
||
### Offline testing | ||
This library makes use of mockup data sites such as **DummyJSON** in order to test it's internal parsing tools. If you'd like to fully test offline, you can add the `--offline` flag to your `cargo test` command. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod objects; | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub struct Client { | ||
api_key: String, | ||
} | ||
|
||
impl Client { | ||
pub fn new(api_key: String) -> Self { | ||
Self { api_key } | ||
} | ||
|
||
pub fn verify(&self) -> bool { | ||
!self.api_key.is_empty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pub struct Endpoint { | ||
url: String, | ||
api_key: String, | ||
} | ||
|
||
impl Endpoint { | ||
pub fn new(url: String, api_key: String) -> Self { | ||
Self { url, api_key } | ||
} | ||
|
||
pub fn format(&self) -> String { | ||
assert!(self.verify(), "Failed to verify endpoint string."); | ||
format!("{}?api-key={}", self.url, self.api_key) | ||
} | ||
|
||
fn verify_format(&self) -> bool { | ||
self.url.is_empty() || !self.api_key.is_empty() | ||
} | ||
|
||
pub fn verify(&self) -> bool { | ||
self.verify_format() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use minreq::{self, Response, Error}; | ||
|
||
pub struct HttpClient { | ||
url: String, | ||
method: String, | ||
} | ||
|
||
impl HttpClient { | ||
pub fn new(url: String, method: String) -> Self { | ||
Self { url, method } | ||
} | ||
|
||
pub fn post(&self, payload: String) -> Result<String, Error> { | ||
let response = minreq::post(self.url.to_owned()) | ||
.with_body(payload) | ||
.send()?; | ||
|
||
let parsed = response.as_str()?; | ||
Ok(parsed.to_owned()) | ||
} | ||
|
||
pub fn get(&self) -> Result<String, Error> { | ||
let response: Response = minreq::get(self.url.to_owned()).send()?; | ||
let parsed = response.as_str()?; | ||
|
||
Ok(parsed.to_owned()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) mod endpoint; | ||
pub(crate) mod client; | ||
pub(crate) mod httpclient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::objects::client::Client as Client; | ||
|
||
#[test] | ||
fn test_client_verification() { | ||
let api_key = "my-api-key"; | ||
let my_client = Client::new(api_key.to_owned()); | ||
|
||
assert!(my_client.verify()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::objects::endpoint::Endpoint as Endpoint; | ||
|
||
#[test] | ||
fn test_endpoint_formatting() { | ||
let endpoint_url: &str = "https://my-url.com"; | ||
let endpoint_api_key: &str = "my-api-key"; | ||
let my_endpoint: Endpoint = Endpoint::new(endpoint_url.to_string(), endpoint_api_key.to_string()); | ||
|
||
assert_eq!(my_endpoint.format(), format!("{}?api-key={}", endpoint_url.clone(), endpoint_api_key.clone())); | ||
} | ||
|
||
#[test] | ||
fn test_endpoint_verification() { | ||
let endpoint_url: &str = "https://my-url.com"; | ||
let endpoint_api_key: &str = "my-api-key"; | ||
let my_endpoint: Endpoint = Endpoint::new(endpoint_url.to_string(), endpoint_api_key.to_string()); | ||
|
||
assert!(my_endpoint.verify()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::objects::httpclient::HttpClient as HttpClient; | ||
|
||
#[test] | ||
fn http_get_functionality() { | ||
let endpoint_url = "https://dummyjson.com/test"; | ||
let endpoint_method = "GET"; | ||
|
||
let my_client = HttpClient::new(endpoint_url.to_owned(), endpoint_method.to_owned()); | ||
let http_result = my_client.get(); | ||
|
||
assert_ne!(http_result.unwrap(), "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[cfg(test)] | ||
mod client_tests; | ||
|
||
#[cfg(test)] | ||
mod endpoint_tests; | ||
|
||
#[cfg(test)] | ||
mod http_client_tests; |