1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: WilliamWard |
5
|
|
|
* Date: 8/6/2018 |
6
|
|
|
* Time: 8:44 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace GivePay\Gateway\Transactions; |
10
|
|
|
|
11
|
|
|
final class Card |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string The PAN for the card |
16
|
|
|
*/ |
17
|
|
|
private $pan; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string The card holder's CVV/CVV2 |
21
|
|
|
*/ |
22
|
|
|
private $cvv; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string The card's expiration month (MM) |
26
|
|
|
*/ |
27
|
|
|
private $expiration_month; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string The card's expiration year (YY) |
31
|
|
|
*/ |
32
|
|
|
private $expiration_year; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string The token |
36
|
|
|
*/ |
37
|
|
|
private $token; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool Whether or not this card should be treated as a token |
41
|
|
|
*/ |
42
|
|
|
private $is_token_card = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates a card from information from a physical card |
46
|
|
|
* @param string $pan |
47
|
|
|
* @param string $cvv |
48
|
|
|
* @param string $expiration_month |
49
|
|
|
* @param string $expiration_year |
50
|
|
|
* |
51
|
|
|
* @return Card |
52
|
|
|
*/ |
53
|
4 |
|
public static function withCard($pan, $cvv, $expiration_month, $expiration_year) |
54
|
|
|
{ |
55
|
4 |
|
$card = new self(); |
56
|
4 |
|
$card->pan = $pan; |
57
|
4 |
|
$card->cvv = $cvv; |
58
|
4 |
|
$card->expiration_month = $expiration_month; |
59
|
4 |
|
$card->expiration_year = $expiration_year; |
60
|
|
|
|
61
|
4 |
|
return $card; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Creates a card from a payment token |
66
|
|
|
* @param string $token The payment card token |
67
|
|
|
* @param string $cvv The optional cvc/cvv2 value for the card |
68
|
|
|
* @return Card |
69
|
|
|
*/ |
70
|
3 |
|
public static function withToken($token, $cvv = null) |
71
|
|
|
{ |
72
|
3 |
|
$card = new self(); |
73
|
3 |
|
$card->token = $token; |
74
|
3 |
|
$card->cvv = $cvv; |
75
|
3 |
|
$card->is_token_card = true; |
76
|
|
|
|
77
|
3 |
|
return $card; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array Serializes the card into a GPG request param |
82
|
|
|
*/ |
83
|
5 |
|
public function serialize() |
84
|
|
|
{ |
85
|
5 |
|
if ($this->isTokenCard()) { |
86
|
|
|
return array( |
87
|
2 |
|
'token' => $this->token, |
88
|
2 |
|
'cvv' => $this->cvv |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return array( |
93
|
3 |
|
'card_number' => $this->pan, |
94
|
|
|
'card_present' => false, |
95
|
3 |
|
'expiration_month' => $this->expiration_month, |
96
|
3 |
|
'expiration_year' => $this->expiration_year, |
97
|
3 |
|
'cvv' => $this->cvv |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return bool Whether or not this card is tokenized |
103
|
|
|
*/ |
104
|
5 |
|
private function isTokenCard() |
105
|
|
|
{ |
106
|
5 |
|
return $this->is_token_card; |
107
|
|
|
} |
108
|
|
|
} |