Skip to content

Add AccountProvider for account context management#3

Merged
timrohan merged 1 commit intocodespace-stunning-fortnight-97rx6jg6jjrj2x567from
components/AccountProvider.jsx
Feb 9, 2026
Merged

Add AccountProvider for account context management#3
timrohan merged 1 commit intocodespace-stunning-fortnight-97rx6jg6jjrj2x567from
components/AccountProvider.jsx

Conversation

@timrohan
Copy link
Owner

@timrohan timrohan commented Feb 9, 2026

Implement AccountProvider to manage account state and localStorage synchronization.
'use client';

const AccountStatus = ({ accountStatus, onStartOnboarding, onLogout }) => {
if (!accountStatus) {
return null;
}

const statusColor = accountStatus.chargesEnabled ? "green" : "orange";
const statusText = accountStatus.chargesEnabled ? "Active" : "Pending";
const needsOnboarding = !accountStatus.chargesEnabled && !accountStatus.detailsSubmitted;

return (




Account Status:{" "}
<span style={{ color: statusColor }}>{statusText}


  <div className="status-details">
    <div className="status-item">
      <span>Account ID:</span>
      <span>{accountStatus.id}</span>
    </div>
    <div className="status-item">
      <span>Payouts enabled:</span>
      <span>{accountStatus.payoutsEnabled ? "✅" : "❌"}</span>
    </div>
    <div className="status-item">
      <span>Charges enabled:</span>
      <span>{accountStatus.chargesEnabled ? "✅" : "❌"}</span>
    </div>
    <div className="status-item">
      <span>Details submitted:</span>
      <span>{accountStatus.detailsSubmitted ? "✅" : "❌"}</span>
    </div>
  </div>

  {needsOnboarding && (
    <button
      onClick={onStartOnboarding}
      className="button"
      style={{
        marginBottom: "10px",
      }}
    >
      Onboard to collect payments
    </button>
  )}
  <button
    className="button"
    disabled={!accountStatus}
    onClick={onLogout}
  >
    Log out
  </button>
</div>

);
};

export default AccountStatus;

Implement AccountProvider to manage account state and localStorage synchronization.
@timrohan timrohan self-assigned this Feb 9, 2026
@timrohan timrohan added bug Something isn't working documentation Improvements or additions to documentation duplicate This issue or pull request already exists enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers invalid This doesn't seem right question Further information is requested labels Feb 9, 2026
@timrohan timrohan linked an issue Feb 9, 2026 that may be closed by this pull request
@timrohan timrohan merged commit e84da7e into codespace-stunning-fortnight-97rx6jg6jjrj2x567 Feb 9, 2026
@timrohan
Copy link
Owner Author

timrohan commented Feb 9, 2026

import { NextResponse } from 'next/server';
import { stripe } from '../../../lib/stripe';

export async function POST(request) {
try {
const { accountId } = await request.json();

const accountLink = await stripe.v2.core.accountLinks.create({
  account: accountId,
  use_case: {
    type: 'account_onboarding',
    account_onboarding: {
      configurations: ['merchant', 'customer'],
      refresh_url: 'https://viviarentals.com',
      return_url: 'https://turbo.viviarentals.com',
    },
  },
});


return NextResponse.json({ url: accountLink.url });

} catch (error) {
console.error('Error creating account link:', error);
return NextResponse.json(
{ error: { message: error.message } },
{ status: 400 }
);
}
}

@timrohan
Copy link
Owner Author

timrohan commented Feb 9, 2026

import { NextResponse } from 'next/server';
import { stripe } from '../../../lib/stripe';

// Create checkout session
export async function POST(request) {
const formData = await request.formData();
const priceId = formData.get("priceId");
const accountId = formData.get("accountId");

// Get the price's type from Stripe
const price = await stripe.prices.retrieve(priceId);
const priceType = price.type;
const mode = priceType === "recurring" ? "subscription" : "payment";

const sessionParams = {
line_items: [
{
price: priceId,
quantity: 1,
},
],
mode: mode,
// Defines where Stripe will redirect a customer after successful payment
success_url: ${process.env.DOMAIN}/done?session_id={CHECKOUT_SESSION_ID},
// Defines where Stripe will redirect if a customer cancels payment
cancel_url: ${process.env.DOMAIN},
};

let session;

if (accountId) {
// For direct charges, use stripeAccount parameter
sessionParams.payment_intent_data = {
application_fee_amount: 123,
};

session = await stripe.checkout.sessions.create(sessionParams, {
  stripeAccount: accountId,
});

} else {
session = await stripe.checkout.sessions.create(sessionParams);
}

// Redirect to the Stripe hosted checkout URL
return NextResponse.redirect(session.url, 303);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation duplicate This issue or pull request already exists enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📦 Complete Property Management System - Ready to Deploy

1 participant