Struct SwishClient

Source
pub struct SwishClient { /* private fields */ }
Expand description

The client used to make call to the Swish API.

Implementations§

Source§

impl SwishClient

Source

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();
Source

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
§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);
Source

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);
Source

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
§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);
Source

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§

Source§

impl Debug for SwishClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.