From 7fce704e3fdfae79ee44e94f9bee0bdc636c2219 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:07:17 +0100 Subject: [PATCH 1/7] Added element fields for T&C and merchant terms --- .../WebformElement/NetsEasyPaymentElement.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Plugin/WebformElement/NetsEasyPaymentElement.php b/src/Plugin/WebformElement/NetsEasyPaymentElement.php index d77a383..08f00c0 100644 --- a/src/Plugin/WebformElement/NetsEasyPaymentElement.php +++ b/src/Plugin/WebformElement/NetsEasyPaymentElement.php @@ -51,6 +51,8 @@ protected function defineDefaultProperties() { 'checkout_language' => [], 'amount_to_pay' => '', 'checkout_page_description' => '', + 'terms_and_conditions_url' => $this->paymentHelper->getTermsUrl(), + 'merchant_terms_url' => $this->paymentHelper->getMerchantTermsUrl(), 'payment_methods' => ['Card'], 'payment_posting' => '', ] + parent::defineDefaultProperties(); @@ -93,6 +95,16 @@ public function form(array $form, FormStateInterface $form_state): array { '#description' => $this ->t('This field supports simple html'), ]; + $form['element']['terms_and_conditions_url'] = [ + '#type' => 'textfield', + '#title' => $this->t('Terms and conditions URL'), + '#description' => $this->t('The complete URL to the terms and conditions, including the protocol. Example: https://www.example.com/terms-and-conditions'), + ]; + $form['element']['merchant_terms_url'] = [ + '#type' => 'textfield', + '#title' => $this->t('The merchant terms URL'), + '#description' => $this->t('The complete URL to the merchant terms, including the protocol. Example: https://www.example.com/merchant-terms'), + ]; $form['element']['payment_posting'] = [ '#type' => 'textfield', @@ -131,7 +143,8 @@ public function alterForm(array &$element, array &$form, FormStateInterface $for ? 'os2forms_payment/nets_easy_test' : 'os2forms_payment/nets_easy_prod'; $callbackUrl = Url::fromRoute('')->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - $webformCurrentPage = $form['progress']['#current_page']; + + $webformCurrentPage = $formState->get('current_page'); // Check if we are on the preview page. if ($webformCurrentPage === "webform_preview") { $amountToPay = $this->paymentHelper->getAmountToPay($formState->getUserInput(), $this->getElementProperty($element, 'amount_to_pay')); @@ -147,6 +160,9 @@ public function alterForm(array &$element, array &$form, FormStateInterface $for $paymentMethods = array_values(array_filter($element['#payment_methods'] ?? [])); $paymentPosting = $element['#payment_posting'] ?? 'undefined'; $checkoutLanguage = $element['#checkout_language'] ?? 'da-DK'; + $termsAndConditionsUrl = $element['#terms_and_conditions_url'] ?? ''; + $merchantTermsUrl = $element['#merchant_terms_url'] ?? ''; + $form['os2forms_payment_checkout_container'] = [ '#type' => 'container', @@ -161,6 +177,8 @@ public function alterForm(array &$element, array &$form, FormStateInterface $for 'callbackUrl' => $callbackUrl, 'paymentMethods' => $paymentMethods, 'paymentPosting' => $paymentPosting, + 'termsAndConditionsUrl' => $termsAndConditionsUrl, + 'merchantTermsUrl' => $merchantTermsUrl, ])->toString(TRUE)->getGeneratedUrl(), ], '#limit_validation_errors' => [], From ead010fce3073f55371b33143360e2d87a5e65c5 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:07:45 +0100 Subject: [PATCH 2/7] Added get methods for default terms urls set in settings local --- src/Helper/PaymentHelper.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index 5858eea..73d8468 100644 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -328,6 +328,16 @@ public function getTermsUrl(): ?string { return $this->getPaymentSettings()['terms_url'] ?? NULL; } + /** + * Returns the url for the page displaying merchant terms and conditions. + * + * @return string + * The merchant terms and conditions url. + */ + public function getMerchantTermsUrl(): ?string { + return $this->getPaymentSettings()['merchant_terms_url'] ?? NULL; + } + /** * Returns whether the module is operated in test mode. * From ec39bd9a43faa22e6a2152c340a000beba6dabc8 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:08:06 +0100 Subject: [PATCH 3/7] Sending user defined terms urls to createPayment method --- src/Controller/NetsEasyController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Controller/NetsEasyController.php b/src/Controller/NetsEasyController.php index 8a1e148..608d928 100644 --- a/src/Controller/NetsEasyController.php +++ b/src/Controller/NetsEasyController.php @@ -56,6 +56,8 @@ public function createPayment(Request $request): Response { $callbackUrl = $request->get('callbackUrl'); $paymentPosting = $request->get('paymentPosting'); $paymentMethods = $request->get('paymentMethods'); + $termsAndConditionsUrl = $request->get('termsAndConditionsUrl'); + $merchantTermsUrl = $request->get('merchantTermsUrl'); $paymentMethodsConfiguration = array_map( static fn($name) => ['name' => $name, 'enabled' => TRUE], @@ -71,8 +73,8 @@ public function createPayment(Request $request): Response { 'checkout' => [ 'integrationType' => 'EmbeddedCheckout', 'url' => $callbackUrl, - 'termsUrl' => $this->paymentHelper->getTermsUrl(), - 'merchantTermsUrl' => $this->paymentHelper->getTermsUrl(), + 'termsUrl' => $termsAndConditionsUrl, + 'merchantTermsUrl' => $merchantTermsUrl, 'merchantHandlesConsumerData' => TRUE, 'publicDevice' => TRUE, 'shipping' => [ From 76bd4c2d826fe04327daca4be988c0d0bd88dcf6 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:08:38 +0100 Subject: [PATCH 4/7] Updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cebf00..267b24b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- User definable terms and condition urls + ## [1.0.1] - 2024-12-06 ### Added From 58e62a7770dddf9ac285ccde5edaf4115ad73f70 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:16:01 +0100 Subject: [PATCH 5/7] Coding standards --- src/Plugin/WebformElement/NetsEasyPaymentElement.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugin/WebformElement/NetsEasyPaymentElement.php b/src/Plugin/WebformElement/NetsEasyPaymentElement.php index 08f00c0..f11df9f 100644 --- a/src/Plugin/WebformElement/NetsEasyPaymentElement.php +++ b/src/Plugin/WebformElement/NetsEasyPaymentElement.php @@ -163,7 +163,6 @@ public function alterForm(array &$element, array &$form, FormStateInterface $for $termsAndConditionsUrl = $element['#terms_and_conditions_url'] ?? ''; $merchantTermsUrl = $element['#merchant_terms_url'] ?? ''; - $form['os2forms_payment_checkout_container'] = [ '#type' => 'container', '#attributes' => [ From b79ef9c8ae2cdf1ac8641e993a062aa1323bbc0a Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:19:55 +0100 Subject: [PATCH 6/7] Added description of new local settings field in readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3962b7..02fb691 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,12 @@ $settings['os2forms_payment']['checkout_key'] = ''; // SECRET_KEY, both test and production, can be retrieved from Nets admin panel $settings['os2forms_payment']['secret_key'] = ''; -// Static page containing terms and conditions, e.g. /node/87 +// Page containing terms and conditions URL, including protocol. $settings['os2forms_payment']['terms_url'] = ''; +// Page containing merchant terms URL, including protocol. +$settings['os2forms_payment']['merchant_terms_url'] = ''; + // Boolean describing whether the module is operated in test mode $settings['os2forms_payment']['test_mode'] = TRUE; ``` From 0135ecb23d0a3735e731b7b1b61edc75249147a9 Mon Sep 17 00:00:00 2001 From: Jeppe Krogh Date: Mon, 16 Dec 2024 14:34:52 +0100 Subject: [PATCH 7/7] Set terms urls and payment methods to be required --- src/Plugin/WebformElement/NetsEasyPaymentElement.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Plugin/WebformElement/NetsEasyPaymentElement.php b/src/Plugin/WebformElement/NetsEasyPaymentElement.php index f11df9f..f2cd26e 100644 --- a/src/Plugin/WebformElement/NetsEasyPaymentElement.php +++ b/src/Plugin/WebformElement/NetsEasyPaymentElement.php @@ -99,11 +99,13 @@ public function form(array $form, FormStateInterface $form_state): array { '#type' => 'textfield', '#title' => $this->t('Terms and conditions URL'), '#description' => $this->t('The complete URL to the terms and conditions, including the protocol. Example: https://www.example.com/terms-and-conditions'), + '#required' => TRUE, ]; $form['element']['merchant_terms_url'] = [ '#type' => 'textfield', '#title' => $this->t('The merchant terms URL'), '#description' => $this->t('The complete URL to the merchant terms, including the protocol. Example: https://www.example.com/merchant-terms'), + '#required' => TRUE, ]; $form['element']['payment_posting'] = [ @@ -119,6 +121,7 @@ public function form(array $form, FormStateInterface $form_state): array { 'Card' => $this->t('Kortbetaling'), 'MobilePay' => $this->t('MobilePay'), ], + '#required' => TRUE, ]; return $form;