1
|
|
|
<?php namespace Ntholenaar\MultiSafepayClient\Request; |
2
|
|
|
|
3
|
|
|
use Ntholenaar\MultiSafepayClient\Exception\InvalidRequestException; |
4
|
|
|
|
5
|
|
|
class OrderRequest extends Request |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* {@inheritdoc} |
9
|
|
|
*/ |
10
|
|
|
protected $baseUrl = 'orders'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Show order. |
14
|
|
|
* |
15
|
|
|
* @param $identifier |
16
|
|
|
* @return \Psr\Http\Message\RequestInterface |
17
|
|
|
*/ |
18
|
|
|
public function show($identifier) |
19
|
|
|
{ |
20
|
|
|
return $this->get( |
21
|
|
|
$this->uriFactory->createUri($this->getBaseUrl() . '/'. $identifier) |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Create order. |
27
|
|
|
* |
28
|
|
|
* @param array $parameters |
29
|
|
|
* @throws InvalidRequestException |
30
|
|
|
* @return \Psr\Http\Message\RequestInterface |
31
|
|
|
*/ |
32
|
|
|
public function create(array $parameters) |
33
|
|
|
{ |
34
|
|
|
$uri = $this->uriFactory->createUri($this->getBaseUrl()); |
35
|
|
|
|
36
|
|
|
if (! array_key_exists('amount', $parameters) || |
37
|
|
|
! array_key_exists('currency', $parameters) || |
38
|
|
|
! array_key_exists('description', $parameters) || |
39
|
|
|
! array_key_exists('order_id', $parameters) || |
40
|
|
|
! array_key_exists('payment_options', $parameters) || |
41
|
|
|
! array_key_exists('type', $parameters) |
42
|
|
|
) { |
43
|
|
|
throw new InvalidRequestException('Missing required parameters.'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this->post($uri, array(), $parameters); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create an direct order. |
51
|
|
|
* |
52
|
|
|
* @param array $parameters |
53
|
|
|
* @throws InvalidRequestException |
54
|
|
|
* @return \Psr\Http\Message\RequestInterface |
55
|
|
|
*/ |
56
|
|
|
public function createDirectOrder(array $parameters) |
57
|
|
|
{ |
58
|
|
|
$parameters['type'] = 'direct'; |
59
|
|
|
|
60
|
|
|
if (! array_key_exists('gateway', $parameters) || |
61
|
|
|
! array_key_exists('gateway_info', $parameters) || |
62
|
|
|
! array_key_exists('issuer_id', $parameters) |
63
|
|
|
) { |
64
|
|
|
throw new InvalidRequestException('Missing required parameters.'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this->create($parameters); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Create an redirect order. |
72
|
|
|
* |
73
|
|
|
* @param array $parameters |
74
|
|
|
* @throws InvalidRequestException |
75
|
|
|
* @return \Psr\Http\Message\RequestInterface |
76
|
|
|
*/ |
77
|
|
|
public function createRedirectOrder(array $parameters) |
78
|
|
|
{ |
79
|
|
|
$parameters['type'] = 'redirect'; |
80
|
|
|
|
81
|
|
|
return $this->create($parameters); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|