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 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; ``` 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' => [ 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. * diff --git a/src/Plugin/WebformElement/NetsEasyPaymentElement.php b/src/Plugin/WebformElement/NetsEasyPaymentElement.php index d77a383..f2cd26e 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,18 @@ 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'), + '#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'] = [ '#type' => 'textfield', @@ -107,6 +121,7 @@ public function form(array $form, FormStateInterface $form_state): array { 'Card' => $this->t('Kortbetaling'), 'MobilePay' => $this->t('MobilePay'), ], + '#required' => TRUE, ]; return $form; @@ -131,7 +146,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 +163,8 @@ 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 +179,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' => [],