Skip to content

CreateAccountExternalAccount::new Should Support BankAccount Type for external_account #695

Open
@itsbalamurali

Description

@itsbalamurali

Describe the bug

Issue: CreateAccountExternalAccount::new Should Support BankAccount Type for external_account

Description:

The Stripe API supports passing a BankAccount type directly for the external_account parameter. However, the async-stripe crate currently requires external_account to be of type String, which does not align with the API's capabilities. This limitation forces developers to handle serialization manually, even though the API natively supports structured types like BankAccount.

Expected Behavior:

The CreateAccountExternalAccount::new method should accept the external_account parameter as a BankAccount type directly, allowing developers to pass a BankAccount object without additional steps.

Current Behavior:

The method signature currently looks like this:

pub fn new(account_id: String, external_account: String) -> Self

This requires the external_account to be passed as a String, even when working with a BankAccount.

Suggested Change:

Update the method signature to:

pub fn new(account_id: String, external_account: BankAccount) -> Self

This change would allow the method to accept a BankAccount object directly, aligning the library with the Stripe API's capabilities.

Benefits:

  • Simplifies the API for developers.
  • Removes the need for manual serialization.
  • Aligns the library with the Stripe API's native support for BankAccount.

Additional Context:

This issue was encountered while attempting to create an external bank account using the async-stripe crate. The current implementation adds unnecessary complexity, despite the Stripe API supporting structured types like BankAccount.

To Reproduce

Steps to Reproduce the Behavior

  1. Set up a new Rust project and add the async-stripe crate as a dependency in your Cargo.toml.
  2. Initialize a Stripe Client with a valid secret key.
  3. Create a BankAccount object and attempt to use it as the external_account parameter in the CreateAccountExternalAccount::new method.
  4. Observe that the method requires external_account to be of type String instead of BankAccount.
  5. Attempt to send the request using the send method and note the additional complexity caused by the type mismatch.

Expected behavior

The CreateAccountExternalAccount::new method should accept the external_account parameter as a BankAccount type directly, as supported by the Stripe API. This would allow developers to pass a BankAccount object without requiring additional conversions or workarounds, simplifying the process and aligning the library with the API's capabilities.

Code snippets

use stripe::Client;
use stripe_connect::*;
use stripe_connect::account::*;
use stripe_connect::account_session::*;
use stripe_connect::external_account::CreateAccountExternalAccount;
use stripe_shared::BankAccount;
use stripe_types::*;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let secret_key = "YOUR_SECRET_KEY";
    
    let client = Client::new(secret_key);
    let create_account = CreateAccount::new();
    let mut create_business_profile = CreateAccountBusinessProfile::new();
    create_business_profile.product_description = Some("".to_string());
    create_business_profile.url = Some("".to_string());
    create_business_profile.name = Some("".to_string());
    create_business_profile.support_url = Some("".to_string());
    create_business_profile.support_email = Some("".to_string());
    create_business_profile.support_phone = Some("".to_string());
    let mut business_address = CreateAccountBusinessProfileSupportAddress::new();
    business_address.line1 = Some("".to_string());
    business_address.line2 = Some("".to_string());
    business_address.city = Some("".to_string());
    business_address.country = Some("".to_string());
    business_address.postal_code = Some("".to_string());
    create_business_profile.support_address = Some(business_address);
    let create_account = create_account.business_profile(create_business_profile);
    let mut account_capabilities = CapabilitiesParam::new();
    let mut cap_param = CapabilityParam::new();
    cap_param.requested = Some(true);
    account_capabilities.card_payments = Some(cap_param);
    let mut controller = CreateAccountController::new();
    controller.requirement_collection = Some(CreateAccountControllerRequirementCollection::Application);
    let create_account = create_account.controller(controller);
    let create_account = create_account.default_currency(Currency::EUR);
    let create_account =  create_account.capabilities(account_capabilities);

    // If Company
    let create_account = create_account.business_type(AccountBusinessType::Company);
    let mut create_company = CreateAccountCompany::new();
    create_company.name = Some("".to_string());
    create_company.registration_number = Some("".to_string());
    let registration_date = RegistrationDateSpecs::new(07,02,1994);
    create_company.registration_date = Some(registration_date);
    create_company.phone = Some("".to_string());
    create_company.tax_id = Some("".to_string());
    create_company.tax_id_registrar = Some("".to_string());
    create_company.vat_id = Some("".to_string());
    
    let mut create_company_address = CreateAccountCompanyAddress::new();
    create_company_address.line1 = Some("".to_string());
    create_company_address.postal_code = Some("".to_string());
    create_company_address.city = Some("".to_string());
    create_company_address.state = Some("".to_string());
    create_company_address.country = Some("".to_string());
    create_company.address = Some(create_company_address);
    
    
    
    let create_account = create_account.company(create_company);
    
    // If Individual
    let mut create_individual = CreateAccountIndividual::new();
    create_individual.first_name = Some("".to_string());
    create_individual.last_name = Some("".to_string());
    create_individual.email = Some("".to_string());
    create_individual.phone = Some("".to_string());
    create_individual.gender = Some("".to_string());
    create_individual.id_number = Some("".to_string());
    
    
    let create_account = create_account.individual(create_individual);
    let account = create_account.send(&client).await?;
    println!("created a account {}", account.id);
    
    let account_id = account.id;
    // Create Account Session
    let mut session_components = CreateAccountSessionComponents::new();
    session_components.account_management = Some(AccountConfigParam::new(false));
    session_components.tax_registrations = Some(BaseConfigParam::new(false));
    session_components.tax_settings = Some(BaseConfigParam::new(false));
    session_components.issuing_card = Some(CreateAccountSessionComponentsIssuingCard::new(false));
    session_components.account_onboarding = Some(AccountConfigParam::new(false));
    let create_account_session = CreateAccountSession::new(account_id.to_owned(),session_components);
    let account_session = create_account_session.send(&client).await?;
    println!("created an account session: {}", account_session.client_secret);
    
    //Create External Account (Bank Account)
    let mut bank_account = BankAccount{}; 
    let external_account = ExternalAccount::BankAccount(bank_account);
    let create_bank_account = CreateAccountExternalAccount::new(account_id.to_owned(),external_account); // Problem here.....
    create_bank_account.send(&client).await?;
    Ok(())
}

OS

macOS

Rust version

1.86.0

Library version

async-stripe 1.0.0-alpha.2

API version

2023-10-16

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions