diff --git a/src/gateways/Gateway.php b/src/gateways/Gateway.php index 8ce84da..55ad125 100644 --- a/src/gateways/Gateway.php +++ b/src/gateways/Gateway.php @@ -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'); diff --git a/src/helpers/SimplePayHelper.php b/src/helpers/SimplePayHelper.php index 7973355..0f89cd8 100644 --- a/src/helpers/SimplePayHelper.php +++ b/src/helpers/SimplePayHelper.php @@ -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; /** @@ -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; } @@ -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; } diff --git a/src/services/simplepay/Sdk/SimplePayBase.php b/src/services/simplepay/Sdk/SimplePayBase.php index b81cbf2..6938dfa 100644 --- a/src/services/simplepay/Sdk/SimplePayBase.php +++ b/src/services/simplepay/Sdk/SimplePayBase.php @@ -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); }