Skip to content

Commit d8ef5bd

Browse files
Merge pull request #8 from appinlet/master
Revert to original 2.4.0
2 parents 2d0344a + c65543f commit d8ef5bd

File tree

7 files changed

+187
-222
lines changed

7 files changed

+187
-222
lines changed

app/code/Payfast/Payfast/Controller/Notify/Index.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
/**
55
* Copyright (c) 2008 PayFast (Pty) Ltd
6-
* You (being anyone who is not PayFast (Pty) Ltd) may download and use this plugin / code in your own website
7-
* in conjunction with a registered and active PayFast account. If your PayFast account is terminated for any reason,
8-
* you may not use this plugin / code or part thereof.
9-
* Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or
10-
* part thereof in any way.
6+
* You (being anyone who is not PayFast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active PayFast account. If your PayFast account is terminated for any reason, you may not use this plugin / code or part thereof.
7+
* Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part thereof in any way.
118
*/
129

1310

@@ -33,7 +30,6 @@ class Index extends AbstractPayfast implements CsrfAwareActionInterface, HttpPos
3330
*/
3431
public function execute(): ResultInterface
3532
{
36-
$this->_logger->debug('Notify: ' . json_encode($_POST));
3733
$pre = __METHOD__ . " : ";
3834
$this->_logger->debug($pre . 'bof');
3935

@@ -56,11 +52,6 @@ public function execute(): ResultInterface
5652
flush();
5753
}
5854

