Skip to content

Commit e18353c

Browse files
Merge pull request #127 from michielgerritsen/feature/payment-description-variables
Added the customerCompany and the customerName to the payment variables
2 parents 82e6f44 + 32c43ed commit e18353c

File tree

4 files changed

+139
-35
lines changed

4 files changed

+139
-35
lines changed

app/code/community/Mollie/Mpm/Helper/Data.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -883,11 +883,11 @@ public function getSupportedLocale()
883883

884884
/**
885885
* @param $method
886-
* @param $orderNumber
886+
* @param $order
887887
* @param int $storeId
888888
* @return string
889889
*/
890-
public function getPaymentDescription($method, $orderNumber, $storeId = 0)
890+
public function getPaymentDescription($method, Mage_Sales_Model_Order $order, $storeId = 0)
891891
{
892892
$xpath = str_replace('%method%', 'mollie_' . $method, self::XPATH_PAYMENT_DESCRIPTION);
893893
$description = $this->getStoreConfig($xpath);
@@ -896,9 +896,14 @@ public function getPaymentDescription($method, $orderNumber, $storeId = 0)
896896
$description = '{ordernumber}';
897897
}
898898

899+
$address = $order->getBillingAddress();
900+
$customerNameParts = array_filter([$address->getFirstname(), $address->getMiddlename(), $address->getLastname()]);
901+
899902
$replacements = [
900-
'{ordernumber}' => $orderNumber,
903+
'{ordernumber}' => $order->getIncrementId(),
901904
'{storename}' => Mage::app()->getStore($storeId)->getFrontendName(),
905+
'{customerCompany}' => $address->getCompany(),
906+
'{customerName}' => implode(' ', $customerNameParts),
902907
];
903908

904909
return str_replace(

app/code/community/Mollie/Mpm/Model/Client/Payments.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function startTransaction(Mage_Sales_Model_Order $order)
7575
$method = $this->mollieHelper->getMethodCode($order);
7676
$paymentData = array(
7777
'amount' => $this->mollieHelper->getOrderAmountByOrder($order),
78-
'description' => $this->mollieHelper->getPaymentDescription($method, $order->getIncrementId(), $storeId),
78+
'description' => $this->mollieHelper->getPaymentDescription($method, $order, $storeId),
7979
'billingAddress' => $this->getAddressLine($order->getBillingAddress()),
8080
'redirectUrl' => $this->mollieHelper->getReturnUrl($orderId, $paymentToken, $storeId),
8181
'webhookUrl' => $this->mollieHelper->getWebhookUrl($storeId),
@@ -334,4 +334,4 @@ public function checkCheckoutSession($order, $paymentToken, $paymentData, $type)
334334
}
335335
}
336336

337-
}
337+
}

app/code/community/Mollie/Mpm/Test/Helper/DataTest.php

+69
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,73 @@ public function testGetLocaleCanReturnNull()
6868

6969
$this->assertNull($result);
7070
}
71+
72+
public function generatesTheCorrectPaymentDescriptionProvider()
73+
{
74+
return [
75+
['{storename} - {ordernumber} Order', 'Store Name - Default - 999 Order'],
76+
['{customerCompany} Order', 'Acme Company Order'],
77+
['{customerName} Order', 'John I. Doe Order'],
78+
];
79+
}
80+
/**
81+
* @dataProvider generatesTheCorrectPaymentDescriptionProvider
82+
*/
83+
public function testGeneratesTheCorrectPaymentDescription($description, $expected)
84+
{
85+
Mage::app()->getStore()->setConfig('payment/mollie_ideal/payment_description', $description);
86+
87+
$order = Mage::getModel('sales/order');
88+
$order->setIncrementId(999);
89+
90+
$address = Mage::getModel('sales/quote_address');
91+
$address->setAddressType('billing');
92+
$address->setCompany('Acme Company');
93+
$address->setFirstname('John');
94+
$address->setMiddlename('I.');
95+
$address->setLastname('Doe');
96+
97+
$addressList = $order->getAddressesCollection();
98+
$addressList->addItem($address);
99+
100+
/** @var Mollie_Mpm_Helper_Data $instance */
101+
$instance = Mage::helper('mpm');
102+
$result = $instance->getPaymentDescription('ideal', $order);
103+
104+
$this->assertEquals($expected, $result);
105+
}
106+
public function trimsTheCustomerNameCorrectProvider()
107+
{
108+
return [
109+
'fullname' => [['John', 'I.', 'Doe'], 'John I. Doe'],
110+
'no middlename' => [['John', null, 'Doe'], 'John Doe'],
111+
'no middle and lastname' => [['John', null, null], 'John'],
112+
'only lastname' => [[null, null, 'Doe'], 'Doe'],
113+
];
114+
}
115+
/**
116+
* @dataProvider trimsTheCustomerNameCorrectProvider
117+
*/
118+
public function testTrimsTheCustomerNameCorrect($names, $expected)
119+
{
120+
Mage::app()->getStore()->setConfig('payment/mollie_ideal/payment_description', '{customerName}');
121+
122+
$order = Mage::getModel('sales/order');
123+
$order->setIncrementId(999);
124+
125+
$address = Mage::getModel('sales/quote_address');
126+
$address->setAddressType('billing');
127+
$address->setFirstname($names[0]);
128+
$address->setMiddlename($names[1]);
129+
$address->setLastname($names[2]);
130+
131+
$addressList = $order->getAddressesCollection();
132+
$addressList->addItem($address);
133+
134+
/** @var Mollie_Mpm_Helper_Data $instance */
135+
$instance = Mage::helper('mpm');
136+
$result = $instance->getPaymentDescription('ideal', $order);
137+
138+
$this->assertEquals($expected, $result);
139+
}
71140
}

0 commit comments

Comments
 (0)