Skip to content

chore(connector): [paypal] store paypal email and payer_id in payment_method_data - #13902

Open
Nithin1506200 wants to merge 6 commits into
mainfrom
paypal-payment-method-data
Open

chore(connector): [paypal] store paypal email and payer_id in payment_method_data#13902
Nithin1506200 wants to merge 6 commits into
mainfrom
paypal-payment-method-data

Conversation

@Nithin1506200

Copy link
Copy Markdown
Contributor

Type of Change

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

Description

For PayPal wallet payments (payment_method_type = paypal), the payer details (email, payer_id) returned by PayPal in the payer object of the authorize / capture / sync responses were being dropped. This PR stores them (encrypted) in the payment attempt's additional payment method data and surfaces them in the Payments response under payment_method_data.wallet.paypal.

Changes:

  • paypal/transformers.rs: Parse email_address in the PayPal Payer response struct. Populate AdditionalPaymentMethodConnectorResponse::Paypal { email, payer_id } in the authorize, capture and payments-sync flows via get_connector_response_with_payer_details, only when payment_method_type is Paypal (PaypalRedirect / PaypalSdk wallet flows) — card payments processed via PayPal as a card processor are unaffected.
  • hyperswitch_domain_models/router_data.rs: Added AdditionalPaymentMethodConnectorResponse::Paypal { email, payer_id } variant.
  • api_models: Added PaypalWalletAdditionalData { email, payer_id }, a paypal field in AdditionalPaymentData::Wallet, and a WalletResponseData::Paypal variant so the details appear in the payments response.
  • common_enums / payment_attempt: is_additional_payment_method_data_sensitive now also considers payment_method_type; wallet + paypal data is treated as sensitive (it contains PII — email and a unique payer identifier) and is therefore stored in encrypted_payment_method_data.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

The PayPal payer's email and payer_id are required by merchants for reconciliation, customer support and to link the payment with the payer's PayPal account. These were previously discarded after the connector call.

How did you test it?

Tested manually via API calls (local server with PayPal sandbox):

1. Create a PayPal wallet payment (confirm = true)

Request:

{
    "customer_id": "{{customer_id}}",
    "currency": "USD",
    "amount": 13,
    "confirm": true,
    "payment_method": "wallet",
    "payment_method_type": "paypal",
    "capture_method": "automatic",
    "payment_method_data": {
        "wallet": {
            "paypal_redirect": {
                "email": null
            }
        },
        "billing": {
            "phone": {
                "number": "9898989898",
                "country_code": "+44"
            }
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "return_url": "https://www.google.com",
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "email": "something@example.com"
}

Response — payment moves to requires_customer_action, wallet details are not yet available:

{
    "payment_id": "pay_2PmYDAP6mGkY533NzJtt",
    "status": "requires_customer_action",
    "amount": 13,
    "connector": "paypal",
    "payment_method": "wallet",
    "payment_method_type": "paypal",
    "payment_method_data": {
        "wallet": {},
        "billing": {
            "phone": {
                "number": "9898989898",
                "country_code": "+44"
            }
        }
    },
    "connector_transaction_id": "4G055721XP1572322",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_2PmYDAP6mGkY533NzJtt/merchant_1787645676/pay_2PmYDAP6mGkY533NzJtt_1"
    }
}

2. Complete the PayPal redirect (login + approve) and retrieve the payment

Response — payment succeeded, and payment_method_data.wallet.paypal now contains the payer's email and payer_id (also stored as sender_payment_instrument_id):

{
    "payment_id": "pay_2PmYDAP6mGkY533NzJtt",
    "status": "succeeded",
    "amount": 13,
    "amount_received": 13,
    "connector": "paypal",
    "payment_method": "wallet",
    "payment_method_type": "paypal",
    "payment_method_data": {
        "wallet": {
            "paypal": {
                "email": "bernard.eugine@juspay.in",
                "payer_id": "RRFL3BGBVCH94"
            }
        },
        "billing": {
            "phone": {
                "number": "9898989898",
                "country_code": "+44"
            }
        }
    },
    "connector_transaction_id": "4G055721XP1572322",
    "payment_method_id": "pm_ehNoDlUSQcjmMT5Ju6B5",
    "payment_method_status": "active",
    "sender_payment_instrument_id": "RRFL3BGBVCH94"
}

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

@Nithin1506200
Nithin1506200 requested review from a team as code owners August 28, 2026 10:14
@hyperswitch-bot hyperswitch-bot Bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 28, 2026
@Nithin1506200 Nithin1506200 self-assigned this Aug 28, 2026
@Nithin1506200 Nithin1506200 added the S-test-ready Status: This PR is ready for cypress-tests label Aug 28, 2026
Sakilmostak
Sakilmostak previously approved these changes Aug 28, 2026

@deepanshu-iiitu deepanshu-iiitu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connector changes look good

Comment thread crates/api_models/src/payments.rs Outdated
@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants