feat(core): accept gateway credentials in the request body in payments and refunds (#766)

This commit is contained in:
Abhishek
2023-03-21 14:37:41 +05:30
committed by GitHub
parent d302b286b8
commit cb188f92a6
35 changed files with 748 additions and 130 deletions

View File

@ -125,7 +125,7 @@ impl ConnectorCommon for Fiserv {
code: first_error
.code
.to_owned()
.unwrap_or(consts::NO_ERROR_CODE.to_string()),
.unwrap_or_else(|| consts::NO_ERROR_CODE.to_string()),
message: first_error.message.to_owned(),
reason: first_error.field.to_owned(),
status_code: res.status_code,

View File

@ -531,7 +531,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
.request
.connector_refund_id
.to_owned()
.ok_or_else(|| errors::ConnectorError::MissingConnectorRefundID)?;
.ok_or(errors::ConnectorError::MissingConnectorRefundID)?;
match req.payment_method {
storage_models::enums::PaymentMethod::BankRedirect => Ok(format!(
"{}{}/{}",

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
use api_models::payments::BankRedirectData;
use common_utils::{errors::CustomResult, pii::Email};
use error_stack::ResultExt;
use error_stack::{IntoReport, ResultExt};
use masking::Secret;
use reqwest::Url;
use serde::{Deserialize, Serialize};
@ -297,7 +297,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for TrustpayPaymentsRequest {
utils::to_currency_base_unit(item.request.amount, item.request.currency)?
.parse::<f64>()
.ok()
.ok_or_else(|| errors::ConnectorError::RequestEncodingFailed)?
.ok_or(errors::ConnectorError::RequestEncodingFailed)?
);
let auth = TrustpayAuthType::try_from(&item.connector_auth_type)
.change_context(errors::ConnectorError::FailedToObtainAuthType)?;
@ -556,9 +556,7 @@ fn handle_cards_response(
response.payment_status.as_str(),
response.redirect_url.clone(),
)?;
let form_fields = response
.redirect_params
.unwrap_or(std::collections::HashMap::new());
let form_fields = response.redirect_params.unwrap_or_default();
let redirection_data = response.redirect_url.map(|url| services::RedirectForm {
endpoint: url.to_string(),
method: services::Method::Post,
@ -567,7 +565,7 @@ fn handle_cards_response(
let error = if msg.is_some() {
Some(types::ErrorResponse {
code: response.payment_status,
message: msg.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
message: msg.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: None,
status_code,
})
@ -626,7 +624,7 @@ fn handle_bank_redirects_error_response(
message: response
.payment_result_info
.additional_info
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: None,
status_code,
});
@ -661,7 +659,7 @@ fn handle_bank_redirects_sync_response(
message: reason_info
.reason
.reject_reason
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: None,
status_code,
})
@ -786,7 +784,7 @@ impl<F, T> TryFrom<types::ResponseRouterData<F, TrustpayAuthUpdateResponse, T, t
.response
.result_info
.additional_info
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: None,
status_code: item.http_code,
}),
@ -826,8 +824,8 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for TrustpayRefundRequest {
"{:.2}",
utils::to_currency_base_unit(item.request.amount, item.request.currency)?
.parse::<f64>()
.ok()
.ok_or_else(|| errors::ConnectorError::RequestEncodingFailed)?
.into_report()
.change_context(errors::ConnectorError::RequestEncodingFailed)?
);
match item.payment_method {
storage_models::enums::PaymentMethod::BankRedirect => {
@ -896,7 +894,7 @@ fn handle_cards_refund_response(
let error = if msg.is_some() {
Some(types::ErrorResponse {
code: response.payment_status,
message: msg.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
message: msg.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: None,
status_code,
})
@ -962,7 +960,7 @@ fn handle_bank_redirects_refund_sync_response(
message: reason_info
.reason
.reject_reason
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: None,
status_code,
})
@ -985,7 +983,7 @@ fn handle_bank_redirects_refund_sync_error_response(
message: response
.payment_result_info
.additional_info
.unwrap_or(consts::NO_ERROR_MESSAGE.to_owned()),
.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_owned()),
reason: None,
status_code,
});