@@ -14,39 +14,6 @@ let stripePromise = null;
14
14
let stripePaymentMethod = null ;
15
15
let stripePaymentMethodIsCreditCard = false ;
16
16
17
- // @see https://stripe.com/docs/currencies#zero-decimal
18
- const zeroDecimalCurrencies = [
19
- 'BIF' ,
20
- 'CLP' ,
21
- 'DJF' ,
22
- 'GNF' ,
23
- 'JPY' ,
24
- 'KMF' ,
25
- 'KRW' ,
26
- 'MGA' ,
27
- 'PYG' ,
28
- 'RWF' ,
29
- 'UGX' ,
30
- 'VND' ,
31
- 'VUV' ,
32
- 'XAF' ,
33
- 'XOF' ,
34
- 'XPF' ,
35
- ] ;
36
-
37
- /**
38
- * Takes in an amount value in dollar units and returns the calculated cents amount
39
- *
40
- * @since 3.0.0
41
- */
42
- const dollarsToCents = ( amount : string , currency : string ) => {
43
- if ( zeroDecimalCurrencies . includes ( currency ) ) {
44
- return Math . round ( parseFloat ( amount ) ) ;
45
- }
46
-
47
- return Math . round ( parseFloat ( amount ) * 100 ) ;
48
- } ;
49
-
50
17
const StripeFields = ( { gateway} ) => {
51
18
const stripe = useStripe ( ) ;
52
19
const elements = useElements ( ) ;
@@ -91,6 +58,7 @@ interface StripeGateway extends Gateway {
91
58
}
92
59
93
60
/**
61
+ * @unreleased Replace useWatch with useFormData
94
62
* @since 3.18.0 added fields conditional when donation amount is zero
95
63
* @since 3.13.0 Use only stripeKey to load the Stripe script (when stripeConnectedAccountId is missing) to prevent errors when the account is connected through API keys
96
64
* @since 3.12.1 updated afterCreatePayment response type to include billing details address
@@ -200,20 +168,16 @@ const stripePaymentElementGateway: StripeGateway = {
200
168
throw new Error ( 'Stripe library was not able to load. Check your Stripe settings.' ) ;
201
169
}
202
170
203
- const { useWatch} = window . givewp . form . hooks ;
204
- const donationType = useWatch ( { name : 'donationType' } ) ;
205
- const donationCurrency = useWatch ( { name : 'currency' } ) ;
206
- const donationAmount = useWatch ( { name : 'amount' } ) ;
207
- const stripeAmount = dollarsToCents ( donationAmount , donationCurrency . toString ( ) . toUpperCase ( ) ) ;
171
+ const { isRecurring, currency, amountInMinorUnits : stripeAmount } = window . givewp . form . hooks . useFormData ( ) ;
208
172
209
173
const stripeElementOptions : StripeElementsOptionsMode = {
210
- mode : donationType === 'subscription' ? 'subscription' : 'payment' ,
174
+ mode : isRecurring ? 'subscription' : 'payment' ,
211
175
amount : stripeAmount ,
212
- currency : donationCurrency . toLowerCase ( ) ,
176
+ currency : currency . toLowerCase ( ) ,
213
177
appearance : appearanceOptions ,
214
178
} ;
215
179
216
- if ( donationAmount <= 0 ) {
180
+ if ( stripeAmount <= 0 ) {
217
181
return < > { __ ( 'Donation amount must be greater than zero to proceed.' , 'give' ) } </ > ;
218
182
}
219
183
0 commit comments