Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Register package version with Stripe instance #512

Merged
merged 1 commit into from
Mar 31, 2020
Merged
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
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins": [
"transform-class-properties",
"transform-object-rest-spread",
[ "transform-es2015-classes", { "loose": true } ]
[ "transform-es2015-classes", { "loose": true } ],
"transform-inline-environment-variables"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"babel-loader": "^7.1.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-es2015-classes": "^6.24.1",
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
Expand Down
30 changes: 21 additions & 9 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,16 @@ export default class Provider extends React.Component<Props> {
"Please load Stripe.js (https://js.stripe.com/v3/) on this page to use react-stripe-elements. If Stripe.js isn't available yet (it's loading asynchronously, or you're using server-side rendering), see https://github.com/stripe/react-stripe-elements#advanced-integrations"
);
} else {
const {apiKey, children, stripe, ...options} = this.props;
this._meta = {
tag: 'sync',
stripe: getOrCreateStripe(apiKey, options),
};
const {apiKey, children, ...options} = this.props;
const stripe = getOrCreateStripe(apiKey, options);
this._meta = {tag: 'sync', stripe};
this._register();
}
} else if (this.props.stripe) {
// If we already have a stripe instance (in the constructor), we can behave synchronously.
this._meta = {
tag: 'sync',
stripe: ensureStripeShape(this.props.stripe),
};
const stripe = ensureStripeShape(this.props.stripe);
this._meta = {tag: 'sync', stripe};
this._register();
} else if (this.props.stripe === null) {
this._meta = {
tag: 'async',
Expand Down Expand Up @@ -179,12 +177,26 @@ export default class Provider extends React.Component<Props> {
this._didWakeUpListeners = true;
const stripe = ensureStripeShape(this.props.stripe);
this._meta.stripe = stripe;
this._register();
this._listeners.forEach((fn) => {
fn(stripe);
});
}
}

_register() {
const {stripe} = this._meta;

if (!stripe || !stripe._registerWrapper) {
return;
}

stripe._registerWrapper({
name: 'react-stripe-elements',
version: process.env.npm_package_version || null,
});
}

props: Props;
_didWarn: boolean;
_didWakeUpListeners: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/decls/Stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ declare type StripeShape = {
confirmIdealPayment: ConfirmPaymentFn,
confirmSepaDebitPayment: ConfirmPaymentFn,
confirmSepaDebitSetup: ConfirmSetupFn,
_registerWrapper: (wrapper: {|
name: string,
version: string | null,
|}) => void,
};
Loading