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

Commit 828930c

Browse files
Register package version with Stripe instance (#512)
1 parent 550b1c3 commit 828930c

File tree

5 files changed

+352
-320
lines changed

5 files changed

+352
-320
lines changed

‎.babelrc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"plugins": [
44
"transform-class-properties",
55
"transform-object-rest-spread",
6-
[ "transform-es2015-classes", { "loose": true } ]
6+
[ "transform-es2015-classes", { "loose": true } ],
7+
"transform-inline-environment-variables"
78
]
89
}

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"babel-loader": "^7.1.2",
4949
"babel-plugin-transform-class-properties": "^6.24.1",
5050
"babel-plugin-transform-es2015-classes": "^6.24.1",
51+
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
5152
"babel-plugin-transform-object-rest-spread": "^6.26.0",
5253
"babel-preset-env": "^1.6.1",
5354
"babel-preset-react": "^6.24.1",

‎src/components/Provider.js‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,16 @@ export default class Provider extends React.Component<Props> {
9797
"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"
9898
);
9999
} else {
100-
const {apiKey, children, stripe, ...options} = this.props;
101-
this._meta = {
102-
tag: 'sync',
103-
stripe: getOrCreateStripe(apiKey, options),
104-
};
100+
const {apiKey, children, ...options} = this.props;
101+
const stripe = getOrCreateStripe(apiKey, options);
102+
this._meta = {tag: 'sync', stripe};
103+
this._register();
105104
}
106105
} else if (this.props.stripe) {
107106
// If we already have a stripe instance (in the constructor), we can behave synchronously.
108-
this._meta = {
109-
tag: 'sync',
110-
stripe: ensureStripeShape(this.props.stripe),
111-
};
107+
const stripe = ensureStripeShape(this.props.stripe);
108+
this._meta = {tag: 'sync', stripe};
109+
this._register();
112110
} else if (this.props.stripe === null) {
113111
this._meta = {
114112
tag: 'async',
@@ -179,12 +177,26 @@ export default class Provider extends React.Component<Props> {
179177
this._didWakeUpListeners = true;
180178
const stripe = ensureStripeShape(this.props.stripe);
181179
this._meta.stripe = stripe;
180+
this._register();
182181
this._listeners.forEach((fn) => {
183182
fn(stripe);
184183
});
185184
}
186185
}
187186

187+
_register() {
188+
const {stripe} = this._meta;
189+
190+
if (!stripe || !stripe._registerWrapper) {
191+
return;
192+
}
193+
194+
stripe._registerWrapper({
195+
name: 'react-stripe-elements',
196+
version: process.env.npm_package_version || null,
197+
});
198+
}
199+
188200
props: Props;
189201
_didWarn: boolean;
190202
_didWakeUpListeners: boolean;

‎src/decls/Stripe.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ declare type StripeShape = {
5656
confirmIdealPayment: ConfirmPaymentFn,
5757
confirmSepaDebitPayment: ConfirmPaymentFn,
5858
confirmSepaDebitSetup: ConfirmSetupFn,
59+
_registerWrapper: (wrapper: {|
60+
name: string,
61+
version: string | null,
62+
|}) => void,
5963
};

0 commit comments

Comments
 (0)