Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

success|failed screen #11

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added payment_sdk/src/assets/images/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added payment_sdk/src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions payment_sdk/src/components/ResponseScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {Image, StyleSheet, Text, View} from 'react-native';
import React, {useCallback, useMemo} from 'react';
import SubmitButton from './SubmitButton';

type Props = {
status: 'success' | 'failed';
message?: string;
onPressLabel: string;
onPress: () => void;
};

const ResponseScreen = ({status, message, onPress, onPressLabel}: Props) => {
const renderMessageContent = useMemo(() => {
const title = status === 'success' ? 'Payment Success' : 'Payment Failed';
const defaultMessage =
status === 'success'
? 'Thank you for your order'
: 'Hey there, We tried to charge your card but, something went wrong. Please update your payment method below to continue';
const msg = message || defaultMessage;

return (
<View style={styles.container}>
<Text style={styles.title}>{title}</Text>
<Text style={styles.message}>{msg}</Text>
</View>
);
}, [status, message]);

const renderIcon = useMemo(() => {
const source =
status === 'success'
? require('../assets/images/success.png')
: require('../assets/images/error.png');
return <Image source={source} style={styles.icon} />;
}, [status]);

const memoizedOnPress = useCallback(onPress, [onPress]);

return (
<View style={styles.parentContainer}>
<View style={styles.imageContainer}>{renderIcon}</View>
{renderMessageContent}
<View style={styles.bottomButton}>
<SubmitButton onPress={memoizedOnPress} label={onPressLabel} />
</View>
</View>
);
};

export default ResponseScreen;

const styles = StyleSheet.create({
parentContainer: {
flex: 1,
},
container: {
padding: 16,
alignItems: 'center',
},
imageContainer: {
alignItems: 'center',
marginBottom: 18,
},
icon: {
width: 48,
height: 48,
},
title: {
fontSize: 28,
fontWeight: 'bold',
marginBottom: 16,
color: '#172E44',
},
message: {
fontSize: 16,
marginBottom: 16,
textAlign: 'center',
paddingHorizontal: 32,
},
bottomButton: {
position: 'absolute',
bottom: 32,
left: 0,
right: 0,
},
});
1 change: 1 addition & 0 deletions payment_sdk/src/components/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const styles = StyleSheet.create({
buttonWrapper: {
backgroundColor: "#0B82EE",
borderRadius: 8,
height: 50,
minHeight: 50,
marginHorizontal: 16,
flex: 1,
Expand Down
Loading