Skip to content

Commit

Permalink
Merge pull request #459 from fatchip-Stefan/SW-393_alipay_remove_capture
Browse files Browse the repository at this point in the history
SW-393 remove capturemode param for alipay, trustly, wechatpay and secure invoice
  • Loading branch information
jvarelmann authored May 19, 2022
2 parents 6bf2503 + b5f3501 commit c7f6369
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Frontend/MoptPaymentPayone/Components/Classes/PayoneConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Mopt_PayoneConfig
'mopt_payone__ibt_bancontact',
'mopt_payone__ewallet_amazon_pay',
'mopt_payone__ewallet_alipay',
'mopt_payone__ibt_trustly',
'mopt_payone__ewallet_wechatpay',
];

const PAYMENTS_ADDRESSCHECK_EXCLUDED = [
Expand Down Expand Up @@ -105,6 +107,8 @@ class Mopt_PayoneConfig
'mopt_payone__acc_payone_safe_invoice',
'mopt_payone__ibt_bancontact',
'mopt_payone__ewallet_alipay',
'mopt_payone__ibt_trustly',
'mopt_payone__ewallet_wechatpay',
];

const PAYMENTS_EXCLUDED_FROM_ACCOUNTPAGE = [
Expand All @@ -121,6 +125,13 @@ class Mopt_PayoneConfig
'mopt_payone_klarna',
];

const PAYMENTS_DONOTSENDCAPTUREMODE = [
'mopt_payone__acc_payone_safe_invoice',
'mopt_payone__ewallet_alipay',
'mopt_payone__ibt_trustly',
'mopt_payone__ewallet_wechatpay',
];

/**
* return array with configured valid IPs to accept transaction feedback from
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public function toArray()
* @var Payone_Api_Request_Parameter_Interface $data
*/
$result = array_merge($result, $data->toArray());
if (empty($result['capturemode'])) {
unset($result['capturemode']);
}
} elseif ($data instanceof Payone_Protocol_Service_ApplyFilters == false) {
$result[$key] = $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public function moptPayoneCaptureOrderAction()

$payment = $order->getPayment();
$paymentName = $payment->getName();
// remove _1 ,_2 ... from duplicated payments before matching
$cleanedPaymentName = preg_replace('/_[0-9]*$/', '', $paymentName);

if ($request->getParam('includeShipment') === 'true') {
$includeShipment = true;
} else {
Expand Down Expand Up @@ -138,8 +141,12 @@ public function moptPayoneCaptureOrderAction()

if ($this->moptPayone__main->getPaymentHelper()->isPayoneSafeInvoice($paymentName)){
$autoSettleAccount = true;
}

if (in_array( $cleanedPaymentName,\Mopt_PayoneConfig::PAYMENTS_DONOTSENDCAPTUREMODE)) {
$doNotSendCaptureMode = true;
}

$response = $this->moptPayone_callCaptureService($params, $invoicing, $autoSettleAccount, $doNotSendCaptureMode);

if ($response->getStatus() == Payone_Api_Enum_ResponseType::APPROVED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ public function indexAction()
$request = $this->Request();

$this->logger->debug('notification controller called');

if (!$request->isPost()) {
$this->redirect(array('controller' => 'index', 'action' => 'error'));
return;
}

$this->logger->debug('received $_POST:' . PHP_EOL . var_export($_POST, true) . PHP_EOL);

$rawPost = $_POST;
$_POST = array_map('utf8_encode', $_POST); // utf8 encode all post params to avoid encoding issues

$_POST = $this->utf8_encode_array($_POST);
$this->logger->debug('successfully converted $_POST to utf-8:' . PHP_EOL . var_export($_POST, true) . PHP_EOL);
$request->setParamSources(array('_POST')); // only retrieve data from POST

$this->CheckAndFixActiveShopIfNeeded($request->getParam('param'));
Expand Down Expand Up @@ -129,7 +133,7 @@ public function indexAction()
$validators = $service->getValidators();
foreach ($validators as $validator) {
if ($validator instanceof Payone_TransactionStatus_Validator_Ip) {
$validator->getConfig()->setValue('validator/proxy/enabled',1);
$validator->getConfig()->setValue('validator/proxy/enabled', 1);
}
}

Expand Down Expand Up @@ -168,7 +172,7 @@ public function indexAction()
$this->logger->debug('finished, output TSOK');
echo $response->getStatus();
$this->logger->debug('starting tx forwards');
$this->moptPayoneForwardTransactionStatus($rawPost, $paymentId);
$this->moptPayoneForwardTransactionStatus($_POST, $paymentId);
$this->logger->debug('finished all tasks, exit');
exit;
}
Expand Down Expand Up @@ -220,7 +224,7 @@ public function indexAction()
$this->savePaymentStatus($transactionId, $order['temporaryID'], $mappedShopwareState);
}

} elseif ($request->getParam('txaction') === 'reminder' && $request->getParam('reminderlevel') === '0') {
} elseif ($request->getParam('txaction') === 'reminder' && $request->getParam('reminderlevel') === '0') {
// ignore txaction reminder with reminderlevel 0 since this only marks the end of dunning process
} else {
// ! Amazonpay
Expand All @@ -241,7 +245,7 @@ public function indexAction()
$this->logger->debug('finished, output TSOK');
echo $response->getStatus();
$this->logger->debug('starting tx forwards');
$this->moptPayoneForwardTransactionStatus($rawPost, $paymentId);
$this->moptPayoneForwardTransactionStatus($_POST, $paymentId);

// fire event to do some custom stuff, e.g. synchronising with merchandise management software
// please note that processing this event has to be fast because Payone will mark this request as
Expand Down Expand Up @@ -286,8 +290,6 @@ protected function moptPayoneInitTransactionService($key, $validIps)
*/
protected function moptPayoneForwardTransactionStatus($post, $paymentID)
{
$post = array_map('utf8_encode', $post); // utf8 encode all post params to avoid encoding issues

$post['paymentID'] = $paymentID;

$queueWorker = new Mopt_PayoneTransactionForwardingQueueWorker();
Expand Down Expand Up @@ -453,7 +455,7 @@ protected function saveOrderAttributeData($order, $attributeData, $saveOrderHash
);

$sql = 'UPDATE s_order_attributes SET mopt_payone_status=?, mopt_payone_sequencenumber=?, '
. 'mopt_payone_payment_reference=? ';
. 'mopt_payone_payment_reference=? ';

if ($saveOrderHash) {
$sql = $sql . ' , mopt_payone_order_hash=? ';
Expand Down Expand Up @@ -488,7 +490,7 @@ protected function CheckAndFixActiveShopIfNeeded($customParam)
$shopRepository = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop');
$shop = $shopRepository->getActiveById($shopId);
$shop->registerResources(Shopware()->Bootstrap());

$this->logger->info(
'different shop active, submitted id, new shopid',
array($activeShopId, $shopId, Shopware()->Shop()->getId())
Expand Down Expand Up @@ -525,6 +527,24 @@ protected function clearingDataExists($order)
protected function buildPayoneTransactionLogPath()
{
$logDir = Shopware()->Container()->get('kernel')->getLogDir();
return $logDir . '/moptPayoneTransactionStatus.log';
return $logDir . '/moptPayoneTransactionStatus.log';
}

/**
* converts multi dimensional arrays to utf8
* @param $array
* @return mixed
*/
private function utf8_encode_array($array)
{
foreach ($array as $key => $value) {
if (is_array($value)) {
$array[$key] = $this->utf8_encode_array($value);
} else {
$array[$key] = utf8_encode($value);
}
}
return $array;
}

}

0 comments on commit c7f6369

Please sign in to comment.