/** * Books the incoming payment */ public function book() { $methodOfPaymentId = PlentymarketsMappingController::getMethodOfPaymentByShopwareID($this->order['paymentId']); if ($methodOfPaymentId == MOP_AMAZON_PAYMENT) { PlentymarketsLogger::getInstance()->message('Sync:Order:IncomingPayment', 'The incoming payment of the order with the number »' . $this->order['number'] . '« was ignored (Amazon Payment)'); return; } $transactionId = ''; if ($methodOfPaymentId == MOP_KLARNA || $methodOfPaymentId == MOP_KLARNACREDIT) { $transactionId = $this->getKlarnaTransactionId(); $reasonForPayment = ''; } else { $reasonForPayment = sprintf('Shopware (OrderId: %u, CustomerId: %u)', $this->order['id'], $this->order['customerId']); } if ($methodOfPaymentId == MOP_HEIDELPAY_DD || $methodOfPaymentId == MOP_HEIDELPAY_PP || $methodOfPaymentId == MOP_HEIDELPAY_CC || $methodOfPaymentId == MOP_HEIDELPAY_DC || $methodOfPaymentId == MOP_HEIDELPAY_OT || $methodOfPaymentId == MOP_HEIDELPAY_VA || $methodOfPaymentId == MOP_HEIDELPAY_UA || $methodOfPaymentId == MOP_HEIDELPAY_SFT || $methodOfPaymentId == MOP_HEIDELPAY_TP || $methodOfPaymentId == MOP_HEIDELPAY_GP || $methodOfPaymentId == MOP_HEIDELPAY_IDL || $methodOfPaymentId == MOP_HEIDELPAY_EPS || $methodOfPaymentId == MOP_HEIDELPAY_CB) { $transactionId = $this->getHeidelpayUniqueId() . ';' . $this->order['transactionId']; } $Request_AddIncomingPayments = new PlentySoapRequest_AddIncomingPayments(); $Request_AddIncomingPayments->IncomingPayments = array(); $Object_AddIncomingPayments = new PlentySoapObject_AddIncomingPayments(); $Object_AddIncomingPayments->Amount = $this->order['invoiceAmount']; $Object_AddIncomingPayments->Currency = PlentymarketsMappingController::getCurrencyByShopwareID($this->order['currency']); $Object_AddIncomingPayments->CustomerEmail = $this->order['customer']['email']; $Object_AddIncomingPayments->CustomerID = $this->getCustomerId(); $Object_AddIncomingPayments->CustomerName = $this->getCustomerName(); $Object_AddIncomingPayments->MethodOfPaymentID = $methodOfPaymentId; $Object_AddIncomingPayments->OrderID = $this->plentyOrder->plentyOrderId; $Object_AddIncomingPayments->ReasonForPayment = $reasonForPayment; if ($transactionId) { $Object_AddIncomingPayments->TransactionID = $transactionId; } else { if (empty($this->order['transactionId'])) { $Object_AddIncomingPayments->TransactionID = $Object_AddIncomingPayments->ReasonForPayment; } else { $Object_AddIncomingPayments->TransactionID = $this->order['transactionId']; } } if ($this->object['clearedDate'] instanceof DateTime) { $Object_AddIncomingPayments->TransactionTime = $this->order['clearedDate']->getTimestamp(); } else { $Object_AddIncomingPayments->TransactionTime = time(); } $Request_AddIncomingPayments->IncomingPayments[] = $Object_AddIncomingPayments; $Response_AddIncomingPayments = PlentymarketsSoapClient::getInstance()->AddIncomingPayments($Request_AddIncomingPayments); // Check for success if ($Response_AddIncomingPayments->Success) { PlentymarketsLogger::getInstance()->message('Sync:Order:IncomingPayment', 'The incoming payment of the order with the number »' . $this->order['number'] . '« was booked'); Shopware()->Db()->query(' UPDATE plenty_order SET plentyOrderPaidStatus = 1, plentyOrderPaidTimestamp = NOW() WHERE shopwareId = ? ', array($this->order['id'])); } else { throw new PlentymarketsExportEntityException('The incoming payment of the order with the number »' . $this->order['number'] . '« could not be booked', 4140); } }
/** * Returns the method of payment id * * @throws PlentymarketsExportEntityException if there is no mapping */ protected function getMethodOfPaymentId() { // Sub-objects $Payment = $this->Order->getPayment(); // Payment if ($Payment) { try { return PlentymarketsMappingController::getMethodOfPaymentByShopwareID($Payment->getId()); } catch (PlentymarketsMappingExceptionNotExistant $E) { $shopgateIds = explode('|', PyConf()->get('OrderShopgateMOPIDs', '')); if (in_array($Payment->getId(), $shopgateIds)) { return MOP_SHOPGATE; } } } // Save the error $this->setError(self::CODE_ERROR_MOP); // Exit throw new PlentymarketsExportEntityException('The order with the number »' . $this->Order->getNumber() . '« could not be exported (no mapping for method of payment)', 4030); }