Skip to content

Commit

Permalink
Merge pull request #7 from paynl/PLUG-93
Browse files Browse the repository at this point in the history
PLUG-93
  • Loading branch information
max-geraci authored Mar 23, 2020
2 parents 7f649af + c9f7f04 commit a25f46b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
12 changes: 5 additions & 7 deletions paynl_paymentmethods/controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ public function initContent()
}

$arrEnduser['emailAddress'] = $customer->email;

$arrEnduser['gender'] = $customer->id_gender == 2 ? 'F' : 'M';

// delivery address
$arrAddress = array();
$strAddress = $deliveryAddress->address1 . $deliveryAddress->address2;
$arrStreetHouseNr = Pay_Helper::splitAddress($strAddress);
$arrAddress['streetName'] = $arrStreetHouseNr[0];
$arrAddress['streetNumber'] = $arrStreetHouseNr[1];
$arrAddress['streetNumber'] = !empty($arrStreetHouseNr[1]) ? substr($arrStreetHouseNr[1],0,44) : '';
$arrAddress['zipCode'] = $deliveryAddress->postcode;
$arrAddress['city'] = $deliveryAddress->city;
$country = new Country($deliveryAddress->id_country);
Expand All @@ -153,7 +153,7 @@ public function initContent()
$strAddress = $invoiceAddress->address1 . $invoiceAddress->address2;
$arrStreetHouseNr = Pay_Helper::splitAddress($strAddress);
$arrAddress['streetName'] = $arrStreetHouseNr[0];
$arrAddress['streetNumber'] = $arrStreetHouseNr[1];
$arrAddress['streetNumber'] = !empty($arrStreetHouseNr[1]) ? substr($arrStreetHouseNr[1],0,44) : '';
$arrAddress['zipCode'] = $invoiceAddress->postcode;
$arrAddress['city'] = $invoiceAddress->city;
$country = new Country($invoiceAddress->id_country);
Expand Down Expand Up @@ -211,18 +211,17 @@ public function initContent()
$description = trim($description);
$apiStart->setDescription($description);
$apiStart->setExtra1('CartId: ' . $cart->id);
$apiStart->setObject('prestashop16 ' . $module->getVersion());
$apiStart->setOrderNumber($cart->id);

$apiStart->setPaymentOptionId($paymentOptionId);

$finishUrl = Context::getContext()->link->getModuleLink('paynl_paymentmethods', 'return');
$exchangeUrl = Context::getContext()->link->getModuleLink('paynl_paymentmethods', 'exchange');


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

$apiStart->setAmount(round($total * 100));

$apiStart->setCurrency($currencyCode);

$result = $apiStart->doRequest();
Expand All @@ -238,7 +237,6 @@ public function initContent()

Tools::redirect($result['transaction']['paymentURL']);

//$url = $paynl->startTransaction($cart);
} catch (Exception $e) {
echo $e->getMessage();
}
Expand Down
14 changes: 10 additions & 4 deletions paynl_paymentmethods/includes/classes/Pay/Api/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class Pay_Api_Start extends Pay_Api {
private $_info;
private $_tool;
private $_object;
private $_ordernumber;
private $_domainId;
private $_transferData;

private $_products = array();

public function setCurrency($currency){
Expand All @@ -44,7 +45,10 @@ public function setTool($tool){
public function setObject($object){
$this->_object = $object;
}

public function setOrderNumber($ordernumber) {
$this->_ordernumber = $ordernumber;
}

public function setTransferData($transferData){
$this->_transferData = $transferData;
}
Expand Down Expand Up @@ -232,11 +236,12 @@ protected function _getPostData() {
if (!empty($this->_exchangeUrl)) {
$data['transaction']['orderExchangeUrl'] = $this->_exchangeUrl;
}

if (!empty($this->_description)) {
$data['transaction']['description'] = $this->_description;
}

if (!empty($this->_ordernumber)) {
$data['transaction']['orderNumber'] = $this->_ordernumber;
}
if (!empty($this->_paymentOptionSubId)) {
$data['paymentOptionSubId'] = $this->_paymentOptionSubId;
}
Expand Down Expand Up @@ -270,6 +275,7 @@ protected function _getPostData() {
$data['enduser'] = $this->_enduser;
}


if (!empty($this->_extra1)) {
$data['statsData']['extra1'] = $this->_extra1;
}
Expand Down
16 changes: 4 additions & 12 deletions paynl_paymentmethods/includes/classes/Pay/Helper/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ public static function processTransaction($transactionId, $dry_run = false)
throw new Pay_Exception_Notice('Status already processed');
}

//update the transaction state
self::updateTransactionState($transactionId, $stateText);

$statusPaid = Configuration::get('PAYNL_SUCCESS');
$statusCancel = Configuration::get('PAYNL_CANCEL');


if ($stateText == 'PAID') {
$id_order_state = $statusPaid;
$id_order_state = Configuration::get('PAYNL_SUCCESS');

/** @var CartCore $cart */
$cart = new Cart($cartId);
Expand All @@ -97,11 +90,8 @@ public static function processTransaction($transactionId, $dry_run = false)
$cart->save();

$paymentMethodName = $module->getPaymentMethodName($transaction['option_id']);


$paidAmount = $transactionAmount / 100;


$module->validateOrderPay((int)$cart->id, $id_order_state, $paidAmount, $extraFee, $paymentMethodName, null,
array('transaction_id' => $transactionId), (int)$objCurrency->id, false, $customer->secure_key);

Expand All @@ -121,11 +111,13 @@ public static function processTransaction($transactionId, $dry_run = false)
$objOrder = new Order($real_order_id);
$history = new OrderHistory();
$history->id_order = (int)$objOrder->id;
$history->changeIdOrderState((int)$statusCancel, $objOrder);
$history->changeIdOrderState((int)Configuration::get('PAYNL_CANCEL'), $objOrder);
$history->addWithemail();
}
}

self::updateTransactionState($transactionId, $stateText);

$real_order_id = Order::getOrderByCartId($cartId);
return array(
'orderId' => $orderId,
Expand Down
5 changes: 5 additions & 0 deletions paynl_paymentmethods/paynl_paymentmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public function __construct()
}
}

public function getVersion()
{
return $this->version;
}

public function getHighestVatRate(Cart $cart){
$highestVatRate = 0;
$products = $cart->getProducts();
Expand Down

0 comments on commit a25f46b

Please sign in to comment.