/** * Check - payment method is configured or not * * @param \XLite\Model\Payment\Method $method Payment method * * @return boolean */ public function isConfigured(\XLite\Model\Payment\Method $method) { return \XLite\Model\Payment\Base\Processor::isConfigured($method) && $this->api->isConfigured(); }
/** * Is forced Merchant API for Paypal Express * https://developer.paypal.com/docs/classic/api/#merchant * * @param \XLite\Model\Payment\Base\Processor $processor Payment processor * * @return boolean */ protected function isForceMerchantAPI($processor) { $parentMethod = $processor->getParentMethod(); return !$processor->isForcedEnabled($this) && ('email' == parent::getSetting('api_type') || 'paypal' == parent::getSetting('api_solution') || $parentMethod && !$processor->isConfigured($parentMethod)); }
/** * Translate array of data received from Paypal to the array for updating cart * * @param \XLite\Model\Payment\Base\Processor $processor Payment processor * @param array $paypalData Array of customer data received from Paypal * * @return array */ protected function prepareBuyerData($processor, $paypalData) { $data = $processor->prepareBuyerData($paypalData); if (!\XLite\Core\Auth::getInstance()->isLogged()) { $data += array('email' => str_replace(' ', '+', $paypalData['EMAIL']), 'create_profile' => false); } return $data; }
/** * Process callback * * @param \XLite\Model\Payment\Transaction $transaction Callback-owner transaction * @param \XLite\Model\Payment\Base\Processor $processor Payment processor object * * @return void */ public function processCallbackIPN($transaction, $processor) { $request = \XLite\Core\Request::getInstance(); \XLite\Module\CDev\Paypal\Main::addLog('processCallbackIPN()', $request->getData()); $status = $transaction::STATUS_FAILED; switch ($this->getIPNVerification()) { case self::IPN_DECLINED: $status = $transaction::STATUS_FAILED; $processor->markCallbackRequestAsInvalid(static::t('IPN verification failed')); break; case self::IPN_REQUEST_ERROR: $status = $transaction::STATUS_PENDING; $processor->markCallbackRequestAsInvalid(static::t('IPN HTTP error')); break; case self::IPN_VERIFIED: $backendTransaction = null; if (!empty($request->parent_txn_id)) { // Received IPN is related to the backend transaction $ppref = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\BackendTransactionData')->findOneBy(array('name' => 'PPREF', 'value' => $request->txn_id)); if ($ppref) { $backendTransaction = $ppref->getTransaction(); } } switch ($request->payment_status) { case 'Completed': case 'Canceled_Reversal': case 'Processed': $status = $transaction::STATUS_SUCCESS; if (\XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { if (!isset($backendTransaction)) { $backendTransaction = $this->registerBackendTransaction($transaction, \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_CAPTURE); } $backendTransactionStatus = $transaction::STATUS_SUCCESS; } break; case 'Pending': if ('authorization' == $request->pending_reason && \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { $status = $transaction::STATUS_SUCCESS; if (isset($backendTransaction)) { $backendTransactionStatus = $transaction::STATUS_SUCCESS; } } else { $status = $transaction::STATUS_PENDING; } break; case 'Expired': if (\XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { $status = $transaction::STATUS_FAILED; if (isset($backendTransaction)) { $backendTransactionStatus = $transaction::STATUS_FAILED; } } break; case 'Voided': if (\XLite\Model\Payment\BackendTransaction::TRAN_TYPE_AUTH == $transaction->getType()) { $status = $transaction::STATUS_VOID; } if (!isset($backendTransaction)) { $backendTransaction = $this->registerBackendTransaction($transaction, \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_VOID); } $backendTransactionStatus = $transaction::STATUS_SUCCESS; break; case 'Denied': case 'Reversed': $status = $transaction::STATUS_FAILED; break; case 'Failed': if (isset($backendTransaction)) { $backendTransactionStatus = $transaction::STATUS_FAILED; } break; case 'Refunded': if (!isset($backendTransaction)) { $backendTransaction = $this->registerBackendTransaction($transaction, \XLite\Model\Payment\BackendTransaction::TRAN_TYPE_REFUND); } $backendTransactionStatus = $transaction::STATUS_SUCCESS; $status = $transaction::STATUS_FAILED; break; default: // No default actions } default: // No default actions } if ($transaction->getStatus() != $status) { $transaction->setStatus($status); } if (isset($backendTransactionStatus)) { if ($backendTransaction->getStatus() != $backendTransactionStatus) { $backendTransaction->setStatus($backendTransactionStatus); } $processor->updateInitialBackendTransaction($transaction, $status); } elseif (!empty($request->parent_txn_id)) { \XLite\Core\OrderHistory::getInstance()->registerTransaction($transaction->getOrder()->getOrderNumber(), sprintf('IPN received [method: %s, amount: %s, payment status: %s]', $transaction->getPaymentMethod()->getName(), $request->transaction_entity, $request->mc_gross, $request->payment_status), $this->getRequestData(), 'Note: received IPN does not relate to any backend transaction registered with the order. It is possible if you update payment directly on PayPal site or if your customer or PayPal updated the payment.'); } }