-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PayPalOrder VO and Comparator service
- Loading branch information
Showing
7 changed files
with
750 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PrestashopCheckout\PayPal\Order\Comparator; | ||
|
||
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\ValueObject\PayPalOrder; | ||
|
||
class PayPalOrderComparator | ||
{ | ||
/** | ||
* @param PayPalOrder $oldOrder | ||
* @param PayPalOrder $newOrder | ||
* | ||
* @return array | ||
*/ | ||
public function getFieldsToUpdate(PayPalOrder $oldOrder, PayPalOrder $newOrder) | ||
{ | ||
$fieldsToUpdate = []; | ||
$oldOrderArray = $oldOrder->toArray(); | ||
$newOrderArray = $newOrder->toArray(); | ||
|
||
$fieldsToUpdate = array_filter($newOrderArray, function ($value, $key) use ($oldOrderArray) { | ||
return $this->compareValues($value, $oldOrderArray[$key]); | ||
}, ARRAY_FILTER_USE_BOTH); | ||
|
||
// if ($oldOrder->getIntent() !== $newOrder->getIntent()) { | ||
// $fieldsToUpdate['intent'] = $newOrder->getIntent(); | ||
// } | ||
// | ||
// | ||
// if ($this->compareArraysDeep($oldOrderArray['payer'], $newOrderArray['payer'])) { | ||
// $fieldsToUpdate['payer'] = $newOrderArray['payer']; | ||
// } | ||
// | ||
// if ($this->compareArraysDeep($oldOrderArray['purchase_units'], $newOrderArray['purchase_units'])) { | ||
// $fieldsToUpdate['purchase_units'] = $newOrderArray['purchase_units']; | ||
// } | ||
|
||
return $fieldsToUpdate; | ||
} | ||
|
||
private function compareValues($value1, $value2) | ||
{ | ||
$result = false; | ||
if (is_array($value1) && is_array($value2)) { | ||
$result |= $this->compareArraysDeep($value1, $value2); | ||
} else { | ||
$result |= $value1 !== $value2; | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* @param array $array1 | ||
* @param array $array2 | ||
* @return false|int|string | ||
*/ | ||
private function compareArraysDeep($array1, $array2) | ||
{ | ||
$result = false; | ||
|
||
if (count($array1) !== count($array2)) { | ||
return true; | ||
} | ||
|
||
foreach ($array1 as $key => $oldValue) { | ||
$newValue = $array2[$key]; | ||
if (is_array($oldValue)) { | ||
$result |= $this->compareArraysDeep($oldValue, $newValue); | ||
} else { | ||
$result |= $oldValue !== $newValue; | ||
} | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\PrestashopCheckout\PayPal\Order\ValueObject; | ||
|
||
class PayPalOrderPayer | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $firstName; | ||
/** | ||
* @var string | ||
*/ | ||
private $lastName; | ||
/** | ||
* @var string | ||
*/ | ||
private $email; | ||
/** | ||
* @var string | ||
*/ | ||
private $address1; | ||
/** | ||
* @var string | ||
*/ | ||
private $address2; | ||
/** | ||
* @var string | ||
*/ | ||
private $adminArea1; | ||
/** | ||
* @var string | ||
*/ | ||
private $adminArea2; | ||
/** | ||
* @var string | ||
*/ | ||
private $countryCode; | ||
/** | ||
* @var string | ||
*/ | ||
private $postalCode; | ||
|
||
/** | ||
* @param string $firstName | ||
* @param string $lastName | ||
* @param string $email | ||
* @param string $address1 | ||
* @param string $address2 | ||
* @param string $adminArea1 | ||
* @param string $adminArea2 | ||
* @param string $countryCode | ||
* @param string $postalCode | ||
*/ | ||
public function __construct($firstName, $lastName, $email, $address1, $address2, $adminArea1, $adminArea2, $countryCode, $postalCode) | ||
{ | ||
$this->firstName = $firstName; | ||
$this->lastName = $lastName; | ||
$this->email = $email; | ||
$this->address1 = $address1; | ||
$this->address2 = $address2; | ||
$this->adminArea1 = $adminArea1; | ||
$this->adminArea2 = $adminArea2; | ||
$this->countryCode = $countryCode; | ||
$this->postalCode = $postalCode; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFirstName() | ||
{ | ||
return $this->firstName; | ||
} | ||
|
||
/** | ||
* @param string $firstName | ||
*/ | ||
public function setFirstName($firstName) | ||
{ | ||
$this->firstName = $firstName; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLastName() | ||
{ | ||
return $this->lastName; | ||
} | ||
|
||
/** | ||
* @param string $lastName | ||
*/ | ||
public function setLastName($lastName) | ||
{ | ||
$this->lastName = $lastName; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
*/ | ||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAddress1() | ||
{ | ||
return $this->address1; | ||
} | ||
|
||
/** | ||
* @param string $address1 | ||
*/ | ||
public function setAddress1($address1) | ||
{ | ||
$this->address1 = $address1; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAddress2() | ||
{ | ||
return $this->address2; | ||
} | ||
|
||
/** | ||
* @param string $address2 | ||
*/ | ||
public function setAddress2($address2) | ||
{ | ||
$this->address2 = $address2; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAdminArea1() | ||
{ | ||
return $this->adminArea1; | ||
} | ||
|
||
/** | ||
* @param string $adminArea1 | ||
*/ | ||
public function setAdminArea1($adminArea1) | ||
{ | ||
$this->adminArea1 = $adminArea1; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAdminArea2() | ||
{ | ||
return $this->adminArea2; | ||
} | ||
|
||
/** | ||
* @param string $adminArea2 | ||
*/ | ||
public function setAdminArea2($adminArea2) | ||
{ | ||
$this->adminArea2 = $adminArea2; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCountryCode() | ||
{ | ||
return $this->countryCode; | ||
} | ||
|
||
/** | ||
* @param string $countryCode | ||
*/ | ||
public function setCountryCode($countryCode) | ||
{ | ||
$this->countryCode = $countryCode; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPostalCode() | ||
{ | ||
return $this->postalCode; | ||
} | ||
|
||
/** | ||
* @param string $postalCode | ||
*/ | ||
public function setPostalCode($postalCode) | ||
{ | ||
$this->postalCode = $postalCode; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return [ | ||
'name' => [ | ||
'given_name' => $this->firstName, | ||
'surname' => $this->lastName, | ||
], | ||
'email_address' => $this->email, | ||
'address' => [ | ||
'address_line_1' => $this->address1, | ||
'address_line_2' => $this->address2, | ||
'admin_area_1' => $this->adminArea1, | ||
'admin_area_2' => $this->adminArea2, | ||
'country_code' => $this->countryCode, | ||
'postal_code' => $this->postalCode, | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.