59-
$passPhrase = $this->_config->getValue('passphrase');
60-
if (empty($passPhrase)) {
61-
$passPhrase = null;
62-
}
63-
6455
//// Get data sent by PayFast
6556
if (!$pfError) {
6657
// Posted variables from ITN
@@ -80,7 +71,8 @@ public function execute(): ResultInterface
8071
if (!pfValidSignature(
8172
$pfData,
8273
$pfParamString,
83-
$passPhrase
74+
$this->getConfigData('passphrase'),
75+
$this->getConfigData('server')
8476
)) {
8577
$pfError = true;
8678
$pfErrMsg = PF_ERR_INVALID_SIGNATURE;
@@ -110,7 +102,7 @@ public function execute(): ResultInterface
110102

111103
// Check order is in "pending payment" state
112104
if ($this->_order->getState() !== Order::STATE_PENDING_PAYMENT) {
113-
// $pfError = true;
105+
$pfError = true;
114106
$pfErrMsg = PF_ERR_ORDER_PROCESSED;
115107
}
116108
}
@@ -130,7 +122,7 @@ public function execute(): ResultInterface
130122
pflog('Check status and update order');
131123

132124
// Successful
133-
if ($pfData[Info::PAYMENT_STATUS] === "COMPLETE") {
125+
if ($pfData[Info::PAYMENT_STATUS] == "COMPLETE") {
134126
$this->setPaymentAdditionalInformation($pfData);
135127
// Save invoice
136128
$this->saveInvoice();
@@ -169,18 +161,7 @@ protected function saveInvoice()
169161

170162
/** @var \Magento\Sales\Model\Order $order */
171163
$order = $invoice->getOrder();
172-
$status = $this->getConfigData('successful_order_status');
173-
$state = $this->getConfigData('successful_order_state');
174-
if (!$status || $status === '') {
175-
$status = Order::STATE_PROCESSING;
176-
}
177-
if (!$state || $state === '') {
178-
$state = Order::STATE_PROCESSING;
179-
}
180164
$order->setIsInProcess(true);
181-
$order->setState($state);
182-
$order->setStatus($status);
183-
$order->save();
184165
$transaction = $this->transactionFactory->create();
185166
$transaction->addObject($order)->save();
186167

app/code/Payfast/Payfast/Gateway/Request/AuthorizationRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ public function build(array $buildSubject)
9898
$pfOutput = '';
9999
// Create output string
100100
foreach ($data as $key => $val) {
101-
if (!empty($val) && $key !== 'currency') {
101+
if (!empty($val)) {
102102
$pfOutput .= $key . '=' . urlencode($val) . '&';
103103
}
104104
}
105105

106-
$passPhrase = $this->config->getValue('passphrase', $order->getStoreId()) ?? '';
107-
if (!empty($passPhrase)) {
108-
$pfOutput .= 'passphrase=' . urlencode($passPhrase);
109-
} else {
110-
$pfOutput = rtrim($pfOutput, '&');
106+
$passPhrase = $this->config->getValue('passphrase', $order->getStoreId());
107+
$pfOutput = substr($pfOutput, 0, -1);
108+
109+
if (!empty($passPhrase) && $this->config->getValue('server', $order->getStoreId()) !== 'test') {
110+
$pfOutput = $pfOutput . "&passphrase=" . urlencode($passPhrase);
111111
}
112112

113113
$this->logger->debug($pre . 'pfOutput for signature is : ' . $pfOutput);

app/code/Payfast/Payfast/Model/Payfast.php

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* You (being anyone who is not PayFast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active PayFast account. If your PayFast account is terminated for any reason, you may not use this plugin / code or part thereof.
66
* Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part thereof in any way.
77
*/
8-
98
namespace Payfast\Payfast\Model;
109

1110
require_once dirname(__FILE__) . '/../Model/payfast_common.inc';
@@ -33,13 +32,14 @@
3332
use Magento\Store\Model\Store;
3433
use Magento\Store\Model\StoreManagerInterface;
3534

36-
/**
37-
* PayFast Module.
38-
*
39-
* @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface getExtensionAttributes()
40-
* @SuppressWarnings(PHPMD.TooManyFields)
41-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
42-
*/
35+
/**
36+
* PayFast Module.
37+
*
38+
* @method \Magento\Quote\Api\Data\PaymentMethodExtensionInterface getExtensionAttributes()
39+
* @SuppressWarnings(PHPMD.TooManyFields)
40+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
41+
*/
42+
4343
class Payfast
4444
{
4545
/**
@@ -139,18 +139,18 @@ public function __construct(
139139
TransactionRepositoryInterface $transactionRepository,
140140
BuilderInterface $transactionBuilder
141141
) {
142-
$this->_storeManager = $storeManager;
143-
$this->_urlBuilder = $urlBuilder;
144-
$this->_checkoutSession = $checkoutSession;
145-
$this->_exception = $exception;
142+
$this->_storeManager = $storeManager;
143+
$this->_urlBuilder = $urlBuilder;
144+
$this->_checkoutSession = $checkoutSession;
145+
$this->_exception = $exception;
146146
$this->transactionRepository = $transactionRepository;
147-
$this->transactionBuilder = $transactionBuilder;
147+
$this->transactionBuilder = $transactionBuilder;
148148

149-
$parameters = ['params' => [$this->_code]];
149+
$parameters = [ 'params' => [ $this->_code ] ];
150150

151151
$this->_config = $configFactory->create($parameters);
152152

153-
if (!defined('PF_DEBUG')) {
153+
if (! defined('PF_DEBUG')) {
154154
define('PF_DEBUG', $this->_config->getValue('debug'));
155155
}
156156
}
@@ -191,8 +191,8 @@ public function canUseForCurrency($currencyCode)
191191
/**
192192
* Payment action getter compatible with payment model
193193
*
194-
* @return string
195194
* @see \Magento\Sales\Model\Payment::place()
195+
* @return string
196196
*/
197197
public function getConfigPaymentAction()
198198
{
@@ -233,8 +233,9 @@ protected function getStoreName()
233233
* this where we compile data posted by the form to payfast
234234
*
235235
* @return array
236+
* @throws \Magento\Framework\Exception\NoSuchEntityException
236237
*/
237-
public function getStandardCheckoutFormFields(): array
238+
public function getStandardCheckoutFormFields()
238239
{
239240
$pre = __METHOD__ . ' : ';
240241
// Variable initialization
@@ -247,16 +248,13 @@ public function getStandardCheckoutFormFields(): array
247248

248249
// If NOT test mode, use normal credentials
249250
if ($this->_config->getValue('server') == 'live') {
250-
$merchantId = $this->_config->getValue('merchant_id');
251+
$merchantId = $this->_config->getValue('merchant_id');
251252
$merchantKey = $this->_config->getValue('merchant_key');
252-
} // If test mode, use generic / specific sandbox credentials
253+
}
254+
// If test mode, use generic sandbox credentials
253255
else {
254-
$merchantId = !empty($this->_config->getValue('merchant_id')) ?
255-
$this->_config->getValue('merchant_id') :
256-
'10000100';
257-
$merchantKey = !empty($this->_config->getValue('merchant_key')) ?
258-
$this->_config->getValue('merchant_key') :
259-
'46f0cd694581a';
256+
$merchantId = '10000100';
257+
$merchantKey = '46f0cd694581a';
260258
}
261259

262260
// Create description
@@ -269,22 +267,22 @@ public function getStandardCheckoutFormFields(): array
269267
// Construct data for the form
270268
$data = [
271269
// Merchant details
272-
'merchant_id' => $merchantId,
273-
'merchant_key' => $merchantKey,
274-
'return_url' => $this->getPaidSuccessUrl(),
275-
'cancel_url' => $this->getPaidCancelUrl(),
276-
'notify_url' => $this->getPaidNotifyUrl(),
270+
'merchant_id' => $merchantId,
271+
'merchant_key' => $merchantKey,
272+
'return_url' => $this->getPaidSuccessUrl(),
273+
'cancel_url' => $this->getPaidCancelUrl(),
274+
'notify_url' => $this->getPaidNotifyUrl(),
277275

278276
// Buyer details
279-
'name_first' => $order->getData('customer_firstname'),
280-
'name_last' => $order->getData('customer_lastname'),
277+
'name_first' => $order->getData('customer_firstname'),
278+
'name_last' => $order->getData('customer_lastname'),
281279
'email_address' => $order->getData('customer_email'),
282280

283281
// Item details
284-
'm_payment_id' => $order->getRealOrderId(),
285-
'amount' => $this->getTotalAmount($order),
286-
'item_name' => 'Order #' . $order->getRealOrderId(),
287-
//this html special characters breaks signature.
282+
'm_payment_id' => $order->getRealOrderId(),
283+
'amount' => $this->getTotalAmount($order),
284+
'item_name' => $this->_storeManager->getStore()->getName() . ', Order #' . $order->getRealOrderId(),
285+
//this html special characters breaks signature.
288286
//'item_description' => $pfDescription,
289287
];
290288

@@ -297,21 +295,21 @@ public function getStandardCheckoutFormFields(): array
297295
}
298296

299297
$passPhrase = $this->_config->getValue('passphrase');
300-
if (!empty($passPhrase)) {
301-
$pfOutput .= 'passphrase=' . urlencode($passPhrase);
302-
} else {
303-
$pfOutput = rtrim($pfOutput, '&');
298+
$pfOutput = substr($pfOutput, 0, -1);
299+
300+
if (!empty($passPhrase) && $this->_config->getValue('server') !== 'test') {
301+
$pfOutput = $pfOutput . "&passphrase=" . urlencode($passPhrase);
304302
}
305303

306304
pflog($pre . 'pfOutput for signature is : ' . $pfOutput);
307305

308306
$pfSignature = md5($pfOutput);
309307

310-
$data['signature'] = $pfSignature;
308+
$data['signature'] = $pfSignature;
311309
$data['user_agent'] = 'Magento ' . $this->getAppVersion();
312310
pflog($pre . 'data is :' . print_r($data, true));
313311

314-
return ($data);
312+
return($data);
315313
}
316314

317315
/**
@@ -322,11 +320,10 @@ public function getStandardCheckoutFormFields(): array
322320
private function getAppVersion(): string
323321
{
324322
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
325-
$version = $objectManager->get('Magento\Framework\App\ProductMetadataInterface')->getVersion();
323+
$version = $objectManager->get('Magento\Framework\App\ProductMetadataInterface')->getVersion();
326324

327-
return (preg_match('([0-9])', $version)) ? $version : '2.0.0';
325+
return (preg_match('([0-9])', $version)) ? $version : '2.0.0';
328326
}
329-
330327
/**
331328
* getTotalAmount
332329
*/
@@ -354,7 +351,7 @@ public function getNumberFormat($number)
354351
*/
355352
public function getPaidSuccessUrl()
356353
{
357-
return $this->_urlBuilder->getUrl('payfast/redirect/success', ['_secure' => true]);
354+
return $this->_urlBuilder->getUrl('payfast/redirect/success', [ '_secure' => true ]);
358355
}
359356

360357
/**
@@ -366,11 +363,7 @@ public function getPaidSuccessUrl()
366363
*/
367364
protected function getOrderTransaction($payment)
368365
{
369-
return $this->transactionRepository->getByTransactionType(
370-
Transaction::TYPE_ORDER,
371-
$payment->getId(),
372-
$payment->getOrder()->getId()
373-
);
366+
return $this->transactionRepository->getByTransactionType(Transaction::TYPE_ORDER, $payment->getId(), $payment->getOrder()->getId());
374367
}
375368

376369
/*
@@ -383,13 +376,12 @@ public function getOrderPlaceRedirectUrl()
383376

384377
return $this->_urlBuilder->getUrl('payfast/redirect');
385378
}
386-
387379
/**
388380
* Checkout redirect URL getter for onepage checkout (hardcode)
389381
*
390-
* @return string
391-
* @see Quote\Payment::getCheckoutRedirectUrl()
392382
* @see \Magento\Checkout\Controller\Onepage::savePaymentAction()
383+
* @see Quote\Payment::getCheckoutRedirectUrl()
384+
* @return string
393385
*/
394386
public function getCheckoutRedirectUrl()
395387
{
@@ -405,15 +397,14 @@ public function getCheckoutRedirectUrl()
405397
*/
406398
public function getPaidCancelUrl()
407399
{
408-
return $this->_urlBuilder->getUrl('payfast/redirect/cancel', ['_secure' => true]);
400+
return $this->_urlBuilder->getUrl('payfast/redirect/cancel', [ '_secure' => true ]);
409401
}
410-
411402
/**
412403
* getPaidNotifyUrl
413404
*/
414405
public function getPaidNotifyUrl()
415406
{
416-
return $this->_urlBuilder->getUrl('payfast/notify', ['_secure' => true]);
407+
return $this->_urlBuilder->getUrl('payfast/notify', [ '_secure' => true ]);
417408
}
418409

419410
/**
@@ -423,7 +414,7 @@ public function getPaidNotifyUrl()
423414
*/
424415
public function getPayFastUrl()
425416
{
426-
return ('https://' . $this->getPayfastHost($this->_config->getValue('server')) . '/eng/process');
417+
return('https://' . $this->getPayfastHost($this->_config->getValue('server')) . '/eng/process');
427418
}
428419

429420
/**
@@ -433,7 +424,7 @@ public function getPayFastUrl()
433424
*/
434425
public function getPayfastHost($serverMode)
435426
{
436-
if (!in_array($serverMode, ['live', 'test'])) {
427+
if (!in_array($serverMode, [ 'live', 'test' ])) {
437428
$pfHost = "payfast.{$serverMode}";
438429
} else {
439430
$pfHost = (($serverMode == 'live') ? 'www' : 'sandbox') . '.payfast.co.za';

0 commit comments

Comments
 (0)