| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
namespace MultiSafepay\WooCommerce\Services\Qr; |
| 4 |
|
| 5 |
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\CustomerDetails; |
| 6 |
use MultiSafepay\WooCommerce\Services\CustomerService; |
| 7 |
use MultiSafepay\WooCommerce\Utils\QrOrder; |
| 8 |
|
| 9 |
/** |
| 10 |
* Class QrCustomerService |
| 11 |
* |
| 12 |
* Handles customer data processing for QR-based transactions. |
| 13 |
* |
| 14 |
* @package MultiSafepay\WooCommerce\Services\Qr |
| 15 |
*/ |
| 16 |
class QrCustomerService extends CustomerService { |
| 17 |
|
| 18 |
/** |
| 19 |
* Create customer details from the current cart and user data. |
| 20 |
* |
| 21 |
* @param array $customer |
| 22 |
* @param string $type |
| 23 |
* @return CustomerDetails |
| 24 |
*/ |
| 25 |
public function create_customer_details_from_cart( |
| 26 |
array $customer, |
| 27 |
string $type = 'billing' |
| 28 |
): CustomerDetails { |
| 29 |
|
| 30 |
$customer_address = $this->create_address( |
| 31 |
$customer[ $type ]['address_1'], |
| 32 |
$customer[ $type ]['address_2'], |
| 33 |
$customer[ $type ]['country'], |
| 34 |
$customer[ $type ]['state'] ?? '', |
| 35 |
$customer[ $type ]['city'] ?? '', |
| 36 |
$customer[ $type ]['postcode'] |
| 37 |
); |
| 38 |
|
| 39 |
return $this->create_customer( |
| 40 |
$customer_address, |
| 41 |
$customer[ $type ]['email'] ?? $customer['billing']['email'], |
| 42 |
$customer[ $type ]['phone'] ?? $customer['billing']['phone'], |
| 43 |
$customer[ $type ]['first_name'] ?? $customer['billing']['first_name'], |
| 44 |
$customer[ $type ]['last_name'] ?? $customer['billing']['last_name'], |
| 45 |
( new QrOrder() )->get_customer_ip_address() ?? '', |
| 46 |
( new QrOrder() )->get_user_agent() ?? '', |
| 47 |
$customer[ $type ]['company'] ?? $customer['billing']['company'], |
| 48 |
); |
| 49 |
} |
| 50 |
} |
| 51 |
|