public function index() { $billingService = BOL_BillingService::getInstance(); $language = OW::getLanguage(); $paypalConfigForm = new PaypalConfigForm(); $this->addForm($paypalConfigForm); if (OW::getRequest()->isPost() && $paypalConfigForm->isValid($_POST)) { $res = $paypalConfigForm->process(); OW::getFeedback()->info($language->text('billingpaypal', 'settings_updated')); $this->redirect(); } $adapter = new BILLINGPAYPAL_CLASS_PaypalAdapter(); $this->assign('logoUrl', $adapter->getLogoUrl()); $gateway = $billingService->findGatewayByKey(BILLINGPAYPAL_CLASS_PaypalAdapter::GATEWAY_KEY); $this->assign('gateway', $gateway); $this->assign('activeCurrency', $billingService->getActiveCurrency()); $supported = $billingService->currencyIsSupported($gateway->currencies); $this->assign('currSupported', $supported); $this->setPageHeading(OW::getLanguage()->text('billingpaypal', 'config_page_heading')); $this->setPageHeadingIconClass('ow_ic_app'); }
public function notify() { $logger = OW::getLogger('billingpaypal'); $logger->addEntry(print_r($_POST, true), 'ipn.data-array'); $logger->writeLog(); if (empty($_POST['custom'])) { exit; } $hash = trim($_POST['custom']); $amount = !empty($_POST['mc_gross']) ? $_POST['mc_gross'] : $_POST['payment_gross']; $transactionId = trim($_POST['txn_id']); $status = mb_strtoupper(trim($_POST['payment_status'])); $currency = trim($_POST['mc_currency']); $transactionType = trim($_POST['txn_type']); $business = trim($_POST['business']); $billingService = BOL_BillingService::getInstance(); $adapter = new BILLINGPAYPAL_CLASS_PaypalAdapter(); if ($adapter->isVerified($_POST)) { $sale = $billingService->getSaleByHash($hash); if (!$sale || !strlen($transactionId)) { exit; } if ($amount != $sale->totalAmount) { $logger->addEntry("Wrong amount: " . $amount, 'notify.amount-mismatch'); $logger->writeLog(); exit; } if ($billingService->getGatewayConfigValue(BILLINGPAYPAL_CLASS_PaypalAdapter::GATEWAY_KEY, 'business') != $business) { $logger->addEntry("Wrong PayPal account: " . $business, 'notify.account-mismatch'); $logger->writeLog(); exit; } if ($status == 'COMPLETED') { switch ($transactionType) { case 'web_accept': case 'subscr_payment': if (!$billingService->saleDelivered($transactionId, $sale->gatewayId)) { $sale->transactionUid = $transactionId; if ($billingService->verifySale($adapter, $sale)) { $sale = $billingService->getSaleById($sale->id); $productAdapter = $billingService->getProductAdapter($sale->entityKey); if ($productAdapter) { $billingService->deliverSale($productAdapter, $sale); } } } break; case 'recurring_payment': $rebillTransId = $_REQUEST['recurring_payment_id']; $gateway = $billingService->findGatewayByKey(BILLINGPAYPAL_CLASS_PaypalAdapter::GATEWAY_KEY); if ($billingService->saleDelivered($rebillTransId, $gateway->id)) { exit; } $rebillSaleId = $billingService->registerRebillSale($adapter, $sale, $rebillTransId); if ($rebillSaleId) { $rebillSale = $billingService->getSaleById($rebillSaleId); $productAdapter = $billingService->getProductAdapter($rebillSale->entityKey); if ($productAdapter) { $billingService->deliverSale($productAdapter, $rebillSale); } } break; } } } else { exit; } }