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

View File

@ -410,6 +410,13 @@ pub struct PaypalRedirectResponse {
links: Vec<PaypalLinks>, links: Vec<PaypalLinks>,
} }
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum PaypalSyncResponse {
PaypalOrdersSyncResponse(PaypalOrdersResponse),
PaypalRedirectSyncResponse(PaypalRedirectResponse),
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct PaypalPaymentsSyncResponse { pub struct PaypalPaymentsSyncResponse {
id: String, id: String,
@ -535,6 +542,32 @@ fn get_redirect_url(
Ok(link) 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> impl<F, T>
TryFrom<types::ResponseRouterData<F, PaypalRedirectResponse, T, types::PaymentsResponseData>> TryFrom<types::ResponseRouterData<F, PaypalRedirectResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData> for types::RouterData<F, T, types::PaymentsResponseData>

View File

@ -175,6 +175,7 @@ async fn should_void_authorized_payment() {
// Refunds a payment using the manual capture flow (Non 3DS). // Refunds a payment using the manual capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_refund_manually_captured_payment() { async fn should_refund_manually_captured_payment() {
let authorize_response = CONNECTOR let authorize_response = CONNECTOR
.authorize_payment(get_payment_data(), get_default_payment_info()) .authorize_payment(get_payment_data(), get_default_payment_info())
@ -213,6 +214,7 @@ async fn should_refund_manually_captured_payment() {
// Partially refunds a payment using the manual capture flow (Non 3DS). // Partially refunds a payment using the manual capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_partially_refund_manually_captured_payment() { async fn should_partially_refund_manually_captured_payment() {
let authorize_response = CONNECTOR let authorize_response = CONNECTOR
.authorize_payment(get_payment_data(), get_default_payment_info()) .authorize_payment(get_payment_data(), get_default_payment_info())
@ -252,6 +254,7 @@ async fn should_partially_refund_manually_captured_payment() {
// Synchronizes a refund using the manual capture flow (Non 3DS). // Synchronizes a refund using the manual capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_sync_manually_captured_refund() { async fn should_sync_manually_captured_refund() {
let authorize_response = CONNECTOR let authorize_response = CONNECTOR
.authorize_payment(get_payment_data(), get_default_payment_info()) .authorize_payment(get_payment_data(), get_default_payment_info())
@ -343,6 +346,7 @@ async fn should_sync_auto_captured_payment() {
// Refunds a payment using the automatic capture flow (Non 3DS). // Refunds a payment using the automatic capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_refund_auto_captured_payment() { async fn should_refund_auto_captured_payment() {
let response = CONNECTOR let response = CONNECTOR
.make_payment_and_refund(get_payment_data(), None, get_default_payment_info()) .make_payment_and_refund(get_payment_data(), None, get_default_payment_info())
@ -356,6 +360,7 @@ async fn should_refund_auto_captured_payment() {
// Partially refunds a payment using the automatic capture flow (Non 3DS). // Partially refunds a payment using the automatic capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_partially_refund_succeeded_payment() { async fn should_partially_refund_succeeded_payment() {
let authorize_response = CONNECTOR let authorize_response = CONNECTOR
.make_payment(get_payment_data(), get_default_payment_info()) .make_payment(get_payment_data(), get_default_payment_info())
@ -382,6 +387,7 @@ async fn should_partially_refund_succeeded_payment() {
// Creates multiple refunds against a payment using the automatic capture flow (Non 3DS). // Creates multiple refunds against a payment using the automatic capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_refund_succeeded_payment_multiple_times() { async fn should_refund_succeeded_payment_multiple_times() {
let authorize_response = CONNECTOR let authorize_response = CONNECTOR
.make_payment(get_payment_data(), get_default_payment_info()) .make_payment(get_payment_data(), get_default_payment_info())
@ -410,6 +416,7 @@ async fn should_refund_succeeded_payment_multiple_times() {
// Synchronizes a refund using the automatic capture flow (Non 3DS). // Synchronizes a refund using the automatic capture flow (Non 3DS).
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_sync_refund() { async fn should_sync_refund() {
let refund_response = CONNECTOR let refund_response = CONNECTOR
.make_payment_and_refund(get_payment_data(), None, get_default_payment_info()) .make_payment_and_refund(get_payment_data(), None, get_default_payment_info())
@ -585,6 +592,7 @@ async fn should_fail_capture_for_invalid_payment() {
// Refunds a payment with refund amount higher than payment amount. // Refunds a payment with refund amount higher than payment amount.
#[actix_web::test] #[actix_web::test]
#[ignore = "Since Payment status is in pending status, cannot refund"]
async fn should_fail_for_refund_amount_higher_than_payment_amount() { async fn should_fail_for_refund_amount_higher_than_payment_amount() {
let authorize_response = CONNECTOR let authorize_response = CONNECTOR
.make_payment(get_payment_data(), get_default_payment_info()) .make_payment(get_payment_data(), get_default_payment_info())