use super::common::*;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Card {
pub name: String,
pub number: String,
pub expiry_year: String,
pub expiry_month: CardExpiryMonth,
pub cvv: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub zip_code: Option<String>,
#[serde(rename = "type")]
pub r#type: CardType,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Checkout {
#[serde(skip_serializing_if = "Option::is_none")]
pub checkout_reference: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<Currency>,
#[serde(skip_serializing_if = "Option::is_none")]
pub merchant_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<CheckoutStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub date: Option<crate::datetime::DateTime>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::nullable::deserialize"
)]
pub valid_until: Option<crate::Nullable<crate::datetime::DateTime>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mandate: Option<MandateResponse>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hosted_checkout_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transactions: Option<Vec<CheckoutTransactionsItem>>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutAccepted {
#[serde(skip_serializing_if = "Option::is_none")]
pub next_step: Option<CheckoutAcceptedNextStep>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CheckoutCreateRequest {
pub checkout_reference: String,
pub amount: f32,
pub currency: Currency,
pub merchant_code: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub purpose: Option<CheckoutCreateRequestPurpose>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::nullable::deserialize"
)]
pub valid_until: Option<crate::Nullable<crate::datetime::DateTime>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hosted_checkout: Option<HostedCheckout>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutSuccess {
#[serde(skip_serializing_if = "Option::is_none")]
pub checkout_reference: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<Currency>,
#[serde(skip_serializing_if = "Option::is_none")]
pub merchant_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<CheckoutSuccessStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub date: Option<crate::datetime::DateTime>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::nullable::deserialize"
)]
pub valid_until: Option<crate::Nullable<crate::datetime::DateTime>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mandate: Option<MandateResponse>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hosted_checkout_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transactions: Option<Vec<CheckoutSuccessTransactionsItem>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub merchant_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_instrument: Option<CheckoutSuccessPaymentInstrument>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct DetailsError {
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub details: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub failed_constraints: Option<Vec<DetailsErrorFailedConstraintsItem>>,
}
impl std::fmt::Display for DetailsError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match (&self.title, &self.details) {
(Some(title), Some(details)) => write!(f, "{}: {}", title, details),
(Some(title), None) => write!(f, "{}", title),
(None, Some(details)) => write!(f, "{}", details),
(None, None) => write!(f, "{:?}", self),
}
}
}
impl std::error::Error for DetailsError {}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct HostedCheckout {
pub enabled: bool,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct MandatePayload {
#[serde(rename = "type")]
pub r#type: MandatePayloadType,
pub user_agent: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_ip: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ProcessCheckout {
pub payment_type: ProcessCheckoutPaymentType,
#[serde(skip_serializing_if = "Option::is_none")]
pub installments: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mandate: Option<MandatePayload>,
#[serde(skip_serializing_if = "Option::is_none")]
pub card: Option<Card>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_pay: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub apple_pay: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub personal_details: Option<PersonalDetails>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CardExpiryMonth {
#[serde(rename = "01")]
_01,
#[serde(rename = "02")]
_02,
#[serde(rename = "03")]
_03,
#[serde(rename = "04")]
_04,
#[serde(rename = "05")]
_05,
#[serde(rename = "06")]
_06,
#[serde(rename = "07")]
_07,
#[serde(rename = "08")]
_08,
#[serde(rename = "09")]
_09,
#[serde(rename = "10")]
_10,
#[serde(rename = "11")]
_11,
#[serde(rename = "12")]
_12,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CheckoutStatus {
#[serde(rename = "PENDING")]
Pending,
#[serde(rename = "FAILED")]
Failed,
#[serde(rename = "PAID")]
Paid,
#[serde(rename = "EXPIRED")]
Expired,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CheckoutTransactionsItemStatus {
#[serde(rename = "SUCCESSFUL")]
Successful,
#[serde(rename = "CANCELLED")]
Cancelled,
#[serde(rename = "FAILED")]
Failed,
#[serde(rename = "PENDING")]
Pending,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutTransactionsItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<Currency>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<crate::datetime::DateTime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<CheckoutTransactionsItemStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_type: Option<PaymentType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub installments_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub merchant_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vat_amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tip_amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entry_mode: Option<EntryMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_code: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CheckoutAcceptedNextStepMechanismItem {
#[serde(rename = "iframe")]
Iframe,
#[serde(rename = "browser")]
Browser,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutAcceptedNextStepPayload {
#[serde(
flatten,
default,
skip_serializing_if = "std::collections::HashMap::is_empty"
)]
pub additional_properties: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutAcceptedNextStep {
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub method: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mechanism: Option<Vec<CheckoutAcceptedNextStepMechanismItem>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payload: Option<CheckoutAcceptedNextStepPayload>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CheckoutCreateRequestPurpose {
#[serde(rename = "CHECKOUT")]
Checkout,
#[serde(rename = "SETUP_RECURRING_PAYMENT")]
SetupRecurringPayment,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CheckoutSuccessStatus {
#[serde(rename = "PENDING")]
Pending,
#[serde(rename = "FAILED")]
Failed,
#[serde(rename = "PAID")]
Paid,
#[serde(rename = "EXPIRED")]
Expired,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum CheckoutSuccessTransactionsItemStatus {
#[serde(rename = "SUCCESSFUL")]
Successful,
#[serde(rename = "CANCELLED")]
Cancelled,
#[serde(rename = "FAILED")]
Failed,
#[serde(rename = "PENDING")]
Pending,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutSuccessTransactionsItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<Currency>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<crate::datetime::DateTime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<CheckoutSuccessTransactionsItemStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_type: Option<PaymentType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub installments_count: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub merchant_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vat_amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tip_amount: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub entry_mode: Option<EntryMode>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_code: Option<String>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct CheckoutSuccessPaymentInstrument {
#[serde(skip_serializing_if = "Option::is_none")]
pub token: Option<String>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct DetailsErrorFailedConstraintsItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reference: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum MandatePayloadType {
#[serde(rename = "recurrent")]
Recurrent,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum ProcessCheckoutPaymentType {
#[serde(rename = "card")]
Card,
#[serde(rename = "boleto")]
Boleto,
#[serde(rename = "ideal")]
Ideal,
#[serde(rename = "blik")]
Blik,
#[serde(rename = "bancontact")]
Bancontact,
#[serde(rename = "google_pay")]
GooglePay,
#[serde(rename = "apple_pay")]
ApplePay,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ListAvailablePaymentMethodsResponseAvailablePaymentMethodsItem {
pub id: String,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct ListParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub checkout_reference: Option<String>,
}
pub type ListResponse = Vec<CheckoutSuccess>;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum ProcessResponse {
Status200(CheckoutSuccess),
Status202(CheckoutAccepted),
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct ListAvailablePaymentMethodsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub amount: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct ListAvailablePaymentMethodsResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub available_payment_methods:
Option<Vec<ListAvailablePaymentMethodsResponseAvailablePaymentMethodsItem>>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CreateApplePaySessionBody {
pub context: String,
pub target: String,
}
pub type CreateApplePaySessionResponse = serde_json::Value;
use crate::client::Client;
#[derive(Debug)]
pub enum ListErrorBody {
Unauthorized(Problem),
}
#[derive(Debug)]
pub enum CreateErrorBody {
BadRequest(ErrorExtended),
Unauthorized(Problem),
Forbidden(ErrorForbidden),
Conflict(Error),
}
#[derive(Debug)]
pub enum DeactivateErrorBody {
Unauthorized(Problem),
NotFound(Error),
Conflict(Error),
}
#[derive(Debug)]
pub enum GetErrorBody {
Unauthorized(Problem),
NotFound(Error),
}
#[derive(Debug)]
pub enum ProcessErrorBody {
BadRequest(crate::error::UnknownApiBody),
Unauthorized(Problem),
NotFound(Error),
Conflict(Error),
}
#[derive(Debug)]
pub enum ListAvailablePaymentMethodsErrorBody {
BadRequest(DetailsError),
}
#[derive(Debug)]
pub enum CreateApplePaySessionErrorBody {
BadRequest(crate::error::UnknownApiBody),
NotFound(Error),
}
#[derive(Debug)]
pub struct CheckoutsClient<'a> {
client: &'a Client,
}
impl<'a> CheckoutsClient<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub fn client(&self) -> &Client {
self.client
}
pub async fn list(
&self,
params: ListParams,
) -> crate::error::SdkResult<ListResponse, ListErrorBody> {
let path = "/v0.1/checkouts";
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.get(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout());
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
if let Some(ref value) = params.checkout_reference {
request = request.query(&[("checkout_reference", value)]);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::OK => {
let data: ListResponse = response.json().await?;
Ok(data)
}
reqwest::StatusCode::UNAUTHORIZED => {
let body: Problem = response.json().await?;
Err(crate::error::SdkError::api(ListErrorBody::Unauthorized(
body,
)))
}
_ => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
pub async fn create(
&self,
body: CheckoutCreateRequest,
) -> crate::error::SdkResult<Checkout, CreateErrorBody> {
let path = "/v0.1/checkouts";
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.post(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout())
.json(&body);
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::CREATED => {
let data: Checkout = response.json().await?;
Ok(data)
}
reqwest::StatusCode::BAD_REQUEST => {
let body: ErrorExtended = response.json().await?;
Err(crate::error::SdkError::api(CreateErrorBody::BadRequest(
body,
)))
}
reqwest::StatusCode::UNAUTHORIZED => {
let body: Problem = response.json().await?;
Err(crate::error::SdkError::api(CreateErrorBody::Unauthorized(
body,
)))
}
reqwest::StatusCode::FORBIDDEN => {
let body: ErrorForbidden = response.json().await?;
Err(crate::error::SdkError::api(CreateErrorBody::Forbidden(
body,
)))
}
reqwest::StatusCode::CONFLICT => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(CreateErrorBody::Conflict(body)))
}
_ => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
pub async fn deactivate(
&self,
id: impl Into<String>,
) -> crate::error::SdkResult<Checkout, DeactivateErrorBody> {
let path = format!("/v0.1/checkouts/{}", id.into());
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.delete(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout());
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::OK => {
let data: Checkout = response.json().await?;
Ok(data)
}
reqwest::StatusCode::UNAUTHORIZED => {
let body: Problem = response.json().await?;
Err(crate::error::SdkError::api(
DeactivateErrorBody::Unauthorized(body),
))
}
reqwest::StatusCode::NOT_FOUND => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(DeactivateErrorBody::NotFound(
body,
)))
}
reqwest::StatusCode::CONFLICT => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(DeactivateErrorBody::Conflict(
body,
)))
}
_ => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
pub async fn get(
&self,
id: impl Into<String>,
) -> crate::error::SdkResult<CheckoutSuccess, GetErrorBody> {
let path = format!("/v0.1/checkouts/{}", id.into());
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.get(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout());
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::OK => {
let data: CheckoutSuccess = response.json().await?;
Ok(data)
}
reqwest::StatusCode::UNAUTHORIZED => {
let body: Problem = response.json().await?;
Err(crate::error::SdkError::api(GetErrorBody::Unauthorized(
body,
)))
}
reqwest::StatusCode::NOT_FOUND => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(GetErrorBody::NotFound(body)))
}
_ => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
pub async fn process(
&self,
id: impl Into<String>,
body: ProcessCheckout,
) -> crate::error::SdkResult<ProcessResponse, ProcessErrorBody> {
let path = format!("/v0.1/checkouts/{}", id.into());
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.put(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout())
.json(&body);
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::OK => {
let data: CheckoutSuccess = response.json().await?;
Ok(ProcessResponse::Status200(data))
}
reqwest::StatusCode::ACCEPTED => {
let data: CheckoutAccepted = response.json().await?;
Ok(ProcessResponse::Status202(data))
}
reqwest::StatusCode::BAD_REQUEST => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::api(ProcessErrorBody::BadRequest(
body,
)))
}
reqwest::StatusCode::UNAUTHORIZED => {
let body: Problem = response.json().await?;
Err(crate::error::SdkError::api(ProcessErrorBody::Unauthorized(
body,
)))
}
reqwest::StatusCode::NOT_FOUND => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(ProcessErrorBody::NotFound(
body,
)))
}
reqwest::StatusCode::CONFLICT => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(ProcessErrorBody::Conflict(
body,
)))
}
_ => {
let body = response.text().await?;
let body = crate::error::UnknownApiBody::from_text(body);
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
pub async fn list_available_payment_methods(
&self,
merchant_code: impl Into<String>,
params: ListAvailablePaymentMethodsParams,
) -> crate::error::SdkResult<
ListAvailablePaymentMethodsResponse,
ListAvailablePaymentMethodsErrorBody,
> {
let path = format!("/v0.1/merchants/{}/payment-methods", merchant_code.into());
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.get(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout());
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
if let Some(ref value) = params.amount {
request = request.query(&[("amount", value)]);
}
if let Some(ref value) = params.currency {
request = request.query(&[("currency", value)]);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::OK => {
let data: ListAvailablePaymentMethodsResponse = response.json().await?;
Ok(data)
}
reqwest::StatusCode::BAD_REQUEST => {
let body: DetailsError = response.json().await?;
Err(crate::error::SdkError::api(
ListAvailablePaymentMethodsErrorBody::BadRequest(body),
))
}
_ => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
pub async fn create_apple_pay_session(
&self,
id: impl Into<String>,
body: Option<CreateApplePaySessionBody>,
) -> crate::error::SdkResult<CreateApplePaySessionResponse, CreateApplePaySessionErrorBody>
{
let path = format!("/v0.2/checkouts/{}/apple-pay-session", id.into());
let url = format!("{}{}", self.client.base_url(), path);
let mut request = self
.client
.http_client()
.put(&url)
.header("User-Agent", crate::version::user_agent())
.timeout(self.client.timeout());
if let Some(authorization) = self.client.authorization() {
request = request.header("Authorization", format!("Bearer {}", authorization));
}
for (header_name, header_value) in self.client.runtime_headers() {
request = request.header(*header_name, header_value);
}
if let Some(body) = body {
request = request.json(&body);
}
let response = request.send().await?;
let status = response.status();
match status {
reqwest::StatusCode::OK => {
let data: CreateApplePaySessionResponse = response.json().await?;
Ok(data)
}
reqwest::StatusCode::BAD_REQUEST => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::api(
CreateApplePaySessionErrorBody::BadRequest(body),
))
}
reqwest::StatusCode::NOT_FOUND => {
let body: Error = response.json().await?;
Err(crate::error::SdkError::api(
CreateApplePaySessionErrorBody::NotFound(body),
))
}
_ => {
let body_bytes = response.bytes().await?;
let body = crate::error::UnknownApiBody::from_bytes(body_bytes.as_ref());
Err(crate::error::SdkError::unexpected(status, body))
}
}
}
}