|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\Omnipay\Paylike\Message; |
|
4
|
|
|
|
|
5
|
|
|
use ByTIC\Omnipay\Paylike\Helper; |
|
6
|
|
|
use ByTIC\Omnipay\Paylike\Traits\HasApiTrait; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class CaptureRequest |
|
10
|
|
|
* @package ByTIC\Omnipay\Paylike\Message |
|
11
|
|
|
* |
|
12
|
|
|
* @method CaptureResponse send |
|
13
|
|
|
*/ |
|
14
|
|
|
class CaptureRequest extends AbstractRequest |
|
15
|
|
|
{ |
|
16
|
|
|
use HasApiTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return array |
|
20
|
|
|
* @throws \Omnipay\Common\Exception\InvalidRequestException |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getData() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->validate('privateKey', 'transactionId', 'amount'); |
|
25
|
|
|
|
|
26
|
|
|
$data = ['success' => false]; |
|
27
|
|
|
|
|
28
|
|
|
$parameters = [ |
|
29
|
|
|
'amount' => $this->getAmount() * 100, |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
//optionals |
|
33
|
|
|
$currency = $this->getParameter('currency'); |
|
34
|
|
|
if (is_string($currency) && strlen($currency) === 3) { |
|
35
|
|
|
$parameters['currency'] = $currency; |
|
36
|
|
|
} |
|
37
|
|
|
$descriptor = $this->getParameter('descriptor'); |
|
38
|
|
|
if (is_string($descriptor)) { |
|
39
|
|
|
if(Helper::validateDescriptor($descriptor)){ |
|
40
|
|
|
throw new \Omnipay\Common\Exception\InvalidRequestException("The descriptor does not conform to requirements."); |
|
41
|
|
|
} |
|
42
|
|
|
$parameters['descriptor'] = $descriptor; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
try { |
|
47
|
|
|
$transactions = $this->getApi()->transactions(); |
|
48
|
|
|
$transaction = $transactions->capture( |
|
49
|
|
|
$this->getTransactionId(), |
|
50
|
|
|
$parameters |
|
51
|
|
|
); |
|
52
|
|
|
if (is_array($transaction)) { |
|
|
|
|
|
|
53
|
|
|
$data['transaction'] = $transaction; |
|
54
|
|
|
$data['success'] = true; |
|
55
|
|
|
} |
|
56
|
|
|
} catch (\Paylike\Exception\NotFound $e) { |
|
57
|
|
|
//The transaction was not found |
|
58
|
|
|
$data['exception_class'] = "\Paylike\Exception\NotFound"; |
|
59
|
|
|
$data['message'] = "The transaction was not found"; |
|
60
|
|
|
|
|
61
|
|
|
} catch (\Paylike\Exception\InvalidRequest $e) { |
|
62
|
|
|
// Bad (invalid) request - see $e->getJsonBody() for the error |
|
63
|
|
|
$data['exception_class'] = "\Paylike\Exception\InvalidRequest"; |
|
64
|
|
|
$data['message'] = "Bad (invalid) request - ".substr(json_encode($e->getJsonBody()), 0, 250 ); |
|
65
|
|
|
|
|
66
|
|
|
} catch (\Paylike\Exception\Forbidden $e) { |
|
67
|
|
|
// You are correctly authenticated but do not have access. |
|
68
|
|
|
$data['exception_class'] = "\Paylike\Exception\Forbidden"; |
|
69
|
|
|
$data['message'] = "You are correctly authenticated but do not have access."; |
|
70
|
|
|
|
|
71
|
|
|
} catch (\Paylike\Exception\Unauthorized $e) { |
|
72
|
|
|
// You need to provide credentials (an app's API key) |
|
73
|
|
|
$data['exception_class'] = "\Paylike\Exception\Unauthorized"; |
|
74
|
|
|
$data['message'] = "You need to provide credentials (an app's API key)"; |
|
75
|
|
|
|
|
76
|
|
|
} catch (\Paylike\Exception\Conflict $e) { |
|
77
|
|
|
// Everything you submitted was fine at the time of validation, but something changed in the meantime and came into conflict with this (e.g. double-capture). |
|
78
|
|
|
$data['exception_class'] = "\Paylike\Exception\Conflict"; |
|
79
|
|
|
$data['message'] = "Everything you submitted was fine at the time of validation, but something changed in the meantime and came into conflict with this (e.g. double-capture)"; |
|
80
|
|
|
|
|
81
|
|
|
} catch (\Paylike\Exception\ApiConnection $e) { |
|
82
|
|
|
// Network error on connecting via cURL |
|
83
|
|
|
$data['exception_class'] = "\Paylike\Exception\ApiConnection"; |
|
84
|
|
|
$data['message'] = "Network error on connecting via cURL"; |
|
85
|
|
|
|
|
86
|
|
|
} catch (\Paylike\Exception\ApiException $e) { |
|
87
|
|
|
$data['exception_class'] = "\Paylike\Exception\ApiException"; |
|
88
|
|
|
$data['message'] = "Api Error:" . $e->getMessage(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $data; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|