mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
fix(connector): [Airwallex] Change Session Token to Init Payment (#798)
This commit is contained in:
@ -172,14 +172,14 @@ impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, t
|
||||
|
||||
impl
|
||||
ConnectorIntegration<
|
||||
api::AuthorizeSessionToken,
|
||||
types::AuthorizeSessionTokenData,
|
||||
api::InitPayment,
|
||||
types::PaymentsAuthorizeData,
|
||||
types::PaymentsResponseData,
|
||||
> for Airwallex
|
||||
{
|
||||
fn get_headers(
|
||||
&self,
|
||||
req: &types::PaymentsAuthorizeSessionTokenRouterData,
|
||||
req: &types::PaymentsInitRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> {
|
||||
self.build_headers(req, connectors)
|
||||
@ -191,7 +191,7 @@ impl
|
||||
|
||||
fn get_url(
|
||||
&self,
|
||||
_req: &types::PaymentsAuthorizeSessionTokenRouterData,
|
||||
_req: &types::PaymentsInitRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
Ok(format!(
|
||||
@ -203,7 +203,7 @@ impl
|
||||
|
||||
fn get_request_body(
|
||||
&self,
|
||||
req: &types::PaymentsAuthorizeSessionTokenRouterData,
|
||||
req: &types::PaymentsInitRouterData,
|
||||
) -> CustomResult<Option<String>, errors::ConnectorError> {
|
||||
let req_obj = airwallex::AirwallexIntentRequest::try_from(req)?;
|
||||
let req =
|
||||
@ -214,46 +214,24 @@ impl
|
||||
|
||||
fn build_request(
|
||||
&self,
|
||||
req: &types::PaymentsAuthorizeSessionTokenRouterData,
|
||||
req: &types::PaymentsInitRouterData,
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
|
||||
Ok(Some(
|
||||
services::RequestBuilder::new()
|
||||
.method(services::Method::Post)
|
||||
.url(&types::PaymentsPreAuthorizeType::get_url(
|
||||
self, req, connectors,
|
||||
)?)
|
||||
.headers(types::PaymentsPreAuthorizeType::get_headers(
|
||||
self, req, connectors,
|
||||
)?)
|
||||
.body(types::PaymentsPreAuthorizeType::get_request_body(
|
||||
self, req,
|
||||
)?)
|
||||
.url(&types::PaymentsInitType::get_url(self, req, connectors)?)
|
||||
.headers(types::PaymentsInitType::get_headers(self, req, connectors)?)
|
||||
.body(types::PaymentsInitType::get_request_body(self, req)?)
|
||||
.build(),
|
||||
))
|
||||
}
|
||||
|
||||
fn handle_response(
|
||||
&self,
|
||||
data: &RouterData<
|
||||
api::AuthorizeSessionToken,
|
||||
types::AuthorizeSessionTokenData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
data: &types::PaymentsInitRouterData,
|
||||
res: Response,
|
||||
) -> CustomResult<
|
||||
RouterData<
|
||||
api::AuthorizeSessionToken,
|
||||
types::AuthorizeSessionTokenData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
errors::ConnectorError,
|
||||
>
|
||||
where
|
||||
api::AuthorizeSessionToken: Clone,
|
||||
types::AuthorizeSessionTokenData: Clone,
|
||||
types::PaymentsResponseData: Clone,
|
||||
{
|
||||
) -> CustomResult<types::PaymentsInitRouterData, errors::ConnectorError> {
|
||||
let response: airwallex::AirwallexPaymentsResponse = res
|
||||
.response
|
||||
.parse_struct("airwallex AirwallexPaymentsResponse")
|
||||
@ -289,17 +267,15 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
||||
) -> CustomResult<(), errors::ConnectorError> {
|
||||
let integ: Box<
|
||||
&(dyn ConnectorIntegration<
|
||||
api::AuthorizeSessionToken,
|
||||
types::AuthorizeSessionTokenData,
|
||||
api::InitPayment,
|
||||
types::PaymentsAuthorizeData,
|
||||
types::PaymentsResponseData,
|
||||
> + Send
|
||||
+ Sync
|
||||
+ 'static),
|
||||
> = Box::new(&Self);
|
||||
let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::from((
|
||||
&router_data,
|
||||
types::AuthorizeSessionTokenData::from(&router_data),
|
||||
));
|
||||
let authorize_data =
|
||||
&types::PaymentsInitRouterData::from((&router_data, router_data.request.clone()));
|
||||
let resp = services::execute_connector_processing_step(
|
||||
app_state,
|
||||
integ,
|
||||
|
||||
@ -20,11 +20,9 @@ pub struct AirwallexIntentRequest {
|
||||
//ID created in merchant's order system that corresponds to this PaymentIntent.
|
||||
merchant_order_id: String,
|
||||
}
|
||||
impl TryFrom<&types::PaymentsAuthorizeSessionTokenRouterData> for AirwallexIntentRequest {
|
||||
impl TryFrom<&types::PaymentsInitRouterData> for AirwallexIntentRequest {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: &types::PaymentsAuthorizeSessionTokenRouterData,
|
||||
) -> Result<Self, Self::Error> {
|
||||
fn try_from(item: &types::PaymentsInitRouterData) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
request_id: Uuid::new_v4().to_string(),
|
||||
amount: utils::to_currency_base_unit(item.request.amount, item.request.currency)?,
|
||||
@ -390,6 +388,5 @@ pub struct AirwallexWebhookObjectResource {
|
||||
pub struct AirwallexErrorResponse {
|
||||
pub code: String,
|
||||
pub message: String,
|
||||
pub details: Option<Vec<String>>,
|
||||
pub source: Option<String>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user