New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@shagital/adonisjs-card-validator

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shagital/adonisjs-card-validator

Credit/Debit Card validator for Adonisjs

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Adonisjs Card Validator ▲

npm npm (scoped) NPM

Introduction

Adds credit/debit card validation functionality to Adonisjs using Luhn algorithm

Step One - Install

Via Adonis CLI

adonis install @shagital/adonisjs-card-validator

Via npm/yarn
  • Install package
// via npm
npm require @shagital/adonisjs-card-validator

// via yarn
yarn add @shagital/adonisjs-card-validator

Step Two - Register Provider

Open start/app.js and add @shagital/adonisjs-card-validator/providers/CreditCardValidationProvider to the providers array

Usage

You use the card, cvv and cardExp validation syntax just like you'd normally do validation in Adonisjs. Examples below: NOTE: The specified card type need to be supported. Currency supported card types are:

  • visaelectron
  • maestro
  • forbrugsforeningen
  • dankort
  • visa
  • mastercard
  • amex
  • dinersclub
  • discover
  • unionpay
  • jcb

controller method

//app/Controllers/Http/UserController

const { validate } = use('Validator')

class UserController {

  async store ({ request, session, response }) {
    const rules = {
      card: 'required|card', // validate card number
      cvv: 'required|cvv', // validate cvv2
      expiry_date: 'required|cardExp', // validate card expiry date in the format YYYY-MM
    }

    const validation = await validate(request.all(), rules)

    if (validation.fails()) {
      session
        .withErrors(validation.messages())
     
      return response.redirect('back')
    }

    return 'Validation passed'
  }
}

Validator

//app/Validators/StoreUser.js

'use strict'

class StoreUser {
  get rules () {
    return {
       card: 'required|card:mastercard', // validate mastercard card number
       cvv: 'required|cvv:mastercard', // validate mastercard cvv2
       expiry_date: 'required|cardExp', // validate card expiry date in the format YYYY-MM
    }
  }
}

Contribution

Free for all, if you find an issue with the package or think of an improvement, please send in a PR.

Keywords

FAQs

Package last updated on 23 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc