Skip to content

Commit

Permalink
Merge pull request #15 from paynl/feature/PLUG-2082
Browse files Browse the repository at this point in the history
PLUG-2082 - Custom Exchange URL
  • Loading branch information
woutse authored Jul 10, 2023
2 parents 7f7b93c + 6f4e3ca commit e136906
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .github/linters/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName" />
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamName" />
</rule>
</ruleset>
49 changes: 34 additions & 15 deletions upload/Pay/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ private function configGet($field)
return $configValue;
}

/**
* @return void
*/
public function index()
{
$this->load->language('extension/payment/' . $this->_paymentMethodName);
Expand Down Expand Up @@ -62,11 +65,12 @@ public function index()
'payment_paynl_general_gateway' => trim($settings['payment_paynl_general_gateway']),
'payment_paynl_general_prefix' => $settings['payment_paynl_general_prefix'],
'payment_paynl_general_display_icon' => $settings['payment_paynl_general_display_icon'],
'payment_paynl_general_icon_style' => $settings['payment_paynl_general_icon_style']
'payment_paynl_general_icon_style' => $settings['payment_paynl_general_icon_style'],
'payment_paynl_general_custom_exchange_url' => $settings['payment_paynl_general_custom_exchange_url']
);
$this->model_setting_setting->editSetting('payment_paynl_general', $settingsGeneral);

foreach($settingsGeneral as $strField => $strvalue) {
foreach ($settingsGeneral as $strField => $strvalue) {
$this->config->set($strField, $strvalue);
}
}
Expand All @@ -92,6 +96,7 @@ public function index()
$data['gateway'] = $this->configGet('gateway');
$data['prefix'] = $this->configGet('prefix');
$data['icon_style'] = $this->configGet('icon_style');
$data['custom_exchange_url'] = $this->configGet('custom_exchange_url');
$data['display_icon'] = $this->configGet('display_icon');
$data['text_edit'] = 'PAY. - ' . $this->_defaultLabel;
$data['error_warning'] = '';
Expand Down Expand Up @@ -120,7 +125,9 @@ public function index()
$this->load->model('localisation/geo_zone');
$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();

if (empty($data['label'])) $data['label'] = $this->_defaultLabel;
if (empty($data['label'])) {
$data['label'] = $this->_defaultLabel;
}

$data['confirm_on_start'] = !isset($data['confirm_on_start']) ? 1 : $data['confirm_on_start'];
$data['send_status_updates'] = !isset($data['send_status_updates']) ? '1' : $data['send_status_updates'];
Expand Down Expand Up @@ -159,12 +166,19 @@ public function index()
$this->response->setOutput($this->load->view('extension/payment/paynl3', $data));
}

/**
* @param $field
* @return null
*/
private function getPost($field)
{
$postArr = $this->request->post;
return isset($postArr[$field]) ? $postArr[$field] : null;
}

