Question

In: Computer Science

Use attribute directives to display credit card logo based on the credit card number Use simplified...

Use attribute directives to display credit card logo based on the credit card number Use simplified rules as follows:

4 visa

5 mastercard

34 and 37 amex

30, 36, 38, 39 diners

60, 64, 65 discover

Solutions

Expert Solution

import {Directive, Input, OnChanges, HostBinding} from '@angular/core';

enum CardType { VISA = 'visa', MASTERCARD = 'mastercard', AMERICAN_EXPRESS = 'american-express', DINERS = 'diners', DISCOVER = 'discover'  UNKNOWN = 'unknown'}

@Directive({
  selector: '[ccLogo]'
})
export class CreditCardImageDirective implements OnChanges {


  @HostBinding('src')
  imageSource;

  @Input()
  cardNumber: string

  ngOnChanges() {
    this.imageSource = 'assets/card-types/' + this.getCardTypeFromNumber() + '.png';
  }

  getCardTypeFromNumber(): CardType {
    if (this.cardNumber) {
      if (this.cardNumber.startsWith('37') || this.cardNumber.startsWith('34')) {
        return CardType.AMERICAN_EXPRESS;
      } else if (this.cardNumber.startsWith('4')) {
        return CardType.VISA;
      } else if (this.cardNumber.startsWith('5')) {
        return CardType.MASTERCARD;
      } else if (this.cardNumber.startsWith('30') || this.cardNumber.startsWith('36') ||      this.cardNumber.startsWith('38') || this.cardNumber.startsWith('39')) { 
return CardType.DINERS; 
      } else if (this.cardNumber.startsWith('60') || this.cardNumber.startsWith('64') || this.cardNumber.startsWith('65')) { 
return CardType.DISCOVER; 
    }
    }
    return CardType.UNKNOWN;
  }

}

Related Solutions

Credit Card Number Check. The last digit of a credit card number is the check digit,...
Credit Card Number Check. The last digit of a credit card number is the check digit, which protects against transcription errors such as error in a single digit or switching two digits. The following method is used to verify actual credit card number but, for simplicity, we will describe it for numbers with 8 digits instead of 16: Starting from the rightmost digit, form the sum of every other digit. For example, if the credit card number is 43589795, then...
Credit Card Number Check. The last digit of a credit card number is the check digit,...
Credit Card Number Check. The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or switching two digits. The following method is used to verify actual credit card numbers but, for simplicity, we will describe it for numbers with 8 digits instead of 16: • Starting from the rightmost digit, form the sum of every other digit. For example, if the credit card number is...
Credit Card Number Check. The last digit of a credit card number is the check digit,...
Credit Card Number Check. The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or switching two digits. The following method is used to verify actual credit card numbers but, for simplicity, we will describe it for numbers with 8 digits instead of 16: • Starting from the rightmost digit, form the sum of every other digit. For example, if the credit card number is...
Furniture Store Credit Card Disclosure Statement: On approved furniture store credit card purchases—based on your credit...
Furniture Store Credit Card Disclosure Statement: On approved furniture store credit card purchases—based on your credit worthiness, other terms may apply. $2,399 minimum purchase required for this offer. Other finance offers available with lower minimum payment requirements. The purchase amount is divided into equal monthly payments for the promotional period. An additional $37 will be added to the following month’s payment when payment is received after the due date. No finance charges for 24 months. 23.9% standard rate, APR. The...
write C# console app No arrays Credit card validation Problem. A credit card number must be...
write C# console app No arrays Credit card validation Problem. A credit card number must be between 13 and 16 digits. It must start with: –4 for visa cards –5 for mater cards –37 for American express cards –6 for discover cards •Consider a credit card number 4380556218442727 •Step1: double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. •Step2: now add...
A6-5. Suppose you always use your credit card for purchases. Your credit card limit must then...
A6-5. Suppose you always use your credit card for purchases. Your credit card limit must then be thought of as part of your money holdings. A6-6. In the long run, an economy that is open to capital flows can have investment greater than national saving. A6-7. A central bank that targets inflation would conduct an expansionary monetary policy when faced with a recessionary gap. A6-8. If the policy response discussed in A6-7 is mistimed, it risks becoming pro-cyclical rather than...
What are the three things that affect your card-based credit costs?
What are the three things that affect your card-based credit costs?
The number of credit card holders of a bank in two different cities (city - X...
The number of credit card holders of a bank in two different cities (city - X and city - Y) settling their excess withdrawal amounts in time without attracting interest follows binomial distribution. The manager (collections) of the bank feels that the proportion of the number of such credit card holders in the city - X is not different from the proportion of the number of such credit card holders in the city - Y. To test his intuition, a...
Write a java program The last digit of a credit card number is the check digit,...
Write a java program The last digit of a credit card number is the check digit, which protects againts transaction errors. The following method is used to veryfy credit card numbers. For the simplicity we can assume that the credit card has 8 digits instead of 16. Follwing steps explains the algorithm in determining if a credit card number is a valid card.  Starting from the right most digit, form the sum of every other digit. For example, if...
Credit card usage in the United States is substantial. Many startup companies use credit cards as...
Credit card usage in the United States is substantial. Many startup companies use credit cards as a way to help meet short-term financial needs. The most common forms of debt for startups are use of credit cards and loans from relatives. Suppose that you start up Brothers Sandwich Shop. You invested your savings of $20,000 and borrowed $70,000 from your relatives. Although sales in the first few months are good, you see that you may not have sufficient cash to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT