mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 21:37:41 +08:00
feat(router): Add payment link support (#2105)
Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in> Co-authored-by: Kashif <46213975+kashif-m@users.noreply.github.com> Co-authored-by: Kashif <mohammed.kashif@juspay.in> Co-authored-by: Bernard Eugine <114725419+bernard-eugine@users.noreply.github.com>
This commit is contained in:
66
crates/router/src/db/payment_link.rs
Normal file
66
crates/router/src/db/payment_link.rs
Normal file
@ -0,0 +1,66 @@
|
||||
use error_stack::IntoReport;
|
||||
|
||||
use super::{MockDb, Store};
|
||||
use crate::{
|
||||
connection,
|
||||
core::errors::{self, CustomResult},
|
||||
types::storage,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait PaymentLinkInterface {
|
||||
async fn find_payment_link_by_payment_link_id(
|
||||
&self,
|
||||
payment_link_id: &str,
|
||||
) -> CustomResult<storage::PaymentLink, errors::StorageError>;
|
||||
|
||||
async fn insert_payment_link(
|
||||
&self,
|
||||
_payment_link: storage::PaymentLinkNew,
|
||||
) -> CustomResult<storage::PaymentLink, errors::StorageError>;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl PaymentLinkInterface for Store {
|
||||
async fn find_payment_link_by_payment_link_id(
|
||||
&self,
|
||||
payment_link_id: &str,
|
||||
) -> CustomResult<storage::PaymentLink, errors::StorageError> {
|
||||
let conn = connection::pg_connection_read(self).await?;
|
||||
storage::PaymentLink::find_link_by_payment_link_id(&conn, payment_link_id)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn insert_payment_link(
|
||||
&self,
|
||||
payment_link_object: storage::PaymentLinkNew,
|
||||
) -> CustomResult<storage::PaymentLink, errors::StorageError> {
|
||||
let conn = connection::pg_connection_write(self).await?;
|
||||
payment_link_object
|
||||
.insert(&conn)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl PaymentLinkInterface for MockDb {
|
||||
async fn insert_payment_link(
|
||||
&self,
|
||||
_payment_link: storage::PaymentLinkNew,
|
||||
) -> CustomResult<storage::PaymentLink, errors::StorageError> {
|
||||
// TODO: Implement function for `MockDb`
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn find_payment_link_by_payment_link_id(
|
||||
&self,
|
||||
_payment_link_id: &str,
|
||||
) -> CustomResult<storage::PaymentLink, errors::StorageError> {
|
||||
// TODO: Implement function for `MockDb`x
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user