douglasrcjames
douglasrcjames

Reputation: 1665

Stripe : Error: Received unknown parameter: bank_account[bank_name]

I have been trying to add a bank_name to my Stripe Connect user's external account, but I keep getting an error as if I am misreading the documentation on the function.

Error: Received unknown parameter: bank_account[bank_name]

The documentation shows that I should be able to access the bank_name from the bank_account object, but my error is narrowed down to it being null. My console.log(newValue.externalAccount.bankName) returns the bankName as expected that was entered, so it isn't null going in. Any idea why I am getting this error?

Firebase Function:

exports.createStripeAccount = functions.firestore
  .document("users/{userId}")
  .onUpdate(async (change, context) => {
    const newValue = change.after.data();
    const previousValue = change.before.data();
    if (newValue.state === "technician" && previousValue.state === "client") {
      try {
        const account_add_response = await stripe.accounts.create(
          {
            type: "custom",
            country: "US",
            requested_capabilities: ["platform_payments"],
            email: newValue.email,
            tos_acceptance: newValue.stripeTosAcceptance,
            business_type: "individual",
            business_profile: {
              url: newValue.socialLinks.linkedin
            },
            individual: {
              first_name: newValue.firstName,
              last_name: newValue.lastName,
              gender: newValue.gender,
              email: newValue.email,
              phone: newValue.phone,
              address: {
                line1: newValue.address.line1,
                line2: newValue.address.line2,
                city: newValue.address.city,
                state: newValue.address.state,
                postal_code: newValue.address.zip,
                country: newValue.address.country
              },
              ssn_last_4: newValue.technician.ssnLast4,
              dob: {
                day: newValue.dob.day,
                month: newValue.dob.month,
                year: newValue.dob.year
              }
            }
          },
          async function(error, account) {
            if (error) {
              return console.error(error);
            } else {
              console.log(
                "Writing account.id " + account.id + " to user DB..."
              );
              console.log("newValue.externalAccount.bankName: " + newValue.externalAccount.bankName)
              const bank_add_response = await stripe.accounts.createExternalAccount(
                account.id,
                {
                  external_account: {
                    object: "bank_account",
                    country: "US",
                    currency: "USD",
                    account_holder_name:
                      newValue.externalAccount.accountHolderName, // Have user input manually, might be different than user's name
                    account_holder_type: "individual",
                    bank_name: newValue.externalAccount.bankName,
                    routing_number: newValue.externalAccount.routingNumber,
                    account_number: newValue.externalAccount.accountNumber
                  }
                },
                function(error, bank_account) {
                  if (error) {
                    return console.error(error);
                  } else {
                    console.log(
                      "Writing bank_account.id " +
                        bank_account.id +
                        " to user DB..."
                    );
                    return admin
                      .firestore()
                      .collection("users")
                      .doc(context.params.userId)
                      .set(
                        {
                          connectId: account.id,
                          externalAccount: {
                            bankAccountId: bank_account.id,
                            bankName: bank_account.bank_name,
                            last4: bank_account.last4,
                          }
                        },
                        { merge: true }
                      );
                  }
                }
              );
            }
          }
        );
      } catch (error) {
        console.log(error);
        await change.ref.set(
          { error: userFacingMessage(error) },
          { merge: true }
        );
        return reportError(error, { user: context.params.userId });
      }
    }
  });

Upvotes: 0

Views: 1653

Answers (1)

douglasrcjames
douglasrcjames

Reputation: 1665

Looks like I misunderstood the purpose of the bank_name field. I thought it was for a custom name the user defines about their bank account, like "Doug's Chase Checkings", but it seems that it's auto generated by Stripe and read only.

Upvotes: 1

Related Questions