ordering-ui-react-native 0.22.27 → 0.22.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.22.27",
3
+ "version": "0.22.28",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -9,7 +9,7 @@ import {
9
9
  } from '@stripe/stripe-react-native';
10
10
  import { useTheme } from 'styled-components/native';
11
11
  import { ErrorMessage } from './styles';
12
-
12
+ import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
13
13
  import { StripeElementsForm as StripeFormController } from './naked';
14
14
  import { OButton, OText } from '../shared';
15
15
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
@@ -17,7 +17,7 @@ import { StripeMethodForm } from '../../../../../src/components/StripeMethodForm
17
17
 
18
18
  const StripeElementsFormUI = (props: any) => {
19
19
  const {
20
- publicKey,
20
+ publicKeyState,
21
21
  handleSource,
22
22
  values,
23
23
  businessId,
@@ -55,7 +55,7 @@ const StripeElementsFormUI = (props: any) => {
55
55
  const [isKeyboardShow, setIsKeyboardShow] = useState(false);
56
56
  const zipCodeEnabled = validationFields?.fields?.card?.zipcode?.enabled
57
57
  const zipCodeRequired = validationFields?.fields?.card?.zipcode?.required
58
- const isToSave = methodsPay?.includes(paymethod) ? publicKey : publicKeyAddCard
58
+ const isToSave = methodsPay?.includes(paymethod) ? publicKeyState?.key : (publicKeyAddCard || publicKeyState?.key)
59
59
  const styles = StyleSheet.create({
60
60
  container: {
61
61
  width: '100%',
@@ -201,70 +201,78 @@ const StripeElementsFormUI = (props: any) => {
201
201
 
202
202
  return (
203
203
  <View style={{ ...styles.container, height: methodsPay?.includes(paymethod) ? 'auto' : height - top - bottom - 60 - (isKeyboardShow ? 250 : 0) }}>
204
- {publicKey ? (
205
- <View style={{ flex: 1 }}>
206
- <StripeProvider
207
- publishableKey={isToSave}
208
- merchantIdentifier={merchantId}
209
- urlScheme={`${urlScheme}://checkout/${cart?.uuid}`}
210
- >
211
- {methodsPay?.includes(paymethod) ? (
212
- <StripeMethodForm
213
- handleSource={handleSource}
214
- onCancel={onCancel}
215
- cart={cart}
216
- cartTotal={cartTotal}
217
- setErrors={setErrors}
218
- paymethod={paymethod}
219
- devMode={publicKey?.includes('test')}
220
- setMethodPaySupported={setMethodPaySupported}
221
- placeByMethodPay={placeByMethodPay}
222
- methodPaySupported={methodPaySupported}
223
- setPlaceByMethodPay={setPlaceByMethodPay}
224
- androidAppId={androidAppId}
225
- />
226
- ) : (
227
- <CardField
228
- postalCodeEnabled={zipCodeEnabled}
229
- cardStyle={{
230
- backgroundColor: '#FFFFFF',
231
- textColor: '#000000',
232
- borderWidth: 1,
233
- borderRadius: 8,
234
- borderColor: theme.colors.border
235
- }}
236
- style={{
237
- width: '100%',
238
- height: 50,
239
- marginVertical: 30,
240
- zIndex: 9999,
241
- }}
242
- onCardChange={(cardDetails: any) => setCard(cardDetails)}
243
- />
244
- )}
245
- </StripeProvider>
246
- {!!errors && (
204
+ {publicKeyState.loading ? (
205
+ <Placeholder Animation={Fade}>
206
+ <PlaceholderLine height={50} style={{ marginTop: 20 }} />
207
+ </Placeholder>
208
+ ) : (
209
+ <>
210
+ {publicKeyState?.key ? (
211
+ <View style={{ flex: 1 }}>
212
+ <StripeProvider
213
+ publishableKey={isToSave}
214
+ merchantIdentifier={merchantId}
215
+ urlScheme={`${urlScheme}://checkout/${cart?.uuid}`}
216
+ >
217
+ {methodsPay?.includes(paymethod) ? (
218
+ <StripeMethodForm
219
+ handleSource={handleSource}
220
+ onCancel={onCancel}
221
+ cart={cart}
222
+ cartTotal={cartTotal}
223
+ setErrors={setErrors}
224
+ paymethod={paymethod}
225
+ devMode={publicKeyState?.key?.includes('test')}
226
+ setMethodPaySupported={setMethodPaySupported}
227
+ placeByMethodPay={placeByMethodPay}
228
+ methodPaySupported={methodPaySupported}
229
+ setPlaceByMethodPay={setPlaceByMethodPay}
230
+ androidAppId={androidAppId}
231
+ />
232
+ ) : (
233
+ <CardField
234
+ postalCodeEnabled={zipCodeEnabled}
235
+ cardStyle={{
236
+ backgroundColor: '#FFFFFF',
237
+ textColor: '#000000',
238
+ borderWidth: 1,
239
+ borderRadius: 8,
240
+ borderColor: theme.colors.border
241
+ }}
242
+ style={{
243
+ width: '100%',
244
+ height: 50,
245
+ marginVertical: 30,
246
+ zIndex: 9999,
247
+ }}
248
+ onCardChange={(cardDetails: any) => setCard(cardDetails)}
249
+ />
250
+ )}
251
+ </StripeProvider>
252
+ {!!errors && (
253
+ <ErrorMessage>
254
+ <OText
255
+ size={20}
256
+ color={theme.colors.error}
257
+ style={{ marginTop: 20, textAlign: 'center' }}
258
+ >
259
+ {errors}
260
+ </OText>
261
+ </ErrorMessage>
262
+ )}
263
+ </View>
264
+ ) : (
247
265
  <ErrorMessage>
248
266
  <OText
249
267
  size={20}
250
268
  color={theme.colors.error}
251
- style={{ marginTop: 20, textAlign: 'center' }}
269
+ style={{ marginTop: 20 }}
252
270
  >
253
- {errors}
271
+ {t('SOMETHING_WRONG', 'Something is wrong!')}
254
272
  </OText>
255
273
  </ErrorMessage>
256
274
  )}
257
- </View>
258
- ) : (
259
- <ErrorMessage>
260
- <OText
261
- size={20}
262
- color={theme.colors.error}
263
- style={{ marginTop: 20 }}
264
- >
265
- {t('SOMETHING_WRONG', 'Something is wrong!')}
266
- </OText>
267
- </ErrorMessage>
275
+ </>
268
276
  )}
269
277
  {!methodsPay?.includes(paymethod) && (
270
278
  <OButton
@@ -13,6 +13,7 @@ export const StripeElementsForm = (props: any) => {
13
13
  const [ordering] = useApi();
14
14
  const [{ token }] = useSession();
15
15
  const [state, setState] = useState({ loading: false, loadingAdd: false, error: null, requirements: null });
16
+ const [publicKeyState, setPublicKeyState] = useState({ key: props.publicKey, loading: true, error: null })
16
17
 
17
18
  const getRequirements = async () => {
18
19
  try {
@@ -85,6 +86,51 @@ export const StripeElementsForm = (props: any) => {
85
86
  }
86
87
  }
87
88
 
89
+ /**
90
+ * Method to get stripe credentials from API
91
+ */
92
+ const getCredentials = async () => {
93
+ try {
94
+ setPublicKeyState({
95
+ ...publicKeyState,
96
+ loading: true
97
+ })
98
+ const { content: { result, error } } = await ordering.setAccessToken(token).paymentCards().getCredentials()
99
+ if (!error) {
100
+ setPublicKeyState({
101
+ loading: false,
102
+ key: result.publishable,
103
+ error: null
104
+ })
105
+ } else {
106
+ setPublicKeyState({
107
+ ...publicKeyState,
108
+ loading: false,
109
+ error: result
110
+ })
111
+ }
112
+ } catch (error) {
113
+ setPublicKeyState({
114
+ ...publicKeyState,
115
+ loading: false,
116
+ error: error.message
117
+ })
118
+ }
119
+ }
120
+
121
+ useEffect(() => {
122
+ if (!token) return
123
+ if (props.publicKey) {
124
+ setPublicKeyState({
125
+ loading: false,
126
+ key: props.publicKey,
127
+ error: null
128
+ })
129
+ } else {
130
+ getCredentials()
131
+ }
132
+ }, [token, props.publicKey])
133
+
88
134
  useEffect(() => {
89
135
  if (!token || state.requirements) return
90
136
  toSave && getRequirements()
@@ -96,6 +142,7 @@ export const StripeElementsForm = (props: any) => {
96
142
  values={state}
97
143
  requirements={state.requirements}
98
144
  stripeTokenHandler={stripeTokenHandler}
145
+ publicKeyState={publicKeyState}
99
146
  />
100
147
  )
101
148
  }