chore: merging back release v0.3.0 back to main (#636) (#655)

Co-authored-by: Sangamesh Kulkarni <59434228+Sangamesh26@users.noreply.github.com>
Co-authored-by: ItsMeShashank <shashank.attarde@juspay.in>
Co-authored-by: Abhishek <abhishek.marrivagu@juspay.in>
Co-authored-by: Jagan <jaganelavarasan@gmail.com>
Co-authored-by: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com>
Co-authored-by: Sampras Lopes <lsampras@protonmail.com>
This commit is contained in:
Arun Raj M
2023-02-26 13:55:17 +05:30
committed by GitHub
parent 7792de55ef
commit f3224cc4df
74 changed files with 5979 additions and 355 deletions

View File

@ -4,7 +4,7 @@ use masking::Secret;
use crate::{
core::errors::{self, CustomResult},
pii::PeekInterface,
types::{self, api},
types::{self, api, PaymentsCancelData},
utils::OptionExt,
};
@ -34,15 +34,37 @@ impl AccessTokenRequestInfo for types::RefreshTokenRouterData {
}
}
pub trait PaymentsRequestData {
pub trait RouterData {
fn get_billing(&self) -> Result<&api::Address, Error>;
fn get_billing_country(&self) -> Result<String, Error>;
fn get_billing_phone(&self) -> Result<&api::PhoneDetails, Error>;
fn get_connector_meta(&self) -> Result<serde_json::Value, Error>;
fn get_session_token(&self) -> Result<String, Error>;
fn get_billing_address(&self) -> Result<&api::AddressDetails, Error>;
fn to_connector_meta<T>(&self) -> Result<T, Error>
where
T: serde::de::DeserializeOwned;
}
pub trait PaymentsRequestData {
fn get_card(&self) -> Result<api::Card, Error>;
fn get_return_url(&self) -> Result<String, Error>;
}
pub trait PaymentsCancelRequestData {
fn get_amount(&self) -> Result<i64, Error>;
fn get_currency(&self) -> Result<storage_models::enums::Currency, Error>;
}
impl PaymentsCancelRequestData for PaymentsCancelData {
fn get_amount(&self) -> Result<i64, Error> {
self.amount.ok_or_else(missing_field_err("amount"))
}
fn get_currency(&self) -> Result<storage_models::enums::Currency, Error> {
self.currency.ok_or_else(missing_field_err("currency"))
}
}
pub trait RefundsRequestData {
fn get_connector_refund_id(&self) -> Result<String, Error>;
}
@ -56,7 +78,7 @@ impl RefundsRequestData for types::RefundsData {
}
}
impl PaymentsRequestData for types::PaymentsAuthorizeRouterData {
impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Response> {
fn get_billing_country(&self) -> Result<String, Error> {
self.address
.billing
@ -66,13 +88,6 @@ impl PaymentsRequestData for types::PaymentsAuthorizeRouterData {
.ok_or_else(missing_field_err("billing.address.country"))
}
fn get_card(&self) -> Result<api::Card, Error> {
match self.request.payment_method_data.clone() {
api::PaymentMethod::Card(card) => Ok(card),
_ => Err(missing_field_err("card")()),
}
}
fn get_billing_phone(&self) -> Result<&api::PhoneDetails, Error> {
self.address
.billing
@ -94,11 +109,40 @@ impl PaymentsRequestData for types::PaymentsAuthorizeRouterData {
.ok_or_else(missing_field_err("billing"))
}
fn get_connector_meta(&self) -> Result<serde_json::Value, Error> {
self.connector_meta_data
.clone()
.ok_or_else(missing_field_err("connector_meta_data"))
}
fn get_session_token(&self) -> Result<String, Error> {
self.session_token
.clone()
.ok_or_else(missing_field_err("session_token"))
}
fn to_connector_meta<T>(&self) -> Result<T, Error>
where
T: serde::de::DeserializeOwned,
{
serde_json::from_value::<T>(self.get_connector_meta()?)
.into_report()
.change_context(errors::ConnectorError::NoConnectorMetaData)
}
}
impl PaymentsRequestData for types::PaymentsAuthorizeRouterData {
fn get_return_url(&self) -> Result<String, Error> {
self.router_return_url
.clone()
.ok_or_else(missing_field_err("router_return_url"))
}
fn get_card(&self) -> Result<api::Card, Error> {
match self.request.payment_method_data.clone() {
api::PaymentMethod::Card(card) => Ok(card),
_ => Err(missing_field_err("card")()),
}
}
}
pub trait CardData {