1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\BillPay\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\BillPay\Message\RequestData\ArticleDataTrait; |
6
|
|
|
use Omnipay\BillPay\Message\RequestData\BankAccountTrait; |
7
|
|
|
use Omnipay\BillPay\Message\RequestData\CompanyDetailsTrait; |
8
|
|
|
use Omnipay\BillPay\Message\RequestData\CustomerDetailsTrait; |
9
|
|
|
use Omnipay\BillPay\Message\RequestData\DataTrait; |
10
|
|
|
use Omnipay\BillPay\Message\RequestData\RateTrait; |
11
|
|
|
use Omnipay\BillPay\Message\RequestData\ShippingDetailsTrait; |
12
|
|
|
use Omnipay\BillPay\Message\RequestData\TotalTrait; |
13
|
|
|
use Omnipay\Common\Exception\InvalidRequestException; |
14
|
|
|
use Omnipay\Common\Message\ResponseInterface; |
15
|
|
|
use SimpleXMLElement; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Message AuthorizeRequest. |
19
|
|
|
* |
20
|
|
|
* @link https://techdocs.billpay.de/en/For_developers/XML_API/Preauthorize.html |
21
|
|
|
* |
22
|
|
|
* @author Andreas Lange <[email protected]> |
23
|
|
|
* @copyright 2016, Connox GmbH |
24
|
|
|
* @license MIT |
25
|
|
|
*/ |
26
|
|
|
class AuthorizeRequest extends AbstractRequest |
27
|
|
|
{ |
28
|
|
|
use DataTrait; |
29
|
|
|
use CustomerDetailsTrait; |
30
|
|
|
use CompanyDetailsTrait; |
31
|
|
|
use ShippingDetailsTrait; |
32
|
|
|
use ArticleDataTrait; |
33
|
|
|
use TotalTrait; |
34
|
|
|
use RateTrait; |
35
|
|
|
use BankAccountTrait; |
36
|
|
|
|
37
|
|
|
const PAYMENT_TYPE_INVOICE = 'invoice'; |
38
|
|
|
const PAYMENT_TYPE_DIRECT_DEBIT = 'direct_debit'; |
39
|
|
|
const PAYMENT_TYPE_TRANSACTION_CREDIT = 'transaction_credit'; |
40
|
|
|
const PAYMENT_TYPE_PAY_LATER = 'pay_later'; |
41
|
|
|
const PAYMENT_TYPE_COLLATERAL_PROMISE = 'collateral_promise'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the raw data array for this message. The format of this varies from gateway to |
45
|
|
|
* gateway, but will usually be either an associative array, or a SimpleXMLElement. |
46
|
|
|
* |
47
|
|
|
* @throws InvalidRequestException |
48
|
|
|
* |
49
|
|
|
* @return SimpleXMLElement |
50
|
|
|
*/ |
51
|
15 |
|
public function getData() |
52
|
|
|
{ |
53
|
15 |
|
$this->validateData(); |
54
|
|
|
|
55
|
12 |
|
$data = $this->getBaseData(); |
56
|
|
|
|
57
|
12 |
|
$this->appendData($data); |
58
|
11 |
|
$this->appendCustomerDetails($data); |
59
|
11 |
|
$this->appendCompanyDetails($data); |
60
|
11 |
|
$this->appendShippingDetails($data); |
61
|
11 |
|
$this->appendArticleData($data); |
62
|
10 |
|
$this->appendTotal($data); |
63
|
9 |
|
$this->appendRate($data); |
64
|
9 |
|
$this->appendBankAccount($data); |
65
|
|
|
|
66
|
9 |
|
return $data; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Set the payment method. |
71
|
|
|
* |
72
|
|
|
* @param string $value |
73
|
|
|
* |
74
|
|
|
* @throws InvalidRequestException |
75
|
|
|
* |
76
|
|
|
* @return AbstractRequest Provides a fluent interface |
77
|
|
|
* |
78
|
|
|
* @see AuthorizeRequest::PAYMENT_TYPE_* |
79
|
|
|
*/ |
80
|
18 |
|
public function setPaymentMethod($value) |
81
|
|
|
{ |
82
|
18 |
|
if ($value !== null && ! array_key_exists($value, self::$paymentTypes)) { |
83
|
1 |
|
throw new InvalidRequestException(sprintf('Unknown payment method specified \'%s\' specified.', $value)); |
84
|
|
|
} |
85
|
|
|
|
86
|
18 |
|
return parent::setPaymentMethod($value); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param SimpleXMLElement $response |
91
|
|
|
* |
92
|
|
|
* @return ResponseInterface |
93
|
|
|
*/ |
94
|
7 |
|
protected function createResponse($response) |
95
|
|
|
{ |
96
|
7 |
|
return $this->response = new AuthorizeResponse($this, $response); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
7 |
|
protected function getEndpoint() |
103
|
|
|
{ |
104
|
7 |
|
return parent::getEndpoint() . '/preauthorize'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @throws InvalidRequestException |
109
|
|
|
*/ |
110
|
15 |
|
private function validateData() |
111
|
|
|
{ |
112
|
15 |
|
$this->validateDataCard(); |
113
|
14 |
|
$this->validateDataItems(); |
114
|
13 |
|
$this->validateDataCustomerDetails(); |
115
|
12 |
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @throws InvalidRequestException |
119
|
|
|
*/ |
120
|
15 |
|
private function validateDataCard() |
121
|
|
|
{ |
122
|
15 |
|
if ($this->getCard() === null) { |
123
|
1 |
|
throw new InvalidRequestException('Credit card object required.'); |
124
|
|
|
} |
125
|
14 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @throws InvalidRequestException |
129
|
|
|
*/ |
130
|
13 |
|
private function validateDataCustomerDetails() |
131
|
|
|
{ |
132
|
13 |
|
if ($this->getCustomerDetails() === null) { |
133
|
1 |
|
throw new InvalidRequestException('Customer object required.'); |
134
|
|
|
} |
135
|
12 |
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @throws InvalidRequestException |
139
|
|
|
*/ |
140
|
14 |
|
private function validateDataItems() |
141
|
|
|
{ |
142
|
14 |
|
if ($this->getItems() === null || $this->getItems()->count() === 0) { |
143
|
1 |
|
throw new InvalidRequestException('Item objects are required.'); |
144
|
|
|
} |
145
|
13 |
|
} |
146
|
|
|
} |
147
|
|
|
|