pub struct SwishClient { /* private fields */ }
Expand description
The client used to make call to the Swish API.
Implementations§
Source§impl SwishClient
impl SwishClient
Sourcepub fn new(
merchant_swish_number: &str,
cert_path: &str,
passphrase: &str,
handle: Handle,
) -> Self
pub fn new( merchant_swish_number: &str, cert_path: &str, passphrase: &str, handle: Handle, ) -> Self
Creates a new SwishClient
§Arguments
merchant_swish_number
- The merchants swish number which will receive the payments.cert_path
- The path to the certificate.passphrase
- The passphrase to the certificate.handle
- A tokio reactor handle.
§Returns
A configured SwishClient
.
§Example
extern crate tokio_core;
extern crate swish_api;
use swish_api::client::SwishClient;
use tokio_core::reactor::Core;
use std::env;
let core = Core::new().unwrap();
let handle = core.handle();
let current_dir = env::current_dir().unwrap();
let cert_path = current_dir.join("./certs/test_cert.p12");
let swish_client = cert_path
.into_os_string()
.to_str()
.map(|cert_path_string| {
SwishClient::new("1231181189", cert_path_string, "swish", handle)
}).unwrap();
Sourcepub fn create_payment<'a>(
&'a self,
params: PaymentParams<'_>,
) -> Box<dyn Future<Item = CreatedPayment, Error = SwishClientError> + 'a>
pub fn create_payment<'a>( &'a self, params: PaymentParams<'_>, ) -> Box<dyn Future<Item = CreatedPayment, Error = SwishClientError> + 'a>
Creates a payment with the provided PaymentParams
.
§Returns
A Future with a CreatedPayment
.
§Arguments
params
-PaymentParams
.
§Example
extern crate tokio_core;
extern crate swish_api;
use tokio_core::reactor::Core;
use std::env;
use swish_api::client::{PaymentParams, SwishClient};
let core = Core::new().unwrap();
let handle = core.handle();
let current_dir = env::current_dir().unwrap();
let cert_path = current_dir.join("./tests/test_cert.p12");
let root_cert_path = current_dir.join("./tests/root_cert.der");
let swish_client = cert_path
.into_os_string()
.to_str()
.map(|cert_path_string| {
SwishClient::new("1231181189", cert_path_string, "swish", handle)
}).unwrap();
let mut payment_params = PaymentParams::default();
payment_params.amount = 100.00;
payment_params.payee_alias = "1231181189";
payment_params.payee_payment_reference = Some("0123456789");
payment_params.callback_url = "https://example.com/api/swishcb/paymentrequests";
payment_params.message = Some("Kingston USB Flash Drive 8 GB");
let payment = swish_client.create_payment(payment_params);
Sourcepub fn get_payment<'a>(
&'a self,
payment_id: &str,
) -> Box<dyn Future<Item = Payment, Error = SwishClientError> + 'a>
pub fn get_payment<'a>( &'a self, payment_id: &str, ) -> Box<dyn Future<Item = Payment, Error = SwishClientError> + 'a>
Gets a payment for a given payment_id
.
§Returns
A Future with a Payment
.
§Arguments
payment_id
- A string id for a payment
§Example
extern crate tokio_core;
extern crate swish_api;
use tokio_core::reactor::Core;
use std::env;
use swish_api::client::SwishClient;
let core = Core::new().unwrap();
let handle = core.handle();
let current_dir = env::current_dir().unwrap();
let cert_path = current_dir.join("./tests/test_cert.p12");
let root_cert_path = current_dir.join("./tests/root_cert.der");
let swish_client = cert_path
.into_os_string()
.to_str()
.map(|cert_path_string| {
SwishClient::new("1231181189", cert_path_string, "swish", handle)
}).unwrap();
let payment_id = "111";
let payment = swish_client.get_payment(payment_id);
Sourcepub fn create_refund<'a>(
&'a self,
params: RefundParams<'_>,
) -> Box<dyn Future<Item = CreatedRefund, Error = SwishClientError> + 'a>
pub fn create_refund<'a>( &'a self, params: RefundParams<'_>, ) -> Box<dyn Future<Item = CreatedRefund, Error = SwishClientError> + 'a>
Creates a refund with the provided RefundParams
.
§Returns
A Future with a CreatedRefund
.
§Arguments
params
-RefundParams
.
§Example
extern crate tokio_core;
extern crate swish_api;
use tokio_core::reactor::Core;
use std::env;
use swish_api::client::{RefundParams, SwishClient};
let core = Core::new().unwrap();
let handle = core.handle();
let current_dir = env::current_dir().unwrap();
let cert_path = current_dir.join("./tests/test_cert.p12");
let root_cert_path = current_dir.join("./tests/root_cert.der");
let swish_client = cert_path
.into_os_string()
.to_str()
.map(|cert_path_string| {
SwishClient::new("1231181189", cert_path_string, "swish", handle)
}).unwrap();
let mut refund_params = RefundParams::default();
refund_params.amount = 100.00;
refund_params.callback_url = "https://example.com/api/swishcb/refunds";
refund_params.payer_payment_reference = Some("0123456789");
refund_params.message = Some("Refund for Kingston USB Flash Drive 8 GB");
let refund = swish_client.create_refund(refund_params);
Sourcepub fn get_refund<'a>(
&'a self,
refund_id: &str,
) -> Box<dyn Future<Item = Refund, Error = SwishClientError> + 'a>
pub fn get_refund<'a>( &'a self, refund_id: &str, ) -> Box<dyn Future<Item = Refund, Error = SwishClientError> + 'a>
Gets a refund for a given refund_id
.
§Returns
A Future with a Refund
.
§Arguments
refund_id
- A string id for a refund
§Example
extern crate tokio_core;
extern crate swish_api;
use tokio_core::reactor::Core;
use std::env;
use swish_api::client::SwishClient;
let core = Core::new().unwrap();
let handle = core.handle();
let current_dir = env::current_dir().unwrap();
let cert_path = current_dir.join("./tests/test_cert.p12");
let root_cert_path = current_dir.join("./tests/root_cert.der");
let swish_client = cert_path
.into_os_string()
.to_str()
.map(|cert_path_string| {
SwishClient::new("1231181189", cert_path_string, "swish", handle)
}).unwrap();
let refund_id = "111";
let refund = swish_client.get_refund(refund_id);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SwishClient
impl !RefUnwindSafe for SwishClient
impl !Send for SwishClient
impl !Sync for SwishClient
impl Unpin for SwishClient
impl !UnwindSafe for SwishClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more