Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(connector): [BOA/CYBS] add cancelled status to refund response #4623

Merged
merged 2 commits into from
May 10, 2024

Conversation

AkshayaFoiger
Copy link
Contributor

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

We faced wrong de-serialization of Rsync response struct due to missing cancelled status
Hotfix for #4620

How did you test it?

Sanity test

  1. Create a payment with BOA
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: ""' \
--data-raw '{
    "amount": 100,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "A",
    "email": "abcdef123@gmail.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "John",
            "last_name": "Doe"
        }
    },
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "13.232.74.226"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "IN",
            "first_name": "John",
            "last_name": "Doe"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number":  "4622943127013705", 
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },    
      "connector_metadata": {
            "noon": {
                "order_category": "pay"
            }
        },
    "metadata": {
        "city": "NY",
        "unit": "245",
        "account_name": "transaction_processing"
    }

}'

Response

{
    "payment_id": "pay_amTC6WtPVyjPOnEt3wzj",
    "merchant_id": "merchant_1715334662",
    "status": "succeeded",
    "amount": 100,
    "net_amount": 100,
    "amount_capturable": 0,
    "amount_received": 100,
    "connector": "bankofamerica",
    "client_secret": "pay_amTC6WtPVyjPOnEt3wzj_secret_BbVhr0K19o2onZMacr3i",
    "created": "2024-05-10T10:11:46.823Z",
    "currency": "USD",
    "customer_id": "A",
    "customer": {
        "id": "A",
        "name": "John Doe",
        "email": "abcdef123@gmail.com",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "3705",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "462294",
            "card_extended_bin": null,
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "avs_response": {
                    "code": "Y",
                    "codeRaw": "Y"
                },
                "card_verification": {
                    "resultCode": "M",
                    "resultCodeRaw": "M"
                },
                "approval_code": "831000",
                "consumer_authentication_response": {
                    "code": "2",
                    "codeRaw": "2"
                },
                "cavv": null,
                "eci": null,
                "eci_raw": null
            },
            "authentication_data": {
                "retrieval_reference_number": "413110157586",
                "acs_transaction_id": null,
                "system_trace_audit_number": "157586"
            }
        },
        "billing": null
    },
    "payment_token": "token_aaIxHAJKyj2H8lSzKZdY",
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "IN",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "John",
            "last_name": "Doe"
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "John",
            "last_name": "Doe"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "abcdef123@gmail.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "A",
        "created_at": 1715335906,
        "expires": 1715339506,
        "secret": "epk_09915eea1c03477fada03e0df4db692b"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "7153359081346288403954",
    "frm_message": null,
    "metadata": {
        "city": "NY",
        "unit": "245",
        "account_name": "transaction_processing"
    },
    "connector_metadata": {
        "apple_pay": null,
        "airwallex": null,
        "noon": {
            "order_category": "pay"
        }
    },
    "feature_metadata": null,
    "reference_id": "pay_amTC6WtPVyjPOnEt3wzj_1",
    "payment_link": null,
    "profile_id": "pro_X1O5OZ5ve8TBBMNSqDbW",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_OJcPQicNRnW6RdXNFogx",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-05-10T10:26:46.823Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "13.232.74.226",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 1536,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 723,
        "java_script_enabled": true
    },
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-05-10T10:11:49.053Z"
}

3.Create a refund with BOA

curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'api-key: ""' \
--data '{
    "payment_id": "pay_amTC6WtPVyjPOnEt3wzj",
    "amount": 10,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

Response

{
    "refund_id": "ref_8vCMk5MCmn7IPOmbsJXt",
    "payment_id": "pay_amTC6WtPVyjPOnEt3wzj",
    "amount": 10,
    "currency": "USD",
    "status": "pending",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-05-10T10:12:13.026Z",
    "updated_at": "2024-05-10T10:12:13.026Z",
    "connector": "bankofamerica",
    "profile_id": "pro_X1O5OZ5ve8TBBMNSqDbW",
    "merchant_connector_id": "mca_OJcPQicNRnW6RdXNFogx"
}

4.Cancel the refund through dashboard
5.Do a Rsync

curl --location 'http://localhost:8080/refunds/ref_8vCMk5MCmn7IPOmbsJXt?force_sync=true' \
--header 'Accept: application/json' \
--header 'api-key: ""'

Response

