|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pin\Charge; |
|
4
|
|
|
|
|
5
|
|
|
use Pin\RequestInterface; |
|
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
7
|
|
|
|
|
8
|
|
|
class Create implements RequestInterface |
|
9
|
|
|
{ |
|
10
|
|
|
protected $options; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct(array $options = array()) |
|
13
|
|
|
{ |
|
14
|
|
|
$resolver = new OptionsResolver(); |
|
15
|
|
|
$this->setDefaultOptions($resolver); |
|
16
|
|
|
|
|
17
|
|
|
$this->options = $resolver->resolve($options); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
protected function setDefaultOptions(OptionsResolver $resolver) |
|
21
|
|
|
{ |
|
22
|
|
|
$resolver |
|
23
|
|
|
->setRequired(array( |
|
24
|
|
|
'amount', |
|
25
|
|
|
'description', |
|
26
|
|
|
'email' |
|
27
|
|
|
)) |
|
28
|
|
|
->setDefined(array( |
|
29
|
|
|
'currency', |
|
30
|
|
|
'ip_address', |
|
31
|
|
|
'card', |
|
32
|
|
|
'card_token', |
|
33
|
|
|
'customer_token', |
|
34
|
|
|
'capture' |
|
35
|
|
|
)) |
|
36
|
|
|
->setAllowedTypes('currency', 'string') |
|
37
|
|
|
->setAllowedTypes('amount', 'numeric') |
|
38
|
|
|
->setAllowedTypes('description', 'string') |
|
39
|
|
|
->setAllowedTypes('email', 'string') |
|
40
|
|
|
->setAllowedTypes('card', 'array') |
|
41
|
|
|
->setAllowedTypes('card_token', 'string') |
|
42
|
|
|
->setAllowedTypes('customer_token', 'string') |
|
43
|
|
|
->setAllowedTypes('capture', 'string') |
|
44
|
|
|
->setAllowedValues('currency', array('AUD', 'USD', 'NZD', 'SGD', 'EUR', 'GBP', 'CAD', 'HKD', 'JPY')) |
|
45
|
|
|
; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getMethod() |
|
52
|
|
|
{ |
|
53
|
|
|
return self::METHOD_POST; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getPath() |
|
60
|
|
|
{ |
|
61
|
|
|
return '/1/charges'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getData() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->options; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|