/**
* @return boolean
*/
public function validateGeneral()
{
$apiToken = $this->getPost('payment_paynl_general_apitoken');
Expand All @@ -176,7 +190,7 @@ public function validateGeneral()

if (empty($serviceId)) {
$this->error['serviceid'] = $this->language->get('error_no_serviceid');
}elseif (empty($apiToken)) {
} elseif (empty($apiToken)) {
$this->error['apitoken'] = $this->language->get('error_no_apitoken');
} else {
try {
Expand All @@ -185,7 +199,6 @@ public function validateGeneral()
$gateway = (!empty($reqGateway) && substr($reqGateway, 0, 4) == 'http') ? $reqGateway : null;

$this->model_extension_payment_paynl3->refreshPaymentOptions($serviceId, $apiToken, $gateway);

} catch (Pay_Api_Exception $e) {
$this->error['apitoken'] = $this->language->get('error_api_error') . $e->getMessage();
} catch (Pay_Exception $e) {
Expand All @@ -198,9 +211,12 @@ public function validateGeneral()
return empty($this->error);
}

/**
* @return boolean
*/
public function validatePaymentMethod()
{
try {
try {
$this->load->model('extension/payment/paynl3');
$paymentOption = $this->model_extension_payment_paynl3->getPaymentOption($this->_paymentOptionId);
$status = $this->request->post['payment_' . $this->_paymentMethodName . '_status'];
Expand All @@ -217,26 +233,29 @@ public function validatePaymentMethod()
}
}

/**
* @return void
*/
public function install()
{
$this->load->model('extension/payment/paynl3');

$this->model_extension_payment_paynl3->createTables();
if ($this->config->get('payment_paynl_general_prefix') == null) {
$this->load->model('setting/setting');
$settings = $this->model_setting_setting->getSetting('payment_' . $this->_paymentMethodName);
$settings = $this->model_setting_setting->getSetting('payment_' . $this->_paymentMethodName);
$settingsGeneral = array(
'payment_paynl_general_apitoken' => $this->config->get('payment_paynl_general_apitoken'),
'payment_paynl_general_serviceid' => $this->config->get('payment_paynl_general_serviceid'),
'payment_paynl_general_testmode' => $this->config->get('payment_paynl_general_testmode'),
'payment_paynl_general_gateway' => $this->config->get('payment_paynl_general_gateway'),
'payment_paynl_general_apitoken' => $this->config->get('payment_paynl_general_apitoken'),
'payment_paynl_general_serviceid' => $this->config->get('payment_paynl_general_serviceid'),
'payment_paynl_general_testmode' => $this->config->get('payment_paynl_general_testmode'),
'payment_paynl_general_gateway' => $this->config->get('payment_paynl_general_gateway'),
'payment_paynl_general_prefix' => 'Order ',
'payment_paynl_general_display_icon' => $this->config->get('payment_paynl_general_display_icon'),
'payment_paynl_general_icon_style' => $this->config->get('payment_paynl_general_icon_style')
);
'payment_paynl_general_display_icon' => $this->config->get('payment_paynl_general_display_icon'),
'payment_paynl_general_icon_style' => $this->config->get('payment_paynl_general_icon_style'),
'payment_paynl_general_custom_exchange_url' => $this->config->get('payment_paynl_general_custom_exchange_url')
);
$this->model_setting_setting->editSetting('payment_paynl_general', $settingsGeneral);
$this->model_setting_setting->editSetting('payment_' . $this->_paymentMethodName, $settings);
}
}

}
58 changes: 43 additions & 15 deletions upload/Pay/Controller/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Pay_Controller_Payment extends Controller
protected $_paymentMethodName;
protected $data = array();

/**
* @return mixed
*/
public function index()
{
$this->load->language('extension/payment/paynl3');
Expand All @@ -15,7 +18,7 @@ public function index()
$this->data['button_confirm'] = $this->language->get('button_confirm');
$this->data['button_loading'] = $this->language->get('text_loading');

$this->data['paymentMethodName'] = $this->_paymentMethodName;
$this->data['paymentMethodName'] = $this->_paymentMethodName;

// paymentoption ophalen
$this->load->model('extension/payment/' . $this->_paymentMethodName);
Expand All @@ -42,17 +45,19 @@ public function index()
if (!empty($this->config->get('payment_' . $this->_paymentMethodName . '_vat')) && strlen($company) > 0) {
$this->data['vat'] = $this->config->get('payment_' . $this->_paymentMethodName . '_vat');
}

if (!empty($this->config->get('payment_' . $this->_paymentMethodName . '_dob'))) {
$this->data['dob'] = $this->config->get('payment_' . $this->_paymentMethodName . '_dob');
}

$this->data['terms'] = '';

return $this->load->view('payment/paynl3', $this->data);

}

/**
* @return void
*/
public function startTransaction()
{
$this->load->model('extension/payment/' . $this->_paymentMethodName);
Expand All @@ -75,12 +80,16 @@ public function startTransaction()
}

$returnUrl = $this->url->link('extension/payment/' . $this->_paymentMethodName . '/finish');
$exchangeUrl = $this->url->link('extension/payment/' . $this->_paymentMethodName . '/exchange');
$customExchangeUrl = $this->config->get('payment_paynl_general_custom_exchange_url');
$customExchangeUrl = is_null($customExchangeUrl) ? '' : trim($customExchangeUrl);

if (!empty($customExchangeUrl)) {
$exchangeUrl = htmlspecialchars_decode($customExchangeUrl);
}

$apiStart->setFinishUrl($returnUrl);
$apiStart->setExchangeUrl($exchangeUrl);


$apiStart->setPaymentOptionId($this->_paymentOptionId);
$amount = round($order_info['total'] * 100 * $currency_value);
$apiStart->setAmount($amount);
Expand Down Expand Up @@ -157,14 +166,22 @@ public function startTransaction()

//Producten toevoegen
foreach ($this->cart->getProducts() as $product) {
$priceWithTax = $this->tax->calculate($product['price'] * $currency_value,
$product['tax_class_id'], $this->config->get('config_tax'));
$priceWithTax = $this->tax->calculate(
$product['price'] * $currency_value,
$product['tax_class_id'],
$this->config->get('config_tax')
);

$tax = $priceWithTax - ($product['price'] * $currency_value);

$price = round($priceWithTax * 100);
$apiStart->addProduct($product['product_id'], $product['name'],
$price, $product['quantity'], Pay_Helper::calculateTaxClass($priceWithTax, $tax));
$apiStart->addProduct(
$product['product_id'],
$product['name'],
$price,
$product['quantity'],
Pay_Helper::calculateTaxClass($priceWithTax, $tax)
);
}

$taxes = $this->cart->getTaxes();
Expand Down Expand Up @@ -199,7 +216,7 @@ public function startTransaction()
$totalIncl = $totalIncl * $currency_value;
$total_row_tax = $total_row_tax * $currency_value;

switch($total_row['code']){
switch ($total_row['code']) {
case 'shipping':
$type = "SHIPPING";
break;
Expand All @@ -209,7 +226,7 @@ public function startTransaction()
}

$apiStart->addProduct($total_row['code'], $total_row['title'], round($totalIncl * 100), 1, Pay_Helper::calculateTaxClass($totalIncl, $total_row_tax), $type);
}
}
}

