Skip to content

Commit

Permalink
Merge pull request #530 from Adyen/prettier
Browse files Browse the repository at this point in the history
Prettier JS
  • Loading branch information
descorp authored Sep 18, 2024
2 parents dd7104f + 7ed25d9 commit 9a2dbbc
Show file tree
Hide file tree
Showing 36 changed files with 261 additions and 268 deletions.
19 changes: 9 additions & 10 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import {
DarkTheme,
DefaultTheme,
} from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {createNativeStackNavigator} from '@react-navigation/native-stack';

import { Button, Alert, useColorScheme } from 'react-native';
import {Button, Alert, useColorScheme} from 'react-native';
import CseView from './src/Views/CseView';
import SettingView from './src/Views/SettingsView';
import Result from './src/Views/ResultView';
import SessionsCheckout from './src/Views/Checkout/SessionsCheckout';
import AdvancedCheckout from './src/Views/Checkout/AdvancedCheckout';
import Home from './src/Views/HomeView';
import AppContextProvider from './src/Utilities/AppContext';
import { DEFAULT_CONFIGURATION } from './src/Configuration';
import {DEFAULT_CONFIGURATION} from './src/Configuration';

const Stack = createNativeStackNavigator();

const SettingsButton = ({ navigation }) => {
const SettingsButton = ({navigation}) => {
return (
<Button onPress={() => navigation.navigate(Page.Settings)} title="Edit" />
);
Expand All @@ -47,28 +47,27 @@ const App = () => {
return (
<AppContextProvider
configuration={DEFAULT_CONFIGURATION}
onError={(error) => {
onError={error => {
Alert.alert('App error', error.message || 'Error');
}}
>
}}>
<NavigationContainer theme={isDarkMode ? DarkTheme : DefaultTheme}>
<Stack.Navigator>
<Stack.Screen
name={Page.Home}
component={Home}
options={({ navigation }) => ({
options={({navigation}) => ({
headerRight: () => <SettingsButton navigation={navigation} />,
})}
/>
<Stack.Screen
name={Page.SessionsCheckout}
component={SessionsCheckout}
options={() => ({ title: 'Sessions Checkout' })}
options={() => ({title: 'Sessions Checkout'})}
/>
<Stack.Screen
name={Page.AdvancedCheckout}
component={AdvancedCheckout}
options={() => ({ title: 'Advanced Checkout' })}
options={() => ({title: 'Advanced Checkout'})}
/>
<Stack.Screen name={Page.Settings} component={SettingView} />
<Stack.Screen name={Page.Result} component={Result} />
Expand Down
2 changes: 1 addition & 1 deletion example/src/Configuration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Platform, NativeModules } from 'react-native';
import {Platform, NativeModules} from 'react-native';
export const DEVICE_LOCALE = (
Platform.OS === 'ios'
? NativeModules.SettingsManager.settings.AppleLocale ||
Expand Down
2 changes: 1 addition & 1 deletion example/src/Types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResultCode, PaymentAction } from '@adyen/react-native';
import {ResultCode, PaymentAction} from '@adyen/react-native';

/**
* {@link https://docs.adyen.com/api-explorer/Checkout/70/post/payments#responses-200 API Explorer /payments response}
Expand Down
18 changes: 12 additions & 6 deletions example/src/Utilities/APIClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check

import { LogBox } from 'react-native';
import { ENVIRONMENT, CHANNEL } from '../Configuration';
import {LogBox} from 'react-native';
import {ENVIRONMENT, CHANNEL} from '../Configuration';

LogBox.ignoreLogs(['Require cycle:']);

Expand All @@ -20,7 +20,7 @@ class ApiClient {
return ApiClient.makeRequest(ENVIRONMENT.url + 'payments', body);
}

static paymentDetails = (data) => {
static paymentDetails = data => {
return ApiClient.makeRequest(ENVIRONMENT.url + 'payments/details', data);
};

Expand All @@ -36,7 +36,7 @@ class ApiClient {
return ApiClient.makeRequest(ENVIRONMENT.url + 'sessions', body);
};

static paymentMethods = (configuration) => {
static paymentMethods = configuration => {
const body = {
...parseConfig(configuration),
...parseAmount(configuration),
Expand All @@ -63,7 +63,9 @@ class ApiClient {
const pspReference = response.headers.get('pspreference');
console.debug(`PSP Reference - ${pspReference}`);
const payload = await response.json();
if (response.ok) return payload;
if (response.ok) {
return payload;
}
console.warn(`Error - ${JSON.stringify(payload, null, ' ')}`);
throw new Error(`Network Error ${response.status}:
${payload.message ?? JSON.stringify(payload)}`);
Expand All @@ -78,7 +80,11 @@ const serverConfiguration = {
};

const paymentConfiguration = {
additionalData: { allow3DS2: true },
authenticationData: {
threeDSRequestData: {
nativeThreeDS: 'preferred',
},
},
lineItems: [
{
quantity: '1',
Expand Down
3 changes: 1 addition & 2 deletions example/src/Utilities/AppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const checkoutConfiguration = (
resolve,
reject,
) => {

resolve();
},
},
Expand Down Expand Up @@ -161,7 +160,7 @@ const AppContextProvider = (/** @type {any} */ props) => {

useEffect(() => {
AsyncStorage.getItem(storeKey)
.then((value) => {
.then(value => {
if (value) {
console.debug(`Stored config: ${value}`);
const parsed = JSON.parse(value);
Expand Down
4 changes: 2 additions & 2 deletions example/src/Utilities/Helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ResultCode } from '@adyen/react-native';
import {ResultCode} from '@adyen/react-native';

export const isSuccess = ({ resultCode }) =>
export const isSuccess = ({resultCode}) =>
[
ResultCode.authorised,
ResultCode.received,
Expand Down
6 changes: 3 additions & 3 deletions example/src/Utilities/Styles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet } from 'react-native';
import {StyleSheet} from 'react-native';

const Styles = StyleSheet.create({
page: {
Expand Down Expand Up @@ -44,8 +44,8 @@ const Styles = StyleSheet.create({
textDark: {
color: 'white',
},
slash: { paddingHorizontal: 4, textAlign: 'center' },
centeredText: { textAlign: 'center' },
slash: {paddingHorizontal: 4, textAlign: 'center'},
centeredText: {textAlign: 'center'},
centeredButton: {
alignItems: 'center',
justifyContent: 'center',
Expand Down
19 changes: 11 additions & 8 deletions example/src/Utilities/payByID.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { AdyenCSE, AdyenAction } from '@adyen/react-native';
import { ENVIRONMENT } from '../Configuration';
import {AdyenCSE, AdyenAction} from '@adyen/react-native';
import {ENVIRONMENT} from '../Configuration';
import ApiClient from './APIClient';
import { checkoutConfiguration } from './AppContext';
import { isSuccess } from './Helpers';
import {checkoutConfiguration} from './AppContext';
import {isSuccess} from './Helpers';

export async function payByID(id, cvv, configuration) {
const encryptedCard = await AdyenCSE.encryptCard(
{ cvv },
ENVIRONMENT.publicKey
{cvv},
ENVIRONMENT.publicKey,
);
const paymentData = {
paymentMethod: {
Expand All @@ -21,11 +21,14 @@ export async function payByID(id, cvv, configuration) {
let result = await ApiClient.payments(
paymentData,
configuration,
ENVIRONMENT.returnUrl
ENVIRONMENT.returnUrl,
);
if (result.action) {
const actionConfiguration = checkoutConfiguration(configuration);
const actionData = await AdyenAction.handle(result.action, actionConfiguration);
const actionData = await AdyenAction.handle(
result.action,
actionConfiguration,
);
result = await ApiClient.paymentDetails(actionData);
}
AdyenAction.hide(isSuccess(result.resultCode));
Expand Down
15 changes: 9 additions & 6 deletions example/src/Utilities/payWithCard.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AdyenCSE, AdyenAction } from '@adyen/react-native';
import { ENVIRONMENT } from '../Configuration';
import {AdyenCSE, AdyenAction} from '@adyen/react-native';
import {ENVIRONMENT} from '../Configuration';
import ApiClient from './APIClient';
import { checkoutConfiguration } from './AppContext';
import {checkoutConfiguration} from './AppContext';

export async function payWithCard(unencryptedCard, configuration) {
const encryptedCard = await AdyenCSE.encryptCard(
unencryptedCard,
ENVIRONMENT.publicKey
ENVIRONMENT.publicKey,
);
const paymentData = {
paymentMethod: {
Expand All @@ -22,11 +22,14 @@ export async function payWithCard(unencryptedCard, configuration) {
let result = await ApiClient.payments(
paymentData,
configuration,
ENVIRONMENT.returnUrl
ENVIRONMENT.returnUrl,
);
if (result.action) {
const actionConfiguration = checkoutConfiguration(configuration);
const actionData = await AdyenAction.handle(result.action, actionConfiguration);
const actionData = await AdyenAction.handle(
result.action,
actionConfiguration,
);
result = await ApiClient.paymentDetails(actionData);
}
return result;
Expand Down
Loading

0 comments on commit 9a2dbbc

Please sign in to comment.