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

refactor(bank-debit): remove billingdetails from bankdebit pmd #4371

Merged
merged 16 commits into from May 8, 2024

Conversation

swangi-kumari
Copy link
Contributor

@swangi-kumari swangi-kumari commented Apr 16, 2024

Type of Change

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

Description

This PR includes changes to use payment_method_data.billing.name and payment_method_data.billing.email and payment_method_data.billing_addressinstead of payment_method_data.[BankDebit->AchBankDebit].BankDebitBilling and payment_method_data.[BankDebit->AchBankDebit].bank_account_holder_name at the connector level. The backwards compatibility is provided.

Additional Changes

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

Motivation and Context

How did you test it?

  1. Create a ach direct debit Payment Request via Stripe
{
    "amount": 1800,
    "currency": "USD",
    "confirm": true,
    "business_label": "default",
    "capture_method": "automatic",
    "connector": [
        "stripe"
    ],
    "customer_id": "klarna",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "email": "guest@example.com",
    "name": "JohnDoe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Itsmyfirstpaymentrequest",
    "return_url": "https://google.com",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "setup_future_usage": "off_session",
    "business_country": "US",
    "mandate_data": {
        "customer_acceptance": {
            "acceptance_type": "online",
            "accepted_at": "2022-09-10T10:11:12Z",
            "online": {
                "ip_address": "123.32.25.123",
                "user_agent": "Mozilla/5.0(Linux;Android12;SM-S906NBuild/QP1A.190711.020;wv)AppleWebKit/537.36(KHTML,likeGecko)Version/4.0Chrome/80.0.3987.119MobileSafari/537.36"
            }
        },
        "mandate_type": {
            "single_use": {
                "amount": 6540,
                "currency": "USD"
            }
        }
    },
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "2022-09-10T10:11:12Z",
        "online": {
            "ip_address": "123.32.25.123",
            "user_agent": "Mozilla/5.0(Linux;Android12;SM-S906NBuild/QP1A.190711.020;wv)AppleWebKit/537.36(KHTML,likeGecko)Version/4.0Chrome/80.0.3987.119MobileSafari/537.36"
        }
    },
    "payment_method": "bank_debit",
    "payment_method_type": "ach",
    "payment_method_data": {
        "bank_debit": {
            "ach_bank_debit": {
                "billing_details": {
                    "name": "JohnDoe",
                    "email": "johndoe@example.com"
                },
                "account_number": "000123456789",
                "routing_number": "110000000"
            }
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "HarrisonStreet",
            "line3": "HarrisonStreet",
            "city": "SanFransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "Swangi",
            "last_name": "Kumari"
        }
    },
    "metadata": {
        "order_details": {
            "product_name": "Appleiphone15",
            "quantity": 1,
            "amount": 1800,
            "account_name": "transaction_processing"
        }
    },
    "routing": {
        "type": "single",
        "data": "stripe"
    }
}

Response

