1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apoca\Sibs\Services; |
4
|
|
|
|
5
|
|
|
use Apoca\Sibs\Brands\Card; |
6
|
|
|
use Apoca\Sibs\Brands\Checkout; |
7
|
|
|
use Apoca\Sibs\Brands\PaymentWithCard; |
8
|
|
|
use Apoca\Sibs\Brands\PaymentWithMBWay; |
9
|
|
|
use Apoca\Sibs\Brands\Transaction; |
10
|
|
|
use Apoca\Sibs\Contracts\PaymentInterface; |
11
|
|
|
use Exception; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class SibsService |
15
|
|
|
* |
16
|
|
|
* @package Apoca\Sibs\Services |
17
|
|
|
*/ |
18
|
|
|
class SibsService |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param array $request |
22
|
|
|
* |
23
|
|
|
* @return PaymentInterface |
24
|
|
|
* @throws Exception |
25
|
|
|
*/ |
26
|
|
|
public function checkout(array $request): PaymentInterface |
27
|
|
|
{ |
28
|
|
|
switch (strtoupper($request['brand'])) { |
29
|
|
|
case 'MASTER': |
30
|
|
|
case 'AMEX': |
31
|
|
|
case 'VPAY': |
32
|
|
|
case 'MAESTRO': |
33
|
|
|
case 'VISADEBIT': |
34
|
|
|
case 'VISAELECTRON': |
35
|
|
|
case 'VISA': |
36
|
|
|
$payment = new PaymentWithCard( |
37
|
|
|
$request['amount'], |
38
|
|
|
strtoupper($request['currency']), |
39
|
|
|
strtoupper($request['brand']), |
40
|
|
|
strtoupper($request['type']), |
41
|
|
|
$request['optionalParameters'], |
42
|
|
|
new Card( |
43
|
|
|
$request['number'], |
44
|
|
|
$request['holder'], |
45
|
|
|
$request['expiry_month'], |
46
|
|
|
$request['expiry_year'], |
47
|
|
|
$request['cvv'] |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
break; |
51
|
|
|
case 'CHECKOUT': |
52
|
|
|
$payment = new Checkout($request['amount'], $request['currency'], $request['type'], $request['optionalParameters']); |
53
|
|
|
break; |
54
|
|
|
case 'SIBS_MULTIBANCO': |
55
|
|
|
throw new \RuntimeException('SIBS_MULTIBANCO Service Payment not found.', 404); |
56
|
|
|
break; |
57
|
|
|
case 'DIRECTDEBIT_SEPA': |
58
|
|
|
throw new \RuntimeException('DIRECTDEBIT_SEPA Service Payment not found.', 404); |
59
|
|
|
break; |
60
|
|
|
case 'MBWAY': |
61
|
|
|
$payment = new PaymentWithMBWay( |
62
|
|
|
$request['amount'], |
63
|
|
|
strtoupper($request['currency']), |
64
|
|
|
strtoupper($request['brand']), |
65
|
|
|
strtoupper($request['type']), |
66
|
|
|
$request['accountId'], |
67
|
|
|
$request['optionalParameters'] |
68
|
|
|
); |
69
|
|
|
break; |
70
|
|
|
default: |
71
|
|
|
throw new \RuntimeException('Sibs Service Payment not found.', 404); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $payment; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get payment status |
79
|
|
|
* |
80
|
|
|
* @param string $checkoutId |
81
|
|
|
* |
82
|
|
|
* @return object |
83
|
|
|
*/ |
84
|
|
|
public function status(string $checkoutId): object |
85
|
|
|
{ |
86
|
|
|
return (new Transaction($checkoutId))->status(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|