1 <?php
2 /**
3 * Pagarme Create Credit Card Request
4 *
5 */
6 namespace Omnipay\Pagarme\Message;
7
8
9 /**
10 * Pagarme Create Credit Card Request
11 *
12 * Whenever you make a request through the Pagarme's API the
13 * cardholder information is stored, so that in future,
14 * you can use this information to new charges, or
15 * implementing features like one-click-buy.
16 *
17 * Either a card object or card_id is required. Otherwise,
18 * you must provide a card_hash, like the ones returned by Pagarme.js.
19 *
20 * The customer_id is optional.
21 *
22 * <code>
23 * // Create a credit card object
24 * // This card can be used for testing.
25 * $new_card = new CreditCard(array(
26 * 'firstName' => 'Example',
27 * 'lastName' => 'Customer',
28 * 'number' => '5555555555554444',
29 * 'expiryMonth' => '01',
30 * 'expiryYear' => '2020',
31 * 'cvv' => '456',
32 * ));
33 *
34 * // Do a create card transaction on the gateway
35 * $response = $gateway->createCard(array(
36 * 'card' => $new_card,
37 * 'customerReference' => $customer_id,
38 * ))->send();
39 * if ($response->isSuccessful()) {
40 * echo "Gateway createCard was successful.\n";
41 * // Find the card ID
42 * $card_id = $response->getCardReference();
43 * echo "Card ID = " . $card_id . "\n";
44 * }
45 * </code>
46 *
47 * @link https://docs.pagar.me/api/?shell#cartes
48 */
49 class CreateCardRequest extends AbstractRequest
50 {
51 public function getData()
52 {
53 if ( $this->getCard() ) {
54 $data = $this->getCardData();
55 if ( $this->getCustomerReference() ) {
56 $data['customer_id'] = $this->getCustomerReference();
57 }
58 } elseif ( $this->getCardHash() ) {
59 $data['card_hash'] = $this->getCardHash();
60 } else {
61 $this->validate('card_number');
62 }
63
64 return $data;
65 }
66
67 public function getEndpoint() {
68 return $this->endpoint . 'cards';
69 }
70 }