1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Speicher210\Fastbill\Api\Service\Coupon; |
4
|
|
|
|
5
|
|
|
use Speicher210\Fastbill\Api\AbstractService; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Service for coupon. |
9
|
|
|
*/ |
10
|
|
|
class CouponService extends AbstractService |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Get the coupons. |
14
|
|
|
* |
15
|
|
|
* @param string $code The code to get. |
16
|
|
|
* @return Get\ApiResponse |
17
|
|
|
*/ |
18
|
3 |
|
public function getCoupons($code = null) |
19
|
|
|
{ |
20
|
3 |
|
$requestData = new Get\RequestData($code); |
21
|
3 |
|
$request = new Get\Request($requestData); |
22
|
|
|
|
23
|
3 |
|
$apiResponse = $this->sendRequest($request, Get\ApiResponse::class); |
24
|
|
|
/** @var Get\Response $response */ |
25
|
3 |
|
$response = $apiResponse->getResponse(); |
26
|
3 |
|
foreach ($response->getCoupons() as $coupon) { |
27
|
3 |
|
$validFrom = $coupon->getValidFrom(); |
28
|
3 |
|
if ($validFrom !== null) { |
29
|
3 |
|
$validFrom->setTime(0, 0, 0); |
30
|
3 |
|
} |
31
|
|
|
|
32
|
3 |
|
$validTo = $coupon->getValidTo(); |
33
|
3 |
|
if ($validTo !== null) { |
34
|
3 |
|
$validTo->setTime(0, 0, 0); |
35
|
3 |
|
} |
36
|
3 |
|
} |
37
|
|
|
|
38
|
3 |
|
return $apiResponse; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check a coupon. |
43
|
|
|
* |
44
|
|
|
* @param string $code The code to check. |
45
|
|
|
* @param string $articleNumber The article number. |
46
|
|
|
* @return Check\ApiResponse |
47
|
|
|
*/ |
48
|
6 |
|
public function checkCoupon($code, $articleNumber) |
49
|
|
|
{ |
50
|
6 |
|
$requestData = new Check\RequestData($code, $articleNumber); |
51
|
6 |
|
$request = new Check\Request($requestData); |
52
|
|
|
|
53
|
6 |
|
return $this->sendRequest($request, Check\ApiResponse::class); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Check if a coupon is valid or not. |
58
|
|
|
* |
59
|
|
|
* @param string $code The code to check. |
60
|
|
|
* @param string $articleNumber The article number. |
61
|
|
|
* @return boolean |
62
|
|
|
*/ |
63
|
|
|
public function isCouponValid($code, $articleNumber) |
64
|
|
|
{ |
65
|
|
|
return $this->checkCoupon($code, $articleNumber)->getResponse()->isStatusValid(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|