Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/NetsEasyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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' => [
Expand Down
10 changes: 10 additions & 0 deletions src/Helper/PaymentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
22 changes: 21 additions & 1 deletion src/Plugin/WebformElement/NetsEasyPaymentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand All @@ -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;
Expand All @@ -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('<current>')->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'));
Expand All @@ -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',
Expand All @@ -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' => [],
Expand Down
Loading