/** * Generate Payment Log depending on the status * * @param array $paymentLog Data for payment log storage * @param bool $updatePaymentStatus Update Payment Status * * @return bool */ public static function saveNewPaymentLog($paymentLog, $updatePaymentStatus = true) { if (empty($paymentLog['payment_id'])) { return false; } // Forcing default set of statuses $paymentLog['status'] = RApiPaymentStatus::getStatus($paymentLog['status']); // Currency should not be numeric if (!empty($paymentLog['currency']) && is_numeric($paymentLog['currency'])) { $paymentLog['currency'] = RHelperCurrency::getIsoCode($paymentLog['currency']); } /** @var RedcoreModelPayment_Log $logModel */ $logModel = RModelAdmin::getAdminInstance('Payment_Log', array(), 'com_redcore'); if ($logModel->save($paymentLog)) { if ($updatePaymentStatus) { self::updatePaymentStatus($paymentLog['payment_id']); } } return true; }
/** * Handle the reception of notification from the payment gateway * * @param string $extensionName Name of the extension * @param string $ownerName Name of the owner * @param array $data Data to fill out Payment form * @param array &$logData Log data for payment api * * @return bool paid status */ public function handleCallback($extensionName, $ownerName, $data, &$logData) { $post = JFactory::getApplication()->input->post->getArray(); $postData = array(); // Read the post from PayPal system and add 'cmd' $postData[] = 'cmd=_notify-validate'; foreach ($post as $key => $value) { $value = urlencode(stripslashes($value)); $postData[] = "{$key}={$value}"; } $request = implode('&', $postData); $response = $this->getRequestFromGateway($request); if (strcmp($response, "VERIFIED") == 0) { /* Check the payment_status is Completed check that txn_id has not been previously processed check that receiver_email is your Primary PayPal email check that payment_amount/payment_currency are correct */ $payment = $this->getPaymentByExtensionOrderData($extensionName, $data); if ($post['mc_gross'] != $payment->amount_total) { $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_PRICE_MISMATCH', $extensionName, $this->paymentName, $payment->amount_total, $post['mc_gross']); RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText); $logData['status'] = RApiPaymentStatus::getStatusCreated(); $logData['message_text'] = $statusText; return false; } elseif ($post['mc_currency'] != $payment->currency) { $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_CURRENCY_MISMATCH', $extensionName, $this->paymentName, $payment->currency, $post['mc_currency']); RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText); $logData['status'] = RApiPaymentStatus::getStatusCreated(); $logData['message_text'] = $statusText; return false; } // We are clear to log successful payment log now // Paypal have very similar structure of Status response so we can actually get them directly $logData['status'] = RApiPaymentStatus::getStatus($post['payment_status']); if ($logData['status'] == RApiPaymentStatus::getStatusCompleted()) { $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_SUCCESSFUL', $extensionName, $this->paymentName); } else { $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_CALLBACK_STATUS', $extensionName, $logData['status'], $this->paymentName); } RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = true, $statusText); } elseif (strcmp($response, "INVALID") == 0) { $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_IN_PAYMENT_GATEWAY', $extensionName, $this->paymentName, 'INVALID IPN'); RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText); $logData['status'] = RApiPaymentStatus::getStatusCreated(); $logData['message_text'] = $statusText; return false; } else { $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_IN_PAYMENT_GATEWAY', $extensionName, $this->paymentName, 'HTTP ERROR'); RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText); $logData['status'] = RApiPaymentStatus::getStatusCreated(); $logData['message_text'] = $statusText; return false; } $logData['message_text'] = $statusText; $logData['currency'] = $payment->currency; $logData['amount'] = $payment->amount_total; $logData['transaction_id'] = $data['txn_id']; return true; }