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

Conversation

aednzxy
Copy link
Contributor

@aednzxy aednzxy commented Mar 16, 2022

The motivation behind this PR is to allow support for direct charges against connected accounts. To do this, we must pass in the stripeAccount attribute to the StripeConstructorOptions parameter when initialising stripe-js.

This PR adds an additional, optional attribute stripe-account, allowing the user to provide the ID of the connected account they wish to make charges against.

This is supported both when initialising either via window.Stripe or loadStripe, both methods accept a StripeConstructorOptions parameter after publishableKey. This is where we set the stripe-account attribute that is passed to the web component.

See example of loading stripe elements with stripeAccount attribute:
https://stripe.com/docs/connect/creating-a-payments-page?platform=web&ui=elements#set-up-stripe-elements

When this value is set, the stripe library sets the stripe-account header on corresponding requests. It only needs to be set when we initialise stripe js, the rest is handled by stripe's library.

Optional string. Gets passed to Stripe constructor, either window or via stripe-js. Both accept a StripeConstructorOptions parameter after publishableKey.
Copy link
Owner

@bennypowers bennypowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good can you add some tests?

@whiteancient
Copy link
Contributor

I would love to get this integrated (so I do not have to copy paste all your lovely code). My problem is that I am not competent enough to write the tests you ask for above without some hints of what you would need to be satisfied. Please advise so this can be integrated :)

@bennypowers
Copy link
Owner

@whiteancient take a look at the tests in this block:

describe('with mocked Stripe.js', function() {
An example would be this test that asserts that a stripe element with a valid PK, and a completed form, and generate="payment-method" eventually gets a payment method object
describe('and generate set to `payment-method`', function() {
beforeEach(Helpers.setProps({ generate: 'payment-method' }));
describe('calling submit()', function() {
it('resolves with the payment method', async function() {
const { paymentMethod } = await (element as StripeElements).submit() as Stripe.PaymentMethodResult;
expect(paymentMethod).to.equal(SUCCESS_RESPONSES.paymentMethod);
});

You'll need to add the relevant methods to this mocked stripe.js object: https://github.com/bennypowers/stripe-elements/blob/1a4033cdfe5669a6e50cadd030847912bd0e8c5b/test/mock-stripe/index.ts
and maybe some test helpers a la

export async function createPaymentMethod(): Promise<void> {
if (!(element instanceof StripeElements))
throw new Error(`TEST HELPERS: can't create a payment method on ${element.constructor.name}`);
await swallowCallError.call(this, element.createPaymentMethod());
}

@bennypowers
Copy link
Owner

Is this still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants