1.1.4 • Published 3 years ago

@delrio/credit-card v1.1.4

Weekly downloads
33
License
MIT
Repository
-
Last release
3 years ago

Credit Card to Angular

Alt text


See Demo Page


Versions


AngularCredit Card
>= 11v1.x

Getting Started

Step 1: Install @delrio/credit-card

NPM:
npm install --save @delrio/credit-card

Step 2: Import the CreditCardModule module:

import { CreditCardModule } from '@delrio/credit-card';
import { FormsModule } from '@angular/forms';

@NgModule({
  declarations: [AppComponent],
  imports: [CreditCardModule.forRoot({}), FormsModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

Step 3 (Optional): Configuration Module

import { CreditCardModule } from '@delrio/credit-card';
import { FormsModule } from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    FormsModule,
    CreditCardModule.forRoot({
     cardFront: {
        labelInitialCardNumber: 'XXXX XXXX XXXX XXXX',
        labelInitialDateValid: '**/**',
        labelInitialPersonName: 'NOMBRE DE LA PERSONA',
        labelMonthYear: 'AÑO/MES',
        labelValidUntilText: 'VALIDO HASTA'
     },
     cardBack: {
        labelInitialCVC: '***',
        labelTextFooter: 'Todos los derechos reservados'
     }
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

Define options in your consuming component:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { CreditCardComponent } from '@delrio/credit-card';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  form!: FormGroup;

  @ViewChild('creditCardComponent', { static: true })
  creditCardComponent!: CreditCardComponent

  @ViewChild('creditCardNumberRef', { static: true })
  creditCardNumberRef!: ElementRef;

  @ViewChild('creditCardPersonNameRef', { static: true })
  creditCardPersonNameRef!: ElementRef;

  @ViewChild('creditCardDateValidRef', { static: true })
  creditCardDateValidRef!: ElementRef;

  @ViewChild('creditCardCVC', { static: true })
  creditCardCVC!: ElementRef;


  constructor() { }

  ngOnInit(): void {
    this.form = new FormGroup({
      cardNumber: new FormControl('378282246310005', Validators.required),
      cardPersonName: new FormControl('Juan Perez', Validators.required),
      validDate: new FormControl('10/20', Validators.required),
      cvc: new FormControl('123', Validators.required)
    })

    // Assign Refs of input controls
    this.creditCardComponent.creditCardNumberInputRef = this.creditCardNumberRef;
    this.creditCardComponent.creditCardDateValidInputRef = this.creditCardDateValidRef;
    this.creditCardComponent.creditCardPersonNameInputRef = this.creditCardPersonNameRef;
    this.creditCardComponent.creditCardCVCInputRef = this.creditCardCVC;
  }

}

In template use d-credit-card component with your options

<d-credit-card #creditCardComponent></d-credit-card>
    <form [formGroup]="form">
      <label for="creditcard_number">Número de tarjeta</label>
      <input type="text" id="creditcard_number" formControlName="cardNumber" #creditCardNumberRef> <br>

      <label for="creditcard_person_name">Nombre</label>
      <input type="text" id="creditcard_person_name" formControlName="cardPersonName" #creditCardPersonNameRef> <br>

      <label for="creditcard_date_valid">Fecha de Vencimiento</label>
      <input type="text" id="creditcard_date_valid" formControlName="validDate" #creditCardDateValidRef> <br>

      <label for="creditcard_date_valid">CVC</label>
      <input type="text" id="creditcard_cvc" formControlName="cvc" #creditCardCVC>
    </form>

API

INPUTS

InputTypeDefaultRequiredDescription
labelInitialCardNumberstring•••• •••• •••• ••••noShow the placeholder text of the card number
labelInitialDateValidstring••/••noShow the placeholder text of the card date valid
labelInitialPersonNamestringNombre de la personanoShow the placeholder text of the card name person
labelMonthYearstringMM/YYnoShow the placeholder text of the card date month year
labelValidUntilTextstringValido HastanoShow the placeholder text of the card valid until
labelInitialCVCstring•••noShow the placeholder text label initial CVC
labelTextFooterstringThis card has been issued by Oscar Del Rio and is licensed for anyone to use anywhere for free.noShow the placeholder text of Label Text Footer Card Back
creditCardNumberInputRefstringnullyesElement Ref of the input to bind card number
creditCardPersonNameInputRefstringnullyesElement Ref of the input to bind to name person
creditCardDateValidInputRefstringnullyesElement Ref of the input to bind to valid to

OUTPUTS

OutputDescription
(creditFoundName)Name of the card type found
1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago