|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Locastic\SyliusHTPayWayPlugin\Bridge; |
|
4
|
|
|
|
|
5
|
|
|
use Payum\Core\Action\ActionInterface; |
|
6
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
|
7
|
|
|
use Payum\Core\GatewayAwareInterface; |
|
8
|
|
|
use Payum\Core\GatewayAwareTrait; |
|
9
|
|
|
use Payum\Core\Request\Convert; |
|
10
|
|
|
use Sylius\Component\Core\Model\Order; |
|
11
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
12
|
|
|
|
|
13
|
|
|
class ConvertPaymentToHTPayWayAction implements ActionInterface, GatewayAwareInterface |
|
14
|
|
|
{ |
|
15
|
|
|
use GatewayAwareTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
* |
|
20
|
|
|
* @param Convert $request |
|
21
|
|
|
*/ |
|
22
|
|
|
public function execute($request) |
|
23
|
|
|
{ |
|
24
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
|
25
|
|
|
|
|
26
|
|
|
/** @var PaymentInterface $payment */ |
|
27
|
|
|
$payment = $request->getSource(); |
|
28
|
|
|
|
|
29
|
|
|
/** @var Order $order */ |
|
30
|
|
|
$order = $payment->getOrder(); |
|
31
|
|
|
|
|
32
|
|
|
if ($payment->getDetails()) { |
|
33
|
|
|
$request->setResult($payment->getDetails()); |
|
34
|
|
|
|
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$details = []; |
|
39
|
|
|
|
|
40
|
|
|
$details['pgwOrderId'] = $order->getNumber(); |
|
41
|
|
|
$details['pgwAmount'] = $order->getTotal(); |
|
42
|
|
|
|
|
43
|
|
|
$customer = $order->getCustomer(); |
|
44
|
|
|
|
|
45
|
|
|
if (null !== $customer) { |
|
46
|
|
|
$details['pgwEmail'] = $customer->getEmail(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// $details['pgwLanguage'] = $order->getUser()->getLocale(); |
|
50
|
|
|
|
|
51
|
|
|
$billingAddress = $order->getBillingAddress(); |
|
52
|
|
|
|
|
53
|
|
|
if (null !== $billingAddress) { |
|
54
|
|
|
$details['pgwFirstName'] = $billingAddress->getFirstName(); |
|
55
|
|
|
$details['pgwLastName'] = $billingAddress->getLastName(); |
|
56
|
|
|
$details['pgwStreet'] = $billingAddress->getStreet(); |
|
57
|
|
|
$details['pgwCity'] = $billingAddress->getCity(); |
|
58
|
|
|
$details['pgwPostCode'] = $billingAddress->getPostcode(); |
|
59
|
|
|
|
|
60
|
|
|
if ($billingAddress->getCountryCode()) { |
|
61
|
|
|
$details['pgwCountry'] = $billingAddress->getCountryCode(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$details['pgwPhoneNumber'] = $billingAddress->getPhoneNumber(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$request->setResult($details); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
|
|
public function supports($request) |
|
76
|
|
|
{ |
|
77
|
|
|
return |
|
78
|
|
|
$request instanceof Convert && |
|
79
|
|
|
$request->getSource() instanceof PaymentInterface && |
|
80
|
|
|
$request->getTo() === 'array'; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|