Financial Connections

⭐️ Minimal reference integration: A button that will create a Customer, create a Financial Connection Sessions for that Customer, and start the flow to connect a Financial Account

⚠️ Note: This integration is not production ready and should only be used as a reference.

⚙️ Integration


      

🧑‍💻 Code

<?php

if (isset($_GET['connect'])) {
  $stripeConfiguration = [
    'api_key' => 'sk_•••',
    'stripe_version' => '2023-10-16',
  ];
  
  $stripe = new \Stripe\StripeClient($stripeConfiguration);

  $customer = $stripe->customers->create([
    'name' => 'Finanical Connections Test (' . time() . ')',
  ]);
  
  $financialConnectionsSession = $stripe->financialConnections->sessions->create([
    'account_holder' => [
      'type' => 'customer',
      'customer' => $customer->id,
    ],
    'permissions' => [
      'balances',
      'ownership',
      'payment_method',
      'transactions',
    ],
  ]);
  
  header('Content-Type: application/json');
  
  echo json_encode([
    'customer' => $customer->id,
    'clientSecret' => $financialConnectionsSession->client_secret,
  ]);
  
  exit;
}
  
<script src="https://js.stripe.com/v3/"></script>

<p><button type="button" id="connect-financial-account">Create Customer & Connect Financial Account</button></p>

<pre id="output"></pre>
/* TODO: CSS goes here */
const stripe = Stripe('pk_test_51O2hxMC4JnNRtz8VToJJbGHrFTPPr6TkP09h7ql3YJaqpNcxoSNxtk38glyzi9VrZKStns858YynOO2ZyGmU7VRi00CIUWuUdk');

const connectFinancialAccountButton = document.querySelector('#connect-financial-account');

const outputElement = document.querySelector('#output');

connectFinancialAccountButton.addEventListener('click', async event => {
  const result = await fetch('?connect');
  
  const { customer, clientSecret } = await result.json();
  
  const financialConnectionsSessionResult = await stripe.collectFinancialConnectionsAccounts({
    clientSecret
  });
  
  outputElement.textContent = 'Customer created: ' + customer + "\n\n" + 'Financial Connections Session Result:' + "\n\n" + JSON.stringify(financialConnectionsSessionResult, null, 2);
});