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