diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 00000000..d9844a7b
Binary files /dev/null and b/.DS_Store differ
diff --git a/Api/Data/PlaceOrderResponseInterface.php b/Api/Data/PlaceOrderResponseInterface.php
index a23773cb..b0a98ed9 100644
--- a/Api/Data/PlaceOrderResponseInterface.php
+++ b/Api/Data/PlaceOrderResponseInterface.php
@@ -1,18 +1,4 @@
resultJsonFactory = $resultJsonFactory;
+ $this->context = $context;
+ $this->storeManager = $storeManager;
+ $this->random = $random;
+ $this->cache = $cache;
+ $this->request = $request;
+ $this->configuration = $configuration;
+ $this->identityService = $identityService;
+ }
+
+ public function getOriginFromUrl($url): string
+ {
+ $parsedUrl = parse_url($url);
+ $origin = $parsedUrl['scheme'] . '://' . $parsedUrl['host'];
+ if (isset($parsedUrl['port'])) {
+ $origin .= ':' . $parsedUrl['port'];
+ }
+ return $origin;
+ }
+
+ /**
+ * @return Json
+ * @throws NoSuchEntityException|LocalizedException
+ */
+ public function execute(): Json
+ {
+ $resultJson = $this->resultJsonFactory->create();
+ if (empty($this->request->getParam('code'))) {
+ header('Location: ' . base64_decode($this->request->getParam('target_url')));
+ return $resultJson;
+ }
+ $environment = 'demo';
+ if ($this->request->getParam('env') !== 'demo') {
+ $environment = 'www';
+ }
+ $platform = 'magento';
+ $storeUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_WEB);
+ $baseUrl = trim($storeUrl, '/');
+ $webhookNotificationUrl = $baseUrl . '/airwallex/webhooks';
+ if (!function_exists('gzdecode')) {
+ return $this->error('Error: The gzdecode function is not available. Please make sure the zlib extension is enabled.', $resultJson);
+ }
+
+ $accessToken = gzdecode(base64_decode($this->request->getParam('code')));
+ $requestId = $this->identityService->generateId();
+
+ $url = "https://$environment.airwallex.com/payment_app/plugin/api/v1/connection/finalize";
+ $data = [
+ 'platform' => $platform,
+ 'origin' => $this->getOriginFromUrl($baseUrl),
+ 'baseUrl' => $baseUrl,
+ 'webhookNotificationUrl' => $webhookNotificationUrl,
+ 'token' => $this->token($environment),
+ 'requestId' => $requestId
+ ];
+
+ if (!function_exists('curl_init')) {
+ return $this->error('Error: Please make sure the curl extension is enabled.', $resultJson);
+ }
+
+ $options = [
+ 'http' => [
+ 'method' => 'POST',
+ 'header' => [
+ 'Content-Type: application/json',
+ 'Authorization: Bearer ' . $accessToken,
+ ],
+ 'content' => json_encode($data),
+ 'ignore_errors' => true
+ ],
+ ];
+
+ $context = stream_context_create($options);
+ $response = file_get_contents($url, false, $context);
+ if ($response === false) {
+ return $this->error('Error: Unable to fetch the URL. Please try again.', $resultJson);
+ }
+ $responseData = json_decode($response, true);
+
+ if (!empty($responseData['message']) && $responseData['message'] == 'OK') {
+ return $this->success('Your Airwallex plug-in is activated.
+ You can also manage which account is connected to your Magento store.', $resultJson);
+ }
+
+ return $this->error($responseData['error'], $resultJson);
+ }
+
+ public function error($message, $resultJson): Json
+ {
+ $this->context->getMessageManager()->addErrorMessage($message);
+ header('Location: ' . base64_decode($this->request->getParam('target_url')));
+ return $resultJson;
+ }
+
+ public function success($message, $resultJson): Json
+ {
+ $this->context->getMessageManager()->addSuccessMessage($message);
+ header('Location: ' . base64_decode($this->request->getParam('target_url')));
+ return $resultJson;
+ }
+
+ /**
+ * @throws LocalizedException
+ */
+ public function token($environment): string
+ {
+ $token = $environment . '-' . $this->random->getRandomString(32);
+ $this->cache->save($token, self::CACHE_NAME, [], 60 * 60 * 24);
+ return $token;
+ }
+}
diff --git a/Controller/Webhooks/Index.php b/Controller/Webhooks/Index.php
index 881cc3b3..70902445 100644
--- a/Controller/Webhooks/Index.php
+++ b/Controller/Webhooks/Index.php
@@ -97,7 +97,8 @@ public function execute(): ResponseHttp
}
} catch (Exception $e) {
$id = $data->sourceId ?? '';
- $this->requestLog->setMessage($data->name . " $id webhook: " . $e->getMessage(), $e->getTraceAsString())->send();
+ $name = $data->name ?? '';
+ $this->requestLog->setMessage("$name $id webhook: " . $e->getMessage(), $e->getTraceAsString())->send();
$this->logger->error($e->getMessage());
throw $e;
}
diff --git a/Model/Config/Adminhtml/UpdateSettings.php b/Model/Config/Adminhtml/UpdateSettings.php
new file mode 100644
index 00000000..ecf37445
--- /dev/null
+++ b/Model/Config/Adminhtml/UpdateSettings.php
@@ -0,0 +1,43 @@
+_toHtml();
+ }
+
+ public function render(AbstractElement $element): string
+ {
+ $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
+ return parent::render($element);
+ }
+
+ public function getAccount()
+ {
+ return ObjectManager::getInstance()->get(Configuration::class)->getAccount();
+ }
+
+ /**
+ * @throws LocalizedException
+ */
+ public function getButtonHtml()
+ {
+ $data = [
+ 'id' => 'airwallex_update_settings',
+ 'label' => __('Connect account'),
+ ];
+
+ return $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->setData($data)->toHtml();
+ }
+}
diff --git a/Setup/Patch/Data/AddAirwallexCustomerIdAttribute.php b/Setup/Patch/Data/AddAirwallexCustomerIdAttribute.php
index bcbdd997..f034ec4a 100644
--- a/Setup/Patch/Data/AddAirwallexCustomerIdAttribute.php
+++ b/Setup/Patch/Data/AddAirwallexCustomerIdAttribute.php
@@ -1,18 +1,4 @@
Airwallex\Payments\Model\Config\Source\Mode
airwallex/general/mode
+
airwallex/general/demo_client_id
diff --git a/etc/adminhtml/system/card.xml b/etc/adminhtml/system/card.xml
index bf31adb0..af98f52c 100644
--- a/etc/adminhtml/system/card.xml
+++ b/etc/adminhtml/system/card.xml
@@ -52,14 +52,14 @@
-
-
- Magento\Config\Model\Config\Source\Yesno
- payment/airwallex_payments_card/preverification
-
+
+
+
+
+
-
-
+
+
Adjust this to move the payment method above or below other payment methods
diff --git a/etc/module.xml b/etc/module.xml
index 414e2f59..075a772c 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/view/adminhtml/templates/config/update_settings.phtml b/view/adminhtml/templates/config/update_settings.phtml
new file mode 100644
index 00000000..73a1234d
--- /dev/null
+++ b/view/adminhtml/templates/config/update_settings.phtml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+ getButtonHtml() ?>
+
+
+
diff --git a/view/frontend/web/js/view/payment/method-renderer/address/address-handler.js b/view/frontend/web/js/view/payment/method-renderer/address/address-handler.js
index 35ac6e24..e6cc2c38 100644
--- a/view/frontend/web/js/view/payment/method-renderer/address/address-handler.js
+++ b/view/frontend/web/js/view/payment/method-renderer/address/address-handler.js
@@ -121,10 +121,13 @@ define([
},
city(addr, type) {
- if (type === 'google') {
- return addr.locality || addr.administrativeArea || addr.countryCode;
+ if (addr.locality) return addr.locality;
+ if (['sg', 'singapore'].indexOf(addr.countryCode.toLowerCase()) !== -1) {
+ return 'Singapore';
}
- return addr.locality;
+ if (addr.administrativeArea) return addr.administrativeArea;
+ if (addr.country) return addr.country;
+ return addr.countryCode;
},
postcode(addr, type) {