1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Eres\SyliusIyzicoPlugin\Action; |
6
|
|
|
|
7
|
|
|
use Eres\SyliusIyzicoPlugin\Bridge\IyzicoBridgeInterface; |
8
|
|
|
use Payum\Core\Action\ActionInterface; |
9
|
|
|
use Payum\Core\GatewayAwareInterface; |
10
|
|
|
use Payum\Core\GatewayAwareTrait; |
11
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
12
|
|
|
use Payum\Core\Request\Convert; |
13
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class ConvertPaymentAction implements ActionInterface, GatewayAwareInterface |
17
|
|
|
{ |
18
|
|
|
use GatewayAwareTrait; |
19
|
|
|
|
20
|
|
|
public function execute($request): void |
21
|
|
|
{ |
22
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
23
|
|
|
|
24
|
|
|
/** @var PaymentInterface $payment */ |
25
|
|
|
$payment = $request->getSource(); |
26
|
|
|
|
27
|
|
|
$order = $payment->getOrder(); |
28
|
|
|
|
29
|
|
|
$details = [ |
30
|
|
|
'iyzico_id' => $order->getId(), |
31
|
|
|
'iyzico_currency_code' => $order->getCurrencyCode(), |
|
|
|
|
32
|
|
|
'iyzico_order_number' => $order->getNumber(), |
33
|
|
|
'iyzico_total' => $order->getTotal() / 100, |
34
|
|
|
'iyzico_local_code' => explode("_", $order->getLocaleCode())[0], |
|
|
|
|
35
|
|
|
'iyzico_target_url' => $request->getToken()->getTargetUrl(), |
36
|
|
|
'iyzico_shipping_address' => [ |
37
|
|
|
"firstname" => $order->getShippingAddress()->getFirstName(), |
|
|
|
|
38
|
|
|
"lastname" => $order->getShippingAddress()->getLastName(), |
39
|
|
|
"country_code" => $order->getShippingAddress()->getCountryCode(), |
40
|
|
|
"city" => $order->getShippingAddress()->getCity(), |
41
|
|
|
"street" => $order->getShippingAddress()->getStreet(), |
42
|
|
|
"postcode" => $order->getShippingAddress()->getPostcode(), |
43
|
|
|
], |
44
|
|
|
'iyzico_billing_address' => [ |
45
|
|
|
'firstname' => $order->getBillingAddress()->getFirstName(), |
|
|
|
|
46
|
|
|
'lastname' => $order->getBillingAddress()->getLastName(), |
47
|
|
|
'country_code' => $order->getBillingAddress()->getCountryCode(), |
48
|
|
|
'city' => $order->getBillingAddress()->getCity(), |
49
|
|
|
'street' => $order->getBillingAddress()->getStreet(), |
50
|
|
|
'postcode' => $order->getBillingAddress()->getPostcode(), |
51
|
|
|
], |
52
|
|
|
'iyzico_customer' => [ |
53
|
|
|
'id' => $order->getCustomer()->getId(), |
|
|
|
|
54
|
|
|
'firstname' => $order->getCustomer()->getFirstName() ? $order->getCustomer()->getFirstName() : $order->getShippingAddress()->getFirstName(), |
55
|
|
|
'lastname' => $order->getCustomer()->getLastName() ? $order->getCustomer()->getLastName() : $order->getShippingAddress()->getLastName(), |
56
|
|
|
'phone_number' => $order->getCustomer()->getPhoneNumber() ? $order->getCustomer()->getPhoneNumber() : $order->getShippingAddress()->getPhoneNumber(), |
57
|
|
|
'email' => $order->getCustomer()->getEmail(), |
58
|
|
|
'ip' => $order->getCustomerIp(), |
|
|
|
|
59
|
|
|
'last_login_date' => $order->getCustomer()->getUser() ? $order->getCustomer()->getUser()->getLastLogin() : null, |
60
|
|
|
'registration_date' => $order->getCustomer()->getCreatedAt(), |
61
|
|
|
'identity_number' => $_ENV['APP_ENV'] === 'test' ? '74300864791' : $order->getCustomer()->getIdentityNumber(), |
62
|
|
|
'country_code' => $order->getShippingAddress()->getCountryCode(), |
63
|
|
|
'city' => $order->getShippingAddress()->getCity(), |
64
|
|
|
'street' => $order->getShippingAddress()->getStreet(), |
65
|
|
|
'postcode' => $order->getShippingAddress()->getPostcode(), |
66
|
|
|
], |
67
|
|
|
'iyzico_items' => array_map(function ($orderItem) { |
68
|
|
|
return [ |
69
|
|
|
'id' => $orderItem->getId(), |
70
|
|
|
'name' => $orderItem->getProductName(), |
71
|
|
|
'total' => $orderItem->getTotal() / 100, |
72
|
|
|
'category' => $orderItem->getProduct()->getMainTaxon() ? $orderItem->getProduct()->getMainTaxon()->getName() : "empty" |
73
|
|
|
]; |
74
|
|
|
}, iterator_to_array($order->getItems())), |
75
|
|
|
'iyzico_shipment' => array_map(function ($shipment) use ($order) { |
76
|
|
|
return [ |
77
|
|
|
'id' => $shipment->getMethod()->getId(), |
78
|
|
|
'name' => $shipment->getMethod()->getName(), |
79
|
|
|
'total' => $order->getShippingTotal() / 100, |
|
|
|
|
80
|
|
|
'category' => $shipment->getMethod()->getCategory() ? $shipment->getMethod()->getCategory()->getName() : IyzicoBridgeInterface::SHIPPING_CATEGORY |
81
|
|
|
]; |
82
|
|
|
}, iterator_to_array($order->getShipments())) |
|
|
|
|
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
$request->setResult($details); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function supports($request): bool |
89
|
|
|
{ |
90
|
|
|
return |
91
|
|
|
$request instanceof Convert && |
92
|
|
|
$request->getSource() instanceof PaymentInterface && |
93
|
|
|
$request->getTo() === 'array'; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|