Skip to content

Commit a73bdfb

Browse files
dpaun1985Dan Paun
andauthored
Add stripe link headers to requests (#2375)
Co-authored-by: Dan Paun <[email protected]>
1 parent d8e6812 commit a73bdfb

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 6.5.0 - 2022-xx-xx =
4+
* Add - Stripe Link: Add beta headers for Stripe server requests
45

56
= 6.4.3 - 2022-06-30 =
67
* Fix - Replace unnecessary throws with empty string when keys are invalid.

client/api/index.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,48 @@ export default class WCStripeAPI {
5858
* @return {Object} The Stripe Object.
5959
*/
6060
getStripe() {
61-
const { key, locale, isUPEEnabled } = this.options;
61+
const {
62+
key,
63+
locale,
64+
isUPEEnabled,
65+
paymentMethodsConfig,
66+
} = this.options;
67+
const isStripeLinkEnabled =
68+
undefined !== paymentMethodsConfig.card &&
69+
undefined !== paymentMethodsConfig.link;
6270

6371
if ( ! this.stripe ) {
6472
if ( isUPEEnabled ) {
65-
this.stripe = new Stripe( key, {
66-
betas: [ 'payment_element_beta_1' ],
67-
locale,
68-
} );
73+
let betas = [ 'payment_element_beta_1' ];
74+
if ( isStripeLinkEnabled ) {
75+
betas = betas.concat( [
76+
'link_autofill_modal_beta_1',
77+
'link_beta_2',
78+
] );
79+
}
80+
81+
this.stripe = this.createStripe( key, locale, betas );
6982
} else {
70-
this.stripe = new Stripe( key, {
71-
locale,
72-
} );
83+
this.stripe = this.createStripe( key, locale );
7384
}
7485
}
7586
return this.stripe;
7687
}
7788

89+
createStripe( key, locale, betas = [] ) {
90+
const options = { locale };
91+
92+
if ( betas.length ) {
93+
options.betas = betas;
94+
}
95+
96+
if ( betas.includes( 'link_beta_2' ) ) {
97+
options.apiVersion = '2020-08-27;link_beta=v1';
98+
}
99+
100+
return new Stripe( key, options );
101+
}
102+
78103
/**
79104
* Load Stripe for payment request button.
80105
*

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
129129
== Changelog ==
130130

131131
= 6.5.0 - 2022-xx-xx =
132+
* Add - Stripe Link: Add beta headers for Stripe server requests
132133

133134
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)