Skip to content

Commit

Permalink
feat(connector): [Gocardless] Implement mandate flow (#2461)
Browse files Browse the repository at this point in the history
Co-authored-by: prajjwalkumar17 <[email protected]>
  • Loading branch information
deepanshu-iiitu and prajjwalkumar17 authored Oct 5, 2023
1 parent e24897c commit 4149965
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 143 deletions.
103 changes: 46 additions & 57 deletions crates/router/src/connector/gocardless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,63 @@ impl
types::PaymentsPreProcessingData,
types::PaymentsResponseData,
> for Gocardless
{
}

impl ConnectorValidation for Gocardless {
fn validate_capture_method(
&self,
capture_method: Option<api_models::enums::CaptureMethod>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
enums::CaptureMethod::Automatic => Ok(()),
enums::CaptureMethod::Manual
| enums::CaptureMethod::ManualMultiple
| enums::CaptureMethod::Scheduled => Err(
connector_utils::construct_not_implemented_error_report(capture_method, self.id()),
),
}
}
}

impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData>
for Gocardless
{
//TODO: implement sessions flow
}

impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken>
for Gocardless
{
}

impl
ConnectorIntegration<
api::SetupMandate,
types::SetupMandateRequestData,
types::PaymentsResponseData,
> for Gocardless
{
fn get_headers(
&self,
req: &types::PaymentsPreProcessingRouterData,
req: &types::SetupMandateRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}

fn get_url(
&self,
_req: &types::PaymentsPreProcessingRouterData,
_req: &types::SetupMandateRouterData,
connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
Ok(format!("{}/mandates", self.base_url(connectors)))
}

fn get_request_body(
&self,
req: &types::PaymentsPreProcessingRouterData,
req: &types::SetupMandateRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let req_obj = gocardless::GocardlessMandateRequest::try_from(req)?;
let gocardless_req = types::RequestBody::log_and_get_request_body(
Expand All @@ -340,24 +377,18 @@ impl

fn build_request(
&self,
req: &types::PaymentsPreProcessingRouterData,
req: &types::SetupMandateRouterData,
connectors: &settings::Connectors,
) -> CustomResult<Option<common_utils::request::Request>, errors::ConnectorError> {
// Preprocessing flow is to create mandate, which should to be called only in case of First mandate
if req.request.setup_mandate_details.is_some() {
Ok(Some(
services::RequestBuilder::new()
.method(services::Method::Post)
.url(&types::PaymentsPreProcessingType::get_url(
self, req, connectors,
)?)
.url(&types::SetupMandateType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::PaymentsPreProcessingType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsPreProcessingType::get_request_body(
self, req,
)?)
.headers(types::SetupMandateType::get_headers(self, req, connectors)?)
.body(types::SetupMandateType::get_request_body(self, req)?)
.build(),
))
} else {
Expand All @@ -367,14 +398,9 @@ impl

fn handle_response(
&self,
data: &types::PaymentsPreProcessingRouterData,
data: &types::SetupMandateRouterData,
res: Response,
) -> CustomResult<types::PaymentsPreProcessingRouterData, errors::ConnectorError>
where
api::PreProcessing: Clone,
types::PaymentsPreProcessingData: Clone,
types::PaymentsResponseData: Clone,
{
) -> CustomResult<types::SetupMandateRouterData, errors::ConnectorError> {
let response: gocardless::GocardlessMandateResponse = res
.response
.parse_struct("GocardlessMandateResponse")
Expand All @@ -394,43 +420,6 @@ impl
}
}

impl ConnectorValidation for Gocardless {
fn validate_capture_method(
&self,
capture_method: Option<api_models::enums::CaptureMethod>,
) -> CustomResult<(), errors::ConnectorError> {
let capture_method = capture_method.unwrap_or_default();
match capture_method {
enums::CaptureMethod::Automatic => Ok(()),
enums::CaptureMethod::Manual
| enums::CaptureMethod::ManualMultiple
| enums::CaptureMethod::Scheduled => Err(
connector_utils::construct_not_implemented_error_report(capture_method, self.id()),
),
}
}
}

impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData>
for Gocardless
{
//TODO: implement sessions flow
}

impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken>
for Gocardless
{
}

impl
ConnectorIntegration<
api::SetupMandate,
types::SetupMandateRequestData,
types::PaymentsResponseData,
> for Gocardless
{
}

impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::PaymentsResponseData>
for Gocardless
{
Expand Down
Loading

0 comments on commit 4149965

Please sign in to comment.