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

Support stripe connect #83

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Enter a valid _testing_ publishable key in the input below to activate the examp

Once you've set the `publishable-key` attribute (or the `publishableKey` DOM property), Stripe will create a Stripe Card Element on your page.

For use with Stripe Connect, you can provide the optional `stripe-account` attribute set to the account ID of the connected account.

### Accepting Payments

Fill out some payment information here, then choose the type of payment object you'd like to generate.
Expand Down
9 changes: 7 additions & 2 deletions src/StripeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export class StripeBase extends LitElement {
@property({ type: Boolean, attribute: 'show-error', reflect: true })
showError = false;

/** Stripe account to use (connect) */
@property({ type: String, attribute: 'stripe-account' })
stripeAccount: string;

/* READ-ONLY FIELDS */

/* PAYMENT REPRESENTATIONS */
Expand Down Expand Up @@ -388,13 +392,14 @@ export class StripeBase extends LitElement {
* Initializes Stripe and elements.
*/
private async initStripe(): Promise<void> {
const { publishableKey } = this;
const { publishableKey, stripeAccount } = this;
if (!publishableKey)
readonly.set<StripeBase>(this, { elements: null, element: null, stripe: null });
else {
try {
const options = stripeAccount ? { 'stripeAccount': stripeAccount } : {};
const stripe =
(window.Stripe) ? window.Stripe(publishableKey) : await loadStripe(publishableKey);
(window.Stripe) ? window.Stripe(publishableKey, options) : await loadStripe(publishableKey, options);
const elements = stripe?.elements();
readonly.set<StripeBase>(this, { elements, error: null, stripe });
} catch (e) {
Expand Down