{
    "payment_id": "pay_Rr2bSD8MTT9kFjBsk7Dl",
    "merchant_id": "postman_merchant_GHAction_e8088ef4-bab7-4490-b0ec-a17097a8766c",
    "status": "requires_customer_action",
    "amount": 1800,
    "net_amount": 1800,
    "amount_capturable": 1800,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_Rr2bSD8MTT9kFjBsk7Dl_secret_H6xeQXge0UqXXOFjL7j7",
    "created": "2024-04-17T11:14:31.673Z",
    "currency": "USD",
    "customer_id": "klarna",
    "customer": {
        "id": "klarna",
        "name": "JohnDoe",
        "email": "guest@example.com",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Itsmyfirstpaymentrequest",
    "refunds": null,
    "disputes": null,
    "mandate_id": "man_ZIa62zYZtbamtjzmZWNY",
    "mandate_data": {
        "update_mandate_id": null,
        "customer_acceptance": {
            "acceptance_type": "online",
            "accepted_at": "2022-09-10T10:11:12.000Z",
            "online": {
                "ip_address": "123.32.25.123",
                "user_agent": "Mozilla/5.0(Linux;Android12;SM-S906NBuild/QP1A.190711.020;wv)AppleWebKit/537.36(KHTML,likeGecko)Version/4.0Chrome/80.0.3987.119MobileSafari/537.36"
            }
        },
        "mandate_type": {
            "single_use": {
                "amount": 6540,
                "currency": "USD",
                "start_date": null,
                "end_date": null,
                "metadata": null
            }
        }
    },
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "bank_debit",
    "payment_method_data": {
        "bank_debit": {},
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "SanFransico",
            "country": "US",
            "line1": "1467",
            "line2": "HarrisonStreet",
            "line3": "HarrisonStreet",
            "zip": "94122",
            "state": "California",
            "first_name": "Swangi",
            "last_name": "Kumari"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": "JohnDoe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_Rr2bSD8MTT9kFjBsk7Dl/postman_merchant_GHAction_e8088ef4-bab7-4490-b0ec-a17097a8766c/pay_Rr2bSD8MTT9kFjBsk7Dl_1"
    },
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "ach",
    "connector_label": "stripe_US_default",
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "klarna",
        "created_at": 1713352471,
        "expires": 1713356071,
        "secret": "epk_37877d6d4ba940138babac48669aae38"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "pi_3P6WRhD5R7gDAGff1rVWlAtF",
    "frm_message": null,
    "metadata": {
        "order_details": {
            "amount": 1800,
            "quantity": 1,
            "account_name": "transaction_processing",
            "product_name": "Appleiphone15"
        }
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3P6WRhD5R7gDAGff1rVWlAtF",
    "payment_link": null,
    "profile_id": "pro_Rknhbk9rtqTWVKr4Xe8W",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_GlDUpuIsNCd9fOw0ReKW",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-17T11:29:31.673Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": "pm_b31KdndV2QW9Mdeyyc9U",
    "payment_method_status": null,
    "updated": "2024-04-17T11:14:33.918Z"
}

  1. Create a ACH Payment Request via Adyen
{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "bank_debit",
    "payment_method_type": "ach",
    "payment_method_data": {
        "bank_debit": {
            "ach_bank_debit":{
                "account_number": "1234567890",
                "routing_number" : "121000358"
            }
        }
    },
    "routing": {
        "type": "single",
        "data": "adyen"
    },
    "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"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "profile_id": "pro_16j8JOCurimvr2XXG9EE"
}

Response:

{
    "payment_id": "pay_G8ozQAqdHGvjuyJHWB6u",
    "merchant_id": "merchant_1713352560",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "adyen",
    "client_secret": "pay_G8ozQAqdHGvjuyJHWB6u_secret_gvMEAeEEX6K5OpiltMJP",
    "created": "2024-04-17T12:01:14.760Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "customer": {
        "id": "StripeCustomer",
        "name": "John Doe",
        "email": "guest@example.com",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "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": "bank_debit",
    "payment_method_data": {
        "bank_debit": {},
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": null
        },
        "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": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://duck.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": "ach",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "StripeCustomer",
        "created_at": 1713355274,
        "expires": 1713358874,
        "secret": "epk_2dda0effe72e4397bae9a482f545ff27"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "H9DGFT4FBGKV9ST5",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_G8ozQAqdHGvjuyJHWB6u_1",
    "payment_link": null,
    "profile_id": "pro_nSMRYk7KBM3KvtxFfHJj",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_sAeAHHYq9vjnr1LQd3oL",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-17T12:16:14.760Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-04-17T12:01:16.239Z"
}

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
  • I added a CHANGELOG entry if applicable

@swangi-kumari swangi-kumari added A-connector-compatibility Area: Connector compatibility A-connector-integration Area: Connector integration labels Apr 16, 2024
@swangi-kumari swangi-kumari self-assigned this Apr 16, 2024
@swangi-kumari swangi-kumari marked this pull request as ready for review April 17, 2024 12:02
@swangi-kumari swangi-kumari requested review from a team as code owners April 17, 2024 12:02
.and_then(|billing_details| billing_details.address.as_ref())
.and_then(|billing_address| billing_address.get_optional_full_name())
.ok_or_else(missing_field_err(
"payment_method_data.billing.address.full_name",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"payment_method_data.billing.address.full_name",
"payment_method_data.billing.address.first_name",

address.first_name = bank_account_holder_name
.or(address.first_name.as_ref())
.cloned();
address = address.map(|mut address| -> Address {
Copy link
Member

Choose a reason for hiding this comment

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

why is this changed?

}?;

let billing_details_name = billing_details.name.expose();
let billing_details_name = item.get_billing_full_name()?.expose();
Copy link
Member

Choose a reason for hiding this comment

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

This should be a secret only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are converting it back to secret while returning.

/// The billing address for bank debits
pub address: Option<AddressDetails>,
}

impl GetAddressFromPaymentMethodData for BankDebitBilling {
fn get_billing_address(&self) -> Option<Address> {
let address = if let Some(mut address) = self.address.clone() {
address.first_name = Some(self.name.clone());
address.first_name = self.name.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Here, what if self.name is none, won't we be overriding the value of address.first_name? Instead you can put an or() and then consider address.first_name. Something like this

address.first_name = self.name.clone().or(address.first_name)

@likhinbopanna likhinbopanna added this pull request to the merge queue May 8, 2024
Merged via the queue into main with commit 625b531 May 8, 2024
9 of 12 checks passed
@likhinbopanna likhinbopanna deleted the bank-debit-billing branch May 8, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-compatibility Area: Connector compatibility A-connector-integration Area: Connector integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants