fix(connector): [Paypal] fix PSync for redirection flow for PayPal (#2068)

This commit is contained in:
Prasunna Soppa
2023-09-01 10:50:19 +05:30
committed by GitHub
parent 5b92c39470
commit e730c73516
3 changed files with 44 additions and 2 deletions

View File

@ -569,9 +569,9 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
match data.payment_method {
diesel_models::enums::PaymentMethod::Wallet
| diesel_models::enums::PaymentMethod::BankRedirect => {
let response: paypal::PaypalOrdersResponse = res
let response: paypal::PaypalSyncResponse = res
.response
.parse_struct("paypal PaymentsOrderResponse")
.parse_struct("paypal SyncResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
types::RouterData::try_from(types::ResponseRouterData {
response,
@ -659,6 +659,7 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
.headers(types::PaymentsCaptureType::get_headers(
self, req, connectors,
)?)
.body(types::PaymentsCaptureType::get_request_body(self, req)?)
.build(),
))
}

View File

@ -410,6 +410,13 @@ pub struct PaypalRedirectResponse {
links: Vec<PaypalLinks>,
}
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum PaypalSyncResponse {
PaypalOrdersSyncResponse(PaypalOrdersResponse),
PaypalRedirectSyncResponse(PaypalRedirectResponse),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PaypalPaymentsSyncResponse {
id: String,
@ -535,6 +542,32 @@ fn get_redirect_url(
Ok(link)
}
impl<F, T> TryFrom<types::ResponseRouterData<F, PaypalSyncResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
item: types::ResponseRouterData<F, PaypalSyncResponse, T, types::PaymentsResponseData>,
) -> Result<Self, Self::Error> {
match item.response {
PaypalSyncResponse::PaypalOrdersSyncResponse(response) => {
Self::try_from(types::ResponseRouterData {
response,
data: item.data,
http_code: item.http_code,
})
}
PaypalSyncResponse::PaypalRedirectSyncResponse(response) => {
Self::try_from(types::ResponseRouterData {
response,
data: item.data,
http_code: item.http_code,
})
}
}
}
}
impl<F, T>
TryFrom<types::ResponseRouterData<F, PaypalRedirectResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>