1 <?php
2 /**
3 * Credit Card class
4 */
5
6 namespace Omnipay\Pagarme;
7
8 use Omnipay\Common\CreditCard as Card;
9
10 /**
11 * Credit Card class
12 *
13 * This class extends the Omnipay's Credit Card
14 * allowing the addition of a new attribute "holder_document_number".
15 *
16 * Example:
17 *
18 * <code>
19 * // Define credit card parameters, which should look like this
20 * $parameters = array(
21 * 'firstName' => 'Bobby',
22 * 'lastName' => 'Tables',
23 * 'number' => '4444333322221111',
24 * 'cvv' => '123',
25 * 'expiryMonth' => '12',
26 * 'expiryYear' => '2017',
27 * 'email' => 'testcard@gmail.com',
28 * 'holder_document_number' => '224.158.178-40' // CPF or CNPJ
29 * );
30 *
31 * // Create a credit card object
32 * $card = new CreditCard($parameters);
33 * </code>
34 */
35
36 class CreditCard extends Card
37 {
38 /**
39 * Get Document number (CPF or CNPJ).
40 *
41 * @return string
42 */
43 public function getHolderDocumentNumber()
44 {
45 return $this->getParameter('holder_document_number');
46 }
47
48 /**
49 * Set Document Number (CPF or CNPJ)
50 *
51 * Non-numeric characters are stripped out of the document number, so
52 * it's safe to pass in strings such as "224.158.178-40" etc.
53 *
54 * @param string $value Parameter value
55 * @return CreditCard provides a fluent interface.
56 */
57 public function setHolderDocumentNumber($value)
58 {
59 // strip non-numeric characters
60 return $this->setParameter('holder_document_number', preg_replace('/\D/', '', $value));
61 }
62 }