Skip to content

Commit

Permalink
Merge pull request #127 from michielgerritsen/feature/payment-descrip…
Browse files Browse the repository at this point in the history
…tion-variables

Added the customerCompany and the customerName to the payment variables
  • Loading branch information
Marvin-Magmodules authored Jul 30, 2019
2 parents 82e6f44 + 32c43ed commit e18353c
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 35 deletions.
11 changes: 8 additions & 3 deletions app/code/community/Mollie/Mpm/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,11 @@ public function getSupportedLocale()

/**
* @param $method
* @param $orderNumber
* @param $order
* @param int $storeId
* @return string
*/
public function getPaymentDescription($method, $orderNumber, $storeId = 0)
public function getPaymentDescription($method, Mage_Sales_Model_Order $order, $storeId = 0)
{
$xpath = str_replace('%method%', 'mollie_' . $method, self::XPATH_PAYMENT_DESCRIPTION);
$description = $this->getStoreConfig($xpath);
Expand All @@ -896,9 +896,14 @@ public function getPaymentDescription($method, $orderNumber, $storeId = 0)
$description = '{ordernumber}';
}

$address = $order->getBillingAddress();
$customerNameParts = array_filter([$address->getFirstname(), $address->getMiddlename(), $address->getLastname()]);

$replacements = [
'{ordernumber}' => $orderNumber,
'{ordernumber}' => $order->getIncrementId(),
'{storename}' => Mage::app()->getStore($storeId)->getFrontendName(),
'{customerCompany}' => $address->getCompany(),
'{customerName}' => implode(' ', $customerNameParts),
];

return str_replace(
Expand Down
4 changes: 2 additions & 2 deletions app/code/community/Mollie/Mpm/Model/Client/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function startTransaction(Mage_Sales_Model_Order $order)
$method = $this->mollieHelper->getMethodCode($order);
$paymentData = array(
'amount' => $this->mollieHelper->getOrderAmountByOrder($order),
'description' => $this->mollieHelper->getPaymentDescription($method, $order->getIncrementId(), $storeId),
'description' => $this->mollieHelper->getPaymentDescription($method, $order, $storeId),
'billingAddress' => $this->getAddressLine($order->getBillingAddress()),
'redirectUrl' => $this->mollieHelper->getReturnUrl($orderId, $paymentToken, $storeId),
'webhookUrl' => $this->mollieHelper->getWebhookUrl($storeId),
Expand Down Expand Up @@ -334,4 +334,4 @@ public function checkCheckoutSession($order, $paymentToken, $paymentData, $type)
}
}

}
}
69 changes: 69 additions & 0 deletions app/code/community/Mollie/Mpm/Test/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,73 @@ public function testGetLocaleCanReturnNull()

$this->assertNull($result);
}

public function generatesTheCorrectPaymentDescriptionProvider()
{
return [
['{storename} - {ordernumber} Order', 'Store Name - Default - 999 Order'],
['{customerCompany} Order', 'Acme Company Order'],
['{customerName} Order', 'John I. Doe Order'],
];
}
/**
* @dataProvider generatesTheCorrectPaymentDescriptionProvider
*/
public function testGeneratesTheCorrectPaymentDescription($description, $expected)
{
Mage::app()->getStore()->setConfig('payment/mollie_ideal/payment_description', $description);

$order = Mage::getModel('sales/order');
$order->setIncrementId(999);

$address = Mage::getModel('sales/quote_address');
$address->setAddressType('billing');
$address->setCompany('Acme Company');
$address->setFirstname('John');
$address->setMiddlename('I.');
$address->setLastname('Doe');

$addressList = $order->getAddressesCollection();
$addressList->addItem($address);

/** @var Mollie_Mpm_Helper_Data $instance */
$instance = Mage::helper('mpm');
$result = $instance->getPaymentDescription('ideal', $order);

$this->assertEquals($expected, $result);
}
public function trimsTheCustomerNameCorrectProvider()
{
return [
'fullname' => [['John', 'I.', 'Doe'], 'John I. Doe'],
'no middlename' => [['John', null, 'Doe'], 'John Doe'],
'no middle and lastname' => [['John', null, null], 'John'],
'only lastname' => [[null, null, 'Doe'], 'Doe'],
];
}
/**
* @dataProvider trimsTheCustomerNameCorrectProvider
*/
public function testTrimsTheCustomerNameCorrect($names, $expected)
{
Mage::app()->getStore()->setConfig('payment/mollie_ideal/payment_description', '{customerName}');

$order = Mage::getModel('sales/order');
$order->setIncrementId(999);

$address = Mage::getModel('sales/quote_address');
$address->setAddressType('billing');
$address->setFirstname($names[0]);
$address->setMiddlename($names[1]);
$address->setLastname($names[2]);

$addressList = $order->getAddressesCollection();
$addressList->addItem($address);

/** @var Mollie_Mpm_Helper_Data $instance */
$instance = Mage::helper('mpm');
$result = $instance->getPaymentDescription('ideal', $order);

$this->assertEquals($expected, $result);
}
}
Loading

0 comments on commit e18353c

Please sign in to comment.