mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Co-authored-by: Shankar Singh C <83439957+ShankarSinghC@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: YongJoon Kim <penubokim@gmail.com> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com> Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Co-authored-by: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com> Co-authored-by: Sampras Lopes <Sampras.lopes@juspay.in>
224 lines
8.2 KiB
Rust
224 lines
8.2 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use masking::Secret;
|
|
use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self, domain, api, storage::enums}};
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
pub struct {{project-name | downcase | pascal_case}}RouterData<T> {
|
|
pub amount: MinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
|
|
pub router_data: T,
|
|
}
|
|
|
|
impl<T>
|
|
TryFrom<(
|
|
&types::api::CurrencyUnit,
|
|
types::storage::enums::Currency,
|
|
i64,
|
|
T,
|
|
)> for {{project-name | downcase | pascal_case}}RouterData<T>
|
|
{
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(
|
|
(_currency_unit, _currency, amount, item): (
|
|
&types::api::CurrencyUnit,
|
|
types::storage::enums::Currency,
|
|
i64,
|
|
T,
|
|
),
|
|
) -> Result<Self, Self::Error> {
|
|
//Todo : use utils to convert the amount to the type of amount that a connector accepts
|
|
Ok(Self {
|
|
amount,
|
|
router_data: item,
|
|
})
|
|
}
|
|
}
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
|
|
pub struct {{project-name | downcase | pascal_case}}PaymentsRequest {
|
|
amount: i64,
|
|
card: {{project-name | downcase | pascal_case}}Card
|
|
}
|
|
|
|
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
|
|
pub struct {{project-name | downcase | pascal_case}}Card {
|
|
number: cards::CardNumber,
|
|
expiry_month: Secret<String>,
|
|
expiry_year: Secret<String>,
|
|
cvc: Secret<String>,
|
|
complete: bool,
|
|
}
|
|
|
|
impl TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::PaymentsAuthorizeRouterData>> for {{project-name | downcase | pascal_case}}PaymentsRequest {
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(item: &{{project-name | downcase | pascal_case}}RouterData<&types::PaymentsAuthorizeRouterData>) -> Result<Self,Self::Error> {
|
|
match item.router_data.request.payment_method_data.clone() {
|
|
domain::PaymentMethodData::Card(req_card) => {
|
|
let card = {{project-name | downcase | pascal_case}}Card {
|
|
number: req_card.card_number,
|
|
expiry_month: req_card.card_exp_month,
|
|
expiry_year: req_card.card_exp_year,
|
|
cvc: req_card.card_cvc,
|
|
complete: item.router_data.request.is_auto_capture()?,
|
|
};
|
|
Ok(Self {
|
|
amount: item.amount.to_owned(),
|
|
card,
|
|
})
|
|
}
|
|
_ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()),
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
// Auth Struct
|
|
pub struct {{project-name | downcase | pascal_case}}AuthType {
|
|
pub(super) api_key: Secret<String>
|
|
}
|
|
|
|
impl TryFrom<&types::ConnectorAuthType> for {{project-name | downcase | pascal_case}}AuthType {
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> {
|
|
match auth_type {
|
|
types::ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
|
|
api_key: api_key.to_owned(),
|
|
}),
|
|
_ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
|
|
}
|
|
}
|
|
}
|
|
// PaymentsResponse
|
|
//TODO: Append the remaining status flags
|
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum {{project-name | downcase | pascal_case}}PaymentStatus {
|
|
Succeeded,
|
|
Failed,
|
|
#[default]
|
|
Processing,
|
|
}
|
|
|
|
impl From<{{project-name | downcase | pascal_case}}PaymentStatus> for enums::AttemptStatus {
|
|
fn from(item: {{project-name | downcase | pascal_case}}PaymentStatus) -> Self {
|
|
match item {
|
|
{{project-name | downcase | pascal_case}}PaymentStatus::Succeeded => Self::Charged,
|
|
{{project-name | downcase | pascal_case}}PaymentStatus::Failed => Self::Failure,
|
|
{{project-name | downcase | pascal_case}}PaymentStatus::Processing => Self::Authorizing,
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
|
|
pub struct {{project-name | downcase | pascal_case}}PaymentsResponse {
|
|
status: {{project-name | downcase | pascal_case}}PaymentStatus,
|
|
id: String,
|
|
}
|
|
|
|
impl<F,T> TryFrom<types::ResponseRouterData<F, {{project-name | downcase | pascal_case}}PaymentsResponse, T, types::PaymentsResponseData>> for types::RouterData<F, T, types::PaymentsResponseData> {
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(item: types::ResponseRouterData<F, {{project-name | downcase | pascal_case}}PaymentsResponse, T, types::PaymentsResponseData>) -> Result<Self,Self::Error> {
|
|
Ok(Self {
|
|
status: enums::AttemptStatus::from(item.response.status),
|
|
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
|
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
|
|
redirection_data: None,
|
|
mandate_reference: None,
|
|
connector_metadata: None,
|
|
network_txn_id: None,
|
|
connector_response_reference_id: None,
|
|
incremental_authorization_allowed: None,
|
|
charge_id: None,
|
|
}),
|
|
..item.data
|
|
})
|
|
}
|
|
}
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
// REFUND :
|
|
// Type definition for RefundRequest
|
|
#[derive(Default, Debug, Serialize)]
|
|
pub struct {{project-name | downcase | pascal_case}}RefundRequest {
|
|
pub amount: MinorUnit
|
|
}
|
|
|
|
impl<F> TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::RefundsRouterData<F>>> for {{project-name | downcase | pascal_case}}RefundRequest {
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(item: &{{project-name | downcase | pascal_case}}RouterData<&types::RefundsRouterData<F>>) -> Result<Self,Self::Error> {
|
|
Ok(Self {
|
|
amount: item.amount.to_owned(),
|
|
})
|
|
}
|
|
}
|
|
|
|
// Type definition for Refund Response
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug, Serialize, Default, Deserialize, Clone)]
|
|
pub enum RefundStatus {
|
|
Succeeded,
|
|
Failed,
|
|
#[default]
|
|
Processing,
|
|
}
|
|
|
|
impl From<RefundStatus> for enums::RefundStatus {
|
|
fn from(item: RefundStatus) -> Self {
|
|
match item {
|
|
RefundStatus::Succeeded => Self::Success,
|
|
RefundStatus::Failed => Self::Failure,
|
|
RefundStatus::Processing => Self::Pending,
|
|
//TODO: Review mapping
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
|
pub struct RefundResponse {
|
|
id: String,
|
|
status: RefundStatus
|
|
}
|
|
|
|
impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
|
|
for types::RefundsRouterData<api::Execute>
|
|
{
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(
|
|
item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,
|
|
) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
response: Ok(types::RefundsResponseData {
|
|
connector_refund_id: item.response.id.to_string(),
|
|
refund_status: enums::RefundStatus::from(item.response.status),
|
|
}),
|
|
..item.data
|
|
})
|
|
}
|
|
}
|
|
|
|
impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>> for types::RefundsRouterData<api::RSync>
|
|
{
|
|
type Error = error_stack::Report<errors::ConnectorError>;
|
|
fn try_from(item: types::RefundsResponseRouterData<api::RSync, RefundResponse>) -> Result<Self,Self::Error> {
|
|
Ok(Self {
|
|
response: Ok(types::RefundsResponseData {
|
|
connector_refund_id: item.response.id.to_string(),
|
|
refund_status: enums::RefundStatus::from(item.response.status),
|
|
}),
|
|
..item.data
|
|
})
|
|
}
|
|
}
|
|
|
|
//TODO: Fill the struct with respective fields
|
|
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct {{project-name | downcase | pascal_case}}ErrorResponse {
|
|
pub status_code: u16,
|
|
pub code: String,
|
|
pub message: String,
|
|
pub reason: Option<String>,
|
|
}
|