/** * execute * this method illustrate magento2 super power. */ public function execute() { $pre = __METHOD__ . " : "; pflog($pre . 'bof'); $page_object = $this->pageFactory->create(); try { $this->_initCheckout(); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->_logger->error($pre . $e->getMessage()); $this->messageManager->addExceptionMessage($e, $e->getMessage()); $this->_redirect('checkout/cart'); } catch (\Exception $e) { $this->_logger->error($pre . $e->getMessage()); $this->messageManager->addExceptionMessage($e, __('We can\'t start PayFast Checkout.')); $this->_redirect('checkout/cart'); } return $page_object; }
$error = true; return false; } pflog('ITN OK'); pflog("ITN verified for {$itnVerifyRequest}\n"); if ($error == false and $_POST['payment_status'] == "COMPLETE") { $user_id = intval($_POST['custom_int1']); $mc_gross = $_POST['amount_gross']; $membership_id = $_POST['m_payment_id']; $txn_id = $_POST['pf_payment_id']; $total = Core::getCart($user_id); $v1 = compareFloatNumbers($mc_gross, $total->totalprice, "="); if ($v1 == true) { $row = $db->first("SELECT * FROM " . Membership::mTable . " WHERE id=" . (int) $membership_id); $username = getValueById("username", Users::uTable, (int) $user_id); $data = array('txn_id' => $txn_id, 'membership_id' => $row->id, 'user_id' => (int) $user_id, 'rate_amount' => $total->originalprice, 'tax' => $total->totaltax, 'coupon' => $total->coupon, 'total' => $total->totalprice, 'ip' => $_SERVER['REMOTE_ADDR'], 'created' => "NOW()", 'pp' => "PayFast", 'currency' => "ZAR", 'status' => 1); $db->insert(Membership::pTable, $data); $udata = array('membership_id' => $row->id, 'mem_expire' => $user->calculateDays($row->id), 'trial_used' => $row->trial == 1 ? 1 : 0, 'memused' => 1); $db->update(Users::uTable, $udata, "id=" . (int) $user_id); /* == Notify Administrator == */ require_once BASEPATH . "lib/class_mailer.php"; $row2 = Core::getRowById(Content::eTable, 5); $body = str_replace(array('[USERNAME]', '[ITEMNAME]', '[PRICE]', '[STATUS]', '[PP]', '[IP]'), array($username, $row->title, $core->formatMoney($mc_gross), "Completed", "PayPal", $_SERVER['REMOTE_ADDR']), $row2->body); $newbody = cleanOut($body); $mailer = Mailer::sendMail(); $message = Swift_Message::newInstance()->setSubject($row2->subject)->setTo(array($core->site_email => $core->site_name))->setFrom(array($core->site_email => $core->site_name))->setBody($newbody, 'text/html'); $mailer->send($message); pflog("Email Notification sent successfuly"); } } }
/** * * @param string $paymentAction * @param object $stateObject * * @return $this */ public function initialize($paymentAction, $stateObject) { $pre = __METHOD__ . " : "; pflog($pre . 'bof'); $stateObject->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT); $stateObject->setStatus('pending_payment'); $stateObject->setIsNotified(false); return parent::initialize($paymentAction, $stateObject); // TODO: Change the autogenerated stub }
// If transaction is successful and correct, update order status if ($success == true) { $pfNotes[] = PF_MSG_OK; $order->orderStatus(3, $orderId); } } //// Insert transaction entry // This gets done for every ITN call no matter whether successful or not. // The notes field is used to provide feedback to the user. pflog('Create transaction data and save'); $pfNoteMsg = ''; if (sizeof($pfNotes) > 1) { foreach ($pfNotes as $note) { $pfNoteMsg .= $note . "; "; } } else { $pfNoteMsg .= $pfNotes[0]; } $transData = array(); $transData['customer_id'] = $order->orderSum["customer_id"]; $transData['gateway'] = "PayFast ITN"; $transData['trans_id'] = $pfData['pf_payment_id']; $transData['order_id'] = $orderId; $transData['status'] = $pfData['payment_status']; $transData['amount'] = $pfData['amount_gross']; $transData['notes'] = $pfNoteMsg; pflog("Transaction log data: \n" . print_r($transData, true)); $order->storeTrans($transData); // Close log pflog('', true);
/** * pfValidIP * * @author Jonathan Smit * @param $sourceIP String Source IP address */ function pfValidIP($sourceIP) { // Variable initialization $validHosts = array('www.payfast.co.za', 'sandbox.payfast.co.za', 'w1w.payfast.co.za', 'w2w.payfast.co.za'); $validIps = array(); foreach ($validHosts as $pfHostname) { $ips = gethostbynamel($pfHostname); if ($ips !== false) { $validIps = array_merge($validIps, $ips); } } // Remove duplicates $validIps = array_unique($validIps); pflog("Valid IPs:\n" . print_r($validIps, true)); if (in_array($sourceIP, $validIps)) { return true; } else { return false; } }
/** * saveInvoice * * @throws \Magento\Framework\Exception\LocalizedException */ protected function saveInvoice() { pflog('Saving invoice'); // Check for mail msg $invoice = $this->_order->prepareInvoice(); $invoice->register()->capture(); /** @var \Magento\Framework\DB\Transaction $transaction */ $transaction = $this->_transactionFactory->create(); $transaction->addObject($invoice)->addObject($invoice->getOrder())->save(); $this->_order->addStatusHistoryComment(__('Notified customer about invoice #%1.', $invoice->getIncrementId())); $this->_order->setIsCustomerNotified(true); $this->_order->save(); }