public function actionProcessPayout() { $db_ext = new DbExt(); $paypal_client_id = yii::app()->functions->getOptionAdmin('wd_paypal_client_id'); $paypal_client_secret = yii::app()->functions->getOptionAdmin('wd_paypal_client_secret'); $paypal_config = Yii::app()->functions->getPaypalConnectionWithdrawal(); dump($paypal_config); $Paypal = new Paypal($paypal_config); $Paypal->debug = true; $website_title = yii::app()->functions->getOptionAdmin('website_title'); $cron = new CronFunctions(); if ($res = $cron->getPayoutToProcess()) { if (is_array($res) && count($res) >= 1) { foreach ($res as $val) { $withdrawal_id = $val['withdrawal_id']; $api_raw_response = ''; $status_msg = ''; dump($val); switch ($val['payment_method']) { case "paypal": dump("Process paypal"); //if (!empty($paypal_client_id) && !empty($paypal_client_secret)){ if (is_array($paypal_config) && count($paypal_config) >= 1) { if ($val['account'] != "") { $Paypal->params['RECEIVERTYPE'] = "EmailAddress"; $Paypal->params['CURRENCYCODE'] = "USD"; $Paypal->params['EMAILSUBJECT'] = "=You have a payment from " . $website_title; $Paypal->params['L_EMAIL0'] = $val['account']; $Paypal->params['L_AMT0'] = normalPrettyPrice($val['amount']); $Paypal->params['L_UNIQUEID0'] = str_pad($val['withdrawal_id'], 10, "0"); if ($pay_resp = $Paypal->payout()) { dump($pay_resp); if ($pay_resp['ACK'] == "Success") { $status_msg = 'paid'; $api_raw_response = json_encode($pay_resp); } else { $api_raw_response = json_encode($pay_resp); $status_msg = $pay_resp['L_LONGMESSAGE0']; } } else { $status_msg = $Paypal->getError(); } } else { $status_msg = t("Paypal account is empty"); } } else { $status_msg = t("Payout settings for paypal not yet set"); } break; case "bank": $status_msg = 'paid'; break; } echo "<h3>Update status</h3>"; dump($api_raw_response); dump($status_msg); $params_update = array('date_process' => date('c'), 'api_raw_response' => $api_raw_response, 'status' => $status_msg); dump($params_update); if ($db_ext->updateData("{{withdrawal}}", $params_update, 'withdrawal_id', $withdrawal_id)) { echo "<h2>Update ok</h2>"; } else { echo "<h2>Update Failed</h2>"; } if ($status_msg == "paid") { // send email $subject = yii::app()->functions->getOptionAdmin('wd_template_process_subject'); if (empty($subject)) { $subject = t("Your Request for Withdrawal has been Processed"); } if ($merchant_info = Yii::app()->functions->getMerchant($val['merchant_id'])) { $merchant_email = $merchant_info['contact_email']; $tpl = yii::app()->functions->getOptionAdmin('wd_template_process'); $tpl = smarty("merchant-name", $merchant_info['restaurant_name'], $tpl); $tpl = smarty("payout-amount", standardPrettyFormat($val['amount']), $tpl); $tpl = smarty("payment-method", $val['payment_method'], $tpl); $tpl = smarty("acoount", $val['account'], $tpl); dump($tpl); if (!empty($tpl)) { sendEmail($merchant_email, '', $subject, $tpl); } } } } } } else { dump("No record to process"); } }