Skip to content

Commit

Permalink
Fixed some issues related to Craft & Commerce 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Saboteur777 committed Dec 14, 2022
1 parent 9bf7e9a commit e372e81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/gateways/Gateway.php
Expand Up @@ -286,13 +286,13 @@ protected function createGateway(): AbstractGateway
if (SimplePayHelper::shouldSendInvoiceData($address)) {
$gateway->setInvoiceData([
'name' => $address->fullName ?: ($address->lastName . ' ' . $address->firstName),
'country' => $address->countryIso,
'state' => $address->stateText,
'city' => $address->city,
'zip' => $address->zipCode,
'address' => $address->address1,
'address2' => $address->address2,
'company' => $address->businessName
'country' => $address->countryCode,
'state' => $address->administrativeArea,
'city' => $address->locality,
'zip' => $address->postalCode,
'address' => $address->addressLine1,
'address2' => $address->addressLine2,
'company' => $address->organization
]);
}
$gateway->setLanguage('HU');
Expand Down
15 changes: 7 additions & 8 deletions src/helpers/SimplePayHelper.php
Expand Up @@ -12,7 +12,7 @@

use craft\base\Component;
use craft\commerce\elements\Order;
use craft\commerce\models\Address;
use craft\elements\Address;
use craft\commerce\Plugin as Commerce;

/**
Expand Down Expand Up @@ -65,12 +65,11 @@ public static function getOrderByOrderRef(string $orderRef) : Order
public static function shouldSendInvoiceData(Address $address) : bool
{
/**
* If fullName is missing, check for firstName and lastName separately.
* If both firstName and lastName are missing, fail.
* If fullName is missing, stop processing.
*
* Prevents error 5309.
*/
if (!$address->fullName && !($address->firstName || $address->lastName)) {
if (!$address->fullName) {
return false;
}

Expand All @@ -81,28 +80,28 @@ public static function shouldSendInvoiceData(Address $address) : bool
* API change, e.g.: SimplePay decides country is required without notifying us
* first, prevent sending invoice data.
*/
if (!$address->countryIso) {
if (!$address->countryCode) {
return false;
}

/**
* Prevents error 5310.
*/
if (!$address->city) {
if (!$address->locality) {
return false;
}

/**
* Prevents error 5311.
*/
if (!$address->zipCode) {
if (!$address->postalCode) {
return false;
}

/**
* Prevents error 5312.
*/
if (!$address->address1) {
if (!$address->addressLine1) {
return false;
}

Expand Down
28 changes: 16 additions & 12 deletions src/services/simplepay/Sdk/SimplePayBase.php
Expand Up @@ -229,26 +229,30 @@ public function getReturnData()
*/
public function checkOrSetToJson($data = '')
{
$json = '[]';
//empty
$json = null;
$result = null;
if ($data === '') {
$json = json_encode([]);
$json = json_encode([]);
}
//array
if (is_array($data)) {
$json = json_encode($data);

if (is_array($data) || is_object($data)) {
$json = json_encode($data);
}
//object
if (is_object($data)) {
$json = json_encode($data);

if (is_string($data)) {
$result = @json_decode($data);
}

//json
$result = @json_decode($data);
if ($result !== null) {
$json = $data;
$json = $data;
}

//serialized
$result = @unserialize($data);
if (is_string($data)) {
$result = @unserialize($data);
}

if ($result !== false) {
$json = json_encode($result);
}
Expand Down

0 comments on commit e372e81

Please sign in to comment.