File: Zend_Validate-CreditCard.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (362 lines) | stat: -rw-r--r-- 12,675 bytes parent folder | download | duplicates (2)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.validate.set.creditcard">
    <title>CreditCard</title>

    <para>
        <classname>Zend_Validate_CreditCard</classname> allows you to validate if a given value
        could be a credit card number.
    </para>

    <para>
        A creditcard contains several items of metadata, including a hologram, account number, logo,
        expiration date, security code and the card holder name. The algorithms for verifying the
        combination of metadata are only known to the issuing company, and should be verified with
        them for purposes of payment. However, it's often useful to know whether or not a given
        number actually falls within the ranges of possible numbers <emphasis>prior</emphasis> to
        performing such verification, and, as such, <classname>Zend_Validate_CreditCard</classname>
        simply verifies that the credit card number provided is well-formed.
    </para>

    <para>
        For those cases where you have a service that can perform comprehensive verification,
        <classname>Zend_Validate_CreditCard</classname> also provides the ability to attach a
        service callback to trigger once the credit card number has been deemed valid; this callback
        will then be triggered, and its return value will determine overall validity.
    </para>

    <para>
        The following issuing institutes are accepted:
    </para>

    <itemizedlist>
        <listitem>
            <para>
                <emphasis>American Express</emphasis>
            </para>

            <para>
                <emphasis>China UnionPay</emphasis>
            </para>

            <para>
                <emphasis>Diners Club Card Blanche</emphasis>
            </para>

            <para>
                <emphasis>Diners Club International</emphasis>
            </para>

            <para>
                <emphasis>Diners Club US &amp; Canada</emphasis>
            </para>

            <para>
                <emphasis>Discover Card</emphasis>
            </para>

            <para>
                <emphasis>JCB</emphasis>
            </para>

            <para>
                <emphasis>Laser</emphasis>
            </para>

            <para>
                <emphasis>Maestro</emphasis>
            </para>

            <para>
                <emphasis>MasterCard</emphasis>
            </para>

            <para>
                <emphasis>Solo</emphasis>
            </para>

            <para>
                <emphasis>Visa</emphasis>
            </para>

            <para>
                <emphasis>Visa Electron</emphasis>
            </para>
        </listitem>
    </itemizedlist>

    <note>
        <title>Invalid institutes</title>

        <para>
            The institutes <emphasis>Bankcard</emphasis> and <emphasis>Diners Club
                enRoute</emphasis> do not exist anymore. Therefore they are treated as invalid.
        </para>

        <para>
            <emphasis>Switch</emphasis> has been rebranded to <emphasis>Visa</emphasis> and is
            therefore also treated as invalid.
        </para>
    </note>

    <sect3 id="zend.validate.set.creditcard.options">
        <title>Supported options for Zend_Validate_CreditCard</title>

        <para>
            The following options are supported for <classname>Zend_Validate_CreditCard</classname>:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis><property>service</property></emphasis>: A callback to an online
                    service which will additionally be used for the validation.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis><property>type</property></emphasis>: The type of creditcard which
                    will be validated. See the below list of institutes for details.
                </para>
            </listitem>
        </itemizedlist>
    </sect3>

    <sect3 id="zend.validate.set.creditcard.basic">
        <title>Basic usage</title>

        <para>
            There are several credit card institutes which can be validated by
            <classname>Zend_Validate_CreditCard</classname>. Per default, all known institutes will
            be accepted. See the folowing example:
        </para>

        <programlisting language="php"><![CDATA[
$valid = new Zend_Validate_CreditCard();
if ($valid->isValid($input)) {
    // input appears to be valid
} else {
    // input is invalid
}
]]></programlisting>

        <para>
            The above example would validate against all known credit card institutes.
        </para>
    </sect3>

    <sect3 id="zend.validate.set.creditcard.institute">
        <title>Accepting defined credit cards</title>

        <para>
            Sometimes it is necessary to accept only defined credit card institutes instead of all;
            e.g., when you have a webshop which accepts only Visa and American Express cards.
            <classname>Zend_Validate_CreditCard</classname> allows you to do exactly this by
            limiting it to exactly these institutes.
        </para>

        <para>
            To use a limitation you can either provide specific institutes at initiation, or
            afterwards by using <methodname>setType()</methodname>. Each can take several arguments.
        </para>

        <para>
            You can provide a single institute:
        </para>

        <programlisting language="php"><![CDATA[
$valid = new Zend_Validate_CreditCard(
    Zend_Validate_CreditCard::AMERICAN_EXPRESS
);
]]></programlisting>

        <para>
            When you want to allow multiple institutes, then you can provide them as array:
        </para>

        <programlisting language="php"><![CDATA[
$valid = new Zend_Validate_CreditCard(array(
    Zend_Validate_CreditCard::AMERICAN_EXPRESS,
    Zend_Validate_CreditCard::VISA
));
]]></programlisting>

        <para>
            And as with all validators, you can also pass an associative array of options or an
            instance of <classname>Zend_Config</classname>. In this case you have to provide the
            institutes with the <property>type</property> array key as simulated here:
        </para>

        <programlisting language="php"><![CDATA[
$valid = new Zend_Validate_CreditCard(array(
    'type' => array(Zend_Validate_CreditCard::AMERICAN_EXPRESS)
));
]]></programlisting>

        <table id="zend.validate.set.creditcard.institute.table">
            <title>Constants for credit card institutes</title>

            <tgroup cols="2">
                <thead>
                    <row>
                        <entry>Institute</entry>
                        <entry>Constant</entry>
                    </row>
                </thead>

                <tbody>
                    <row>
                        <entry><emphasis>American Express</emphasis></entry>
                        <entry><constant>AMERICAN_EXPRESS</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>China UnionPay</emphasis></entry>
                        <entry><constant>UNIONPAY</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Diners Club Card Blanche</emphasis></entry>
                        <entry><constant>DINERS_CLUB</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Diners Club International</emphasis></entry>
                        <entry><constant>DINERS_CLUB</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Diners Club US &amp; Canada</emphasis></entry>
                        <entry><constant>DINERS_CLUB_US</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Discover Card</emphasis></entry>
                        <entry><constant>DISCOVER</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>JCB</emphasis></entry>
                        <entry><constant>JCB</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Laser</emphasis></entry>
                        <entry><constant>LASER</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Maestro</emphasis></entry>
                        <entry><constant>MAESTRO</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>MasterCard</emphasis></entry>
                        <entry><constant>MASTERCARD</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Solo</emphasis></entry>
                        <entry><constant>SOLO</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Visa</emphasis></entry>
                        <entry><constant>VISA</constant></entry>
                    </row>

                    <row>
                        <entry><emphasis>Visa Electron</emphasis></entry>
                        <entry><constant>VISA</constant></entry>
                    </row>
                </tbody>
            </tgroup>
        </table>

        <para>
            You can also set or add institutes afterward instantiation by using the methods
            <methodname>setType()</methodname>, <methodname>addType()</methodname> and
            <methodname>getType()</methodname>.
        </para>

        <programlisting language="php"><![CDATA[
$valid = new Zend_Validate_CreditCard();
$valid->setType(array(
    Zend_Validate_CreditCard::AMERICAN_EXPRESS,
    Zend_Validate_CreditCard::VISA
));
]]></programlisting>

        <note>
            <title>Default institute</title>

            <para>
                When no institute is given at initiation then <constant>ALL</constant> will be
                used, which sets all institutes at once.
            </para>

            <para>
                In this case the usage of <methodname>addType()</methodname> is useless because all
                institutes are already added.
            </para>
        </note>
    </sect3>

    <sect3 id="zend.validate.set.creditcard.servicecheck">
        <title>Validation by using foreign APIs</title>

        <para>
            As said before <classname>Zend_Validate_CreditCard</classname> will only validate
            the credit card number. Fortunately, some institutes provide online
            <acronym>API</acronym>s which can validate a credit card number by using algorithms
            which are not available to the public. Most of these services are paid services.
            Therefore, this check is deactivated per default.
        </para>

        <para>
            When you have access to such an <acronym>API</acronym>, then you can use it as an addon
            for <classname>Zend_Validate_CreditCard</classname> and increase the security of the
            validation.
        </para>

        <para>
            To do so, you simply need to give a callback which will be called when the generic
            validation has passed. This prevents the <acronym>API</acronym> from being called
            for invalid numbers, which increases the performance of the application.
        </para>

        <para>
            <methodname>setService()</methodname> sets a new service, and
            <methodname>getService()</methodname> returns the set service. As a configuration
            option,
            you can give the array key '<property>service</property>' at initiation. For details
            about possible options take a look into <link
                linkend="zend.validate.set.callback">Callback</link>.
        </para>

        <programlisting language="php"><![CDATA[
// Your service class
class CcService
{
    public function checkOnline($cardnumber, $types)
    {
        // some online validation
    }
}

// The validation
$service = new CcService();
$valid   = new Zend_Validate_CreditCard(Zend_Validate_CreditCard::VISA);
$valid->setService(array($service, 'checkOnline'));
]]></programlisting>

        <para>
            As you can see the callback method will be called with the creditcard number as the
            first parameter, and the accepted types as the second parameter.
        </para>
    </sect3>
</sect2>
<!--
vim:se ts=4 sw=4 et:
-->