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:
Sahkal Poddar
2023-10-12 14:39:10 +05:30
committed by GitHub
parent 46f14191ab
commit 642085dc74
58 changed files with 2565 additions and 23 deletions

View 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)?
}
}