<title>Mini App</title>
<style>
body {
margin: 0;
padding: 1em;
background-color: #fff;
}
[data-cart-info],
[data-credit-card] {
transform: scale(0.78);
margin-left: -3.4em;
}
[data-cc-info] input:focus,
[data-cc-digits] input:focus {
outline: none;
}
.mdc-card__primary-action,
.mdc-card__primary-action:hover {
cursor: auto;
padding: 20px;
min-height: inherit;
}
[data-credit-card] [data-card-type] {
transition: width 1.5s;
margin-left: calc(100% - 130px);
}
[data-credit-card].is-visa {
background: linear-gradient(135deg, #622774 0%, #c53364 100%);
}
[data-credit-card].is-mastercard {
background: linear-gradient(135deg, #65799b 0%, #5e2563 100%);
}
.is-visa [data-card-type],
.is-mastercard [data-card-type] {
width: auto;
}
input.is-invalid,
.is-invalid input {
text-decoration: line-through;
}
::placeholder {
color: #fff;
}
/* Add Your Css From Here*/
span {
display: inline-block;
vertical-align: middle;
}
[data-credit-card] {
width: 435px;
min-height: 240px;
background-color: #5d6874;
border-radius: 10px;
}
span.material-icons {
font-size: 150px;
}
[data-card-type] {
display: block;
width: 120px;
height: 60px;
}
[data-cc-digits] {
margin-top: 2em;
}
[data-cc-digits]>input {
color: #ffffff;
background: none;
font-size: 2em;
line-height: 2em;
border: none;
margin-right: 0.5em;
}
[data-cc-info] {
margin-top: 1em;
}
[data-cc-info]>input {
color: #ffffff;
font-size: 1.2em;
border: none;
background: none;
}
[data-cc-info]>input:nth-child(2) {
padding-right: 10px;
float: right;
}
[data-pay-btn] {
position: fixed;
border: 1px solid;
width: 90%;
bottom: 20px;
}
</style>
<!-- your HTML goes here -->
<div data-cart-info>
<heading class="mdc-typography--headline4">
<span class="material-icons">
shopping_cart
</span>
<span data-bill>
</span>
</heading>
</div>
<div data-credit-card class="mdc-card mdc-card--outlined">
<div class="mdc-card__primary-action">
<img src="https://placehold.it/120x60.png?text=Card" data-card-type>
<div data-cc-digits>
<input type="text" size="4" placeholder="----"/>
<input type="text" size="4" placeholder="----"/>
<input type="text" size="4" placeholder="----"/>
<input type="text" size="4" placeholder="----"/>
</div>
<div data-cc-info>
<input type="text" size="20" placeholder="Name Surname"/>
<input type="text" size="6" placeholder="MM/YY"/>
</div>
</div>
</div>
<button class="mdc-button" data-pay-btn>
Pay Now
</button>
<script>
const supportedCards = {
visa, mastercard
};
const countries = [
{
code: "US",
currency: "USD",
currencyName: '',
country: 'United States'
},
{
code: "NG",
currency: "NGN",
currencyName: '',
country: 'Nigeria'
},
{
code: 'KE',
currency: 'KES',
currencyName: '',
country: 'Kenya'
},
{
code: 'UG',
currency: 'UGX',
currencyName: '',
country: 'Uganda'
},
{
code: 'RW',
currency: 'RWF',
currencyName: '',
country: 'Rwanda'
},
{
code: 'TZ',
currency: 'TZS',
currencyName: '',
country: 'Tanzania'
},
{
code: 'ZA',
currency: 'ZAR',
currencyName: '',
country: 'South Africa'
},
{
code: 'CM',
currency: 'XAF',
currencyName: '',
country: 'Cameroon'
},
{
code: 'GH',
currency: 'GHS',
currencyName: '',
country: 'Ghana'
}
];
const billHype = () => {
const billDisplay = document.querySelector('.mdc-typography--headline4');
if (!billDisplay) return;
billDisplay.addEventListener('click', () => {
const billSpan = document.querySelector("[data-bill]");
if (billSpan &&
appState.bill &&
appState.billFormatted &&
appState.billFormatted === billSpan.textContent) {
window.speechSynthesis.speak(
new SpeechSynthesisUtterance(appState.billFormatted)
);
}
});
};
const appState = {};
const formatAsMoney = (amount,buyerCountry)=>{
const ountry = countries.find((x)=>x.country === buyerCountry) || countries[0];
return amount.toLocaleString(en-${country.code},{
style:“currency”,
currency:country.currency
});
}
const detectCardType =(first4Digits)=>{}
const validateCardExpiryDate = () =>{}
const validateCardHolderName = () =>{}
const uiCanInteract = () =>{}
const displayCartTotal = ({results}) =>{
const [data] = results;
const{itemsInCart,buyerCountry}=data;
appState.items = itemsInCart;
appState.country = buyerCountry;
appState.bill = itemsInCart.reduce((result,item)=>{
result+(item.price*item.qty)
},0);
appState.billFormatted = formatAsMoney(appState.bill,appState.country);
const billSpan = document.querySelector('[data-bill]');
billSpan.textContent = appState.billFormatted;
appState.cardDigits=[];
uiCanInteract();
};
const fetchBill = () => {
const api = 'https://randomapi.com/api/006b08a801d82d0c9824dcfdfdfa3b3c';
fetch(api)
.then(responce=>response.json())
.then(response=>data(displayCartTotal))
.catch(error=>console.error('Error :',error));
const apiKey = '006b08a801d82d0c9824dcfdfdfa3b3c';
const apiEndpoint = `${apiHost}/${apiKey}`;
};
const startApp = () => {
fetchBill();
};
startApp();
</script>