1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
7
|
|
|
* an email on [email protected]. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\Resolver\ApplePayDirect; |
13
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface; |
15
|
|
|
use BitBag\SyliusMolliePlugin\Entity\OrderInterface; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Payments\Methods\AbstractMethod; |
17
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
18
|
|
|
|
19
|
|
|
final class ApplePayDirectPaymentTypeResolver implements ApplePayDirectPaymentTypeResolverInterface |
20
|
|
|
{ |
21
|
|
|
/** @var ApplePayDirectApiPaymentResolverInterface */ |
22
|
|
|
private $apiPaymentResolver; |
23
|
|
|
|
24
|
|
|
/** @var ApplePayDirectApiOrderPaymentResolverInterface */ |
25
|
|
|
private $apiOrderPaymentResolver; |
26
|
|
|
|
27
|
|
|
public function __construct( |
28
|
|
|
ApplePayDirectApiPaymentResolverInterface $apiPaymentResolver, |
29
|
|
|
ApplePayDirectApiOrderPaymentResolverInterface $apiOrderPaymentResolver |
30
|
|
|
) { |
31
|
|
|
$this->apiPaymentResolver = $apiPaymentResolver; |
32
|
|
|
$this->apiOrderPaymentResolver = $apiOrderPaymentResolver; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function resolve( |
36
|
|
|
MollieGatewayConfigInterface $mollieGatewayConfig, |
37
|
|
|
PaymentInterface $payment, |
38
|
|
|
array $applePayDirectToken |
39
|
|
|
): void { |
40
|
|
|
$details = []; |
41
|
|
|
$order = $payment->getOrder(); |
42
|
|
|
|
43
|
|
|
$amount = number_format(abs($payment->getAmount() / 100), 2, '.', ''); |
44
|
|
|
|
45
|
|
|
$details['amount'] = [ |
46
|
|
|
'currency' => $payment->getCurrencyCode(), |
47
|
|
|
'value' => "$amount", |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
$details['applePayDirectToken'] = json_encode($applePayDirectToken); |
51
|
|
|
$details['backurl'] = $payment->getDetails()['backurl']; |
52
|
|
|
if (AbstractMethod::ORDER_API === $mollieGatewayConfig->getPaymentType()) { |
53
|
|
|
$this->createPaymentOrder($order, $mollieGatewayConfig, $details); |
|
|
|
|
54
|
|
|
|
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->createPayment($order, $details); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function createPayment(OrderInterface $order, array $details): void |
62
|
|
|
{ |
63
|
|
|
$this->apiPaymentResolver->resolve($order, $details); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function createPaymentOrder( |
67
|
|
|
OrderInterface $order, |
68
|
|
|
MollieGatewayConfigInterface $mollieGatewayConfig, |
69
|
|
|
array $details |
70
|
|
|
): void { |
71
|
|
|
$this->apiOrderPaymentResolver->resolve($order, $mollieGatewayConfig, $details); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|