1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Braintree\Business\Payment\Transaction; |
9
|
|
|
|
10
|
|
|
use Braintree\Transaction as BraintreeTransaction; |
11
|
|
|
use SprykerEco\Zed\Braintree\BraintreeConfig; |
12
|
|
|
use SprykerEco\Zed\Braintree\Business\Payment\Method\ApiConstants; |
13
|
|
|
use SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface; |
14
|
|
|
|
15
|
|
|
class CaptureItemsTransaction extends AbstractTransaction |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface |
19
|
|
|
*/ |
20
|
|
|
protected $moneyFacade; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \SprykerEco\Zed\Braintree\BraintreeConfig $config |
24
|
|
|
* @param \SprykerEco\Zed\Braintree\Dependency\Facade\BraintreeToMoneyFacadeInterface $moneyFacade |
25
|
|
|
*/ |
26
|
|
|
public function __construct( |
27
|
|
|
BraintreeConfig $config, |
28
|
|
|
BraintreeToMoneyFacadeInterface $moneyFacade |
29
|
|
|
) { |
30
|
|
|
parent::__construct($config); |
31
|
|
|
$this->moneyFacade = $moneyFacade; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
protected function getTransactionType() |
38
|
|
|
{ |
39
|
|
|
return ApiConstants::SALE; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
protected function getTransactionCode() |
46
|
|
|
{ |
47
|
|
|
return ApiConstants::TRANSACTION_CODE_CAPTURE; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \Braintree\Result\Error|\Braintree\Result\Successful |
52
|
|
|
*/ |
53
|
|
|
protected function doTransaction() |
54
|
|
|
{ |
55
|
|
|
return $this->capture(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return \Braintree\Result\Error|\Braintree\Result\Successful |
60
|
|
|
*/ |
61
|
|
|
protected function capture() |
62
|
|
|
{ |
63
|
|
|
return BraintreeTransaction::submitForPartialSettlement( |
64
|
|
|
$this->getTransactionIdentifier(), |
65
|
|
|
$this->getDecimalAmountValueFromInt($this->transactionMetaTransfer->getCaptureAmount()) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param int $amount |
71
|
|
|
* |
72
|
|
|
* @return float |
73
|
|
|
*/ |
74
|
|
|
protected function getDecimalAmountValueFromInt(int $amount): float |
75
|
|
|
{ |
76
|
|
|
return $this->moneyFacade->convertIntegerToDecimal($amount); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|