forked from jbaroudi/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.payment.d.ts
116 lines (99 loc) · 3.18 KB
/
jquery.payment.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Type definitions for jQuery.payment
// Project: https://github.com/stripe/jquery.payment
// Definitions by: Eric J. Smith <https://github.com/ejsmith/>, John Rutherford <https://github.com/johnrutherford/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module JQueryPayment {
interface Payment {
/**
* Validates a card number:
* * Validates numbers
* * Validates Luhn algorithm
* * Validates length
*
* @param cardNumber The card number to validate.
*/
validateCardNumber(cardNumber: string): boolean;
/**
* Validates a card expiry:
* * Validates numbers
* * Validates in the future
* * Supports year shorthand
*
* @param year The year to validate.
* @param month The months to validate.
*/
validateCardExpiry(year: string, month: string): boolean;
/**
* Validates a card expiry:
* * Validates numbers
* * Validates in the future
* * Supports year shorthand
*
* @param expiry An object with the year and month to validate.
*/
validateCardExpiry(expiry: ExpiryInfo): boolean;
/**
* Validates a card CVC:
* * Validates number
* * Validates length to 4
*
* @param cvc The CVC value to validate.
* @param type Optional card type.
*/
validateCardCVC(cvc: string, type?: string): boolean;
/**
* Returns a card type. The function will return null if the card type can't be determined.
*
* @param cardNumber The card number to parse.
*/
cardType(cardNumber: string): string;
/**
* Parses a credit card expiry in the form of MM/YYYY, returning an object containing the month and
* year. Shorthand years, such as 13 are also supported (and converted into the longhand, e.g. 2013).
*
* @param monthYear The value to parse.
*/
cardExpiryVal(monthYear: string): ExpiryInfo;
/**
* Array of objects that describe valid card types.
*/
cards: CardInfo[];
}
interface ExpiryInfo {
month: number;
year: number;
}
interface CardInfo {
/**
* Card type
*/
type: string;
/*
* Regex used to identify the card type. For the best experience, this should be
* the shortest pattern that can guarantee the card is of a particular type.
*/
pattern: RegExp;
/**
* Array of valid card number lengths.
*/
length: number[];
/**
* Array of valid card CVC lengths.
*/
cvcLength: number[];
/**
* Boolean indicating whether a valid card number should satisfy the Luhn check.
*/
luhn: boolean;
/**
* Regex used to format the card number. Each match is joined with a space.
*/
format: RegExp;
}
}
interface JQuery {
payment(command: string): JQuery;
}
interface JQueryStatic {
payment: JQueryPayment.Payment;
}