$postData = $apiStart->getPostData();
Expand All @@ -218,9 +235,14 @@ public function startTransaction()

//transactie is aangemaakt, nu loggen
$modelName = 'model_extension_payment_' . $this->_paymentMethodName;
$this->$modelName->addTransaction($result['transaction']['transactionId'],
$order_info['order_id'], $this->_paymentOptionId, $amount,
$postData, $optionSub);
$this->$modelName->addTransaction(
$result['transaction']['transactionId'],
$order_info['order_id'],
$this->_paymentOptionId,
$amount,
$postData,
$optionSub
);

$message = 'PAY. Transactie aangemaakt. TransactieId: ' . $result['transaction']['transactionId'] . ' .<br />';

Expand All @@ -241,6 +263,9 @@ public function startTransaction()
die(json_encode($response));
}

/**
* @return void
*/
public function finish()
{
$this->load->model('extension/payment/' . $this->_paymentMethodName);
Expand All @@ -262,7 +287,7 @@ public function finish()
$action = $this->request->get['orderStatusId'];
if ($action == -90) {
$this->session->data['error'] = $this->language->get('text_cancel');
} else if ($action == -63) {
} elseif ($action == -63) {
$this->session->data['error'] = $this->language->get('text_denied');
}

Expand All @@ -271,6 +296,9 @@ public function finish()
die();
}

/**
* @return void
*/
public function exchange()
{
$this->load->model('extension/payment/' . $this->_paymentMethodName);
Expand Down
4 changes: 4 additions & 0 deletions upload/admin/language/en-gb/extension/payment/paynl3.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
$_['text_classic'] = 'Classic';
$_['text_newest'] = 'Newest';

$_['text_custom_exchange_url'] = 'Alternatieve Exchange URL';
$_['text_custom_exchange_url_tooltip'] = 'Use your own exchange-handler. Requests will be send as GET.<br/>
Example: https://www.yourdomain.nl/exchange_handler?action=#action#&order_id=#order_id#';

$_['text_testmode'] = 'Testmode';
$_['text_testmode_tooltip'] = 'Enable or disable test mode to test the exchanges between PAY. and your webshop';

Expand Down
4 changes: 4 additions & 0 deletions upload/admin/language/nl-nl/extension/payment/paynl3.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
$_['text_classic'] = 'Klassiek';
$_['text_newest'] = 'Nieuwste';

$_['text_custom_exchange_url'] = 'Alternatieve Exchange URL';
$_['text_custom_exchange_url_tooltip'] = 'Gebruik je eigen exchange-handler. Requests zullen verzonden worden al een GET.<br/>
Voorbeeld: https://www.yourdomain.nl/exchange_handler?action=#action#&order_id=#order_id#';

$_['text_testmode'] = 'Testmode';
$_['text_testmode_tooltip'] = 'Zet de testmode aan of uit om de exchanges te testen tussen PAY. en uw webshop';

Expand Down
11 changes: 11 additions & 0 deletions upload/admin/view/template/extension/payment/paynl3.twig
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"
for="payment_paynl_general_custom_exchange_url">
<span data-toggle="tooltip" title="{{ text_custom_exchange_url_tooltip }}">
{{ text_custom_exchange_url }}
</span></label>
<div class="col-sm-10">
<input type="text" class="form-control" name="payment_paynl_general_custom_exchange_url"
value="{{ custom_exchange_url }}"/>
</div>
</div>
<div class="form-group">
<div class="panel-heading" style="border-top: 1px solid #dcdcdc; margin-top: 15px;">
<h3 class="panel-title"><i class="fa fa-euro"></i> {{ text_method_settings }}</h3>
Expand Down

0 comments on commit e136906

Please sign in to comment.