{
    "refund_id": "ref_8vCMk5MCmn7IPOmbsJXt",
    "payment_id": "pay_amTC6WtPVyjPOnEt3wzj",
    "amount": 10,
    "currency": "USD",
    "status": "failed",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-05-10T10:12:13.026Z",
    "updated_at": "2024-05-10T10:12:13.026Z",
    "connector": "bankofamerica",
    "profile_id": "pro_X1O5OZ5ve8TBBMNSqDbW",
    "merchant_connector_id": "mca_OJcPQicNRnW6RdXNFogx"
}
  1. Create a payment with CYBS
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: ""' \
--data-raw '{
    "amount": 100,
    "currency": "USD",
    "confirm": true,
    "business_country": "US",
    "business_label": "default",
    
    "capture_method": "automatic",
    "customer_id": "A",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "no_three_ds",
    "return_url": "https://hs-payments-test.netlify.app/payments",
    "email": "arjun.karthik@juspay.in",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "setup_future_usage": "off_session",
    "payment_method": "card",
    "payment_method_type": "credit",
    
    "payment_method_data": {
        "card": {
            
            "card_number": "4622943127013705",
            "card_exp_month": "12",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "838"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "CA",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "New York",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "125.0.0.1"
    },
    "metadata": {
        "order_details": {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 3200,
            "account_name": "transaction_processing"
        }
}  
}'

Response

{
    "payment_id": "pay_3hXZKFhfIqsoZtJz7yU2",
    "merchant_id": "merchant_1715337344",
    "status": "succeeded",
    "amount": 100,
    "net_amount": 100,
    "amount_capturable": 0,
    "amount_received": 100,
    "connector": "cybersource",
    "client_secret": "pay_3hXZKFhfIqsoZtJz7yU2_secret_92ln5fpz16mFdL0n05R1",
    "created": "2024-05-10T10:36:04.739Z",
    "currency": "USD",
    "customer_id": "A",
    "customer": {
        "id": "A",
        "name": "John Doe",
        "email": "arjun.karthik@juspay.in",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "3705",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "462294",
            "card_extended_bin": null,
            "card_exp_month": "12",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "avs_response": {
                    "code": "Y",
                    "codeRaw": "Y"
                },
                "card_verification": null
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_RouIJfjjCMaBdOrdFeMD",
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "CA",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "New York",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": "arjun.karthik@juspay.in",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://hs-payments-test.netlify.app/payments",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": "cybersource_US_default_default",
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "A",
        "created_at": 1715337364,
        "expires": 1715340964,
        "secret": "epk_1b20d4f108c047e58f392a69955e94b6"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "7153373660366132603955",
    "frm_message": null,
    "metadata": {
        "order_details": {
            "amount": 3200,
            "quantity": 1,
            "account_name": "transaction_processing",
            "product_name": "Apple iphone 15"
        }
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_3hXZKFhfIqsoZtJz7yU2_1",
    "payment_link": null,
    "profile_id": "pro_kYhx8P60plH6KfkZZhap",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_Vvwn3D8mQbN4FFItLS22",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-05-10T10:51:04.739Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.0.0.1",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 1536,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 723,
        "java_script_enabled": true
    },
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-05-10T10:36:06.755Z"
}
  1. Create a refund
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'api-key: ""' \
--data '{
    "payment_id": "pay_3hXZKFhfIqsoZtJz7yU2",
    "amount": 10,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

Response

{
    "refund_id": "ref_M4Yvpkhi6pZla1q6t3Qo",
    "payment_id": "pay_3hXZKFhfIqsoZtJz7yU2",
    "amount": 10,
    "currency": "USD",
    "status": "pending",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-05-10T10:37:12.605Z",
    "updated_at": "2024-05-10T10:37:12.605Z",
    "connector": "cybersource",
    "profile_id": "pro_kYhx8P60plH6KfkZZhap",
    "merchant_connector_id": "mca_Vvwn3D8mQbN4FFItLS22"
}
  1. Cancel the payment
curl --location 'http://localhost:8080/refunds/ref_M4Yvpkhi6pZla1q6t3Qo?force_sync=true' \
--header 'Accept: application/json' \
--header 'api-key:""'

Response

{
    "refund_id": "ref_M4Yvpkhi6pZla1q6t3Qo",
    "payment_id": "pay_3hXZKFhfIqsoZtJz7yU2",
    "amount": 10,
    "currency": "USD",
    "status": "failed",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "created_at": "2024-05-10T10:12:13.026Z",
    "updated_at": "2024-05-10T10:12:13.026Z",
    "connector": "cybersource",
    "profile_id": "pro_kYhx8P60plH6KfkZZhap",
    "merchant_connector_id": "mca_Vvwn3D8mQbN4FFItLS22"
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@AkshayaFoiger AkshayaFoiger added A-connector-integration Area: Connector integration C-bug Category: Bug labels May 10, 2024
@AkshayaFoiger AkshayaFoiger self-assigned this May 10, 2024
@AkshayaFoiger AkshayaFoiger requested review from a team as code owners May 10, 2024 11:51
@AkshayaFoiger AkshayaFoiger linked an issue May 10, 2024 that may be closed by this pull request
2 tasks
@AkshayaFoiger AkshayaFoiger changed the base branch from main to hotfix-2024.05.03.1 May 10, 2024 11:52
@Gnanasundari24 Gnanasundari24 merged commit c5783bf into hotfix-2024.05.03.1 May 10, 2024
10 of 13 checks passed
@Gnanasundari24 Gnanasundari24 deleted the boa/cybs-cancel branch May 10, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] : Deserialization error due to missing refund status CANCELLED
5 participants