public function getLastNotPayedTransaction($type) { $payment = Doctrine_Query::create()->from('PaymentTransaction')->where('user_id = ? AND type = ?', array($this->id, '"' . $type . '"'))->andWhere('is_payed = ?', false)->andWhere('date_payed IS NULL')->orderBy('id DESC')->fetchOne(); if (!$payment) { $payment = new PaymentTransaction(); $payment->user_id = $this->id; $payment->type = $type; $payment->save(); } $price_list = PaymentTransaction::getPriceList(); $payment->amount = $price_list[$type]; return $payment; }
public function show($id = null) { $cart = $this->load_cart($id); if (!$cart->paid) { $cart->check_discounts(); $manualGateway = null; $gateways = null; $allGateways = PaymentGateway::find_all('', 'paymentgateways.position ASC'); foreach ($allGateways as $gateway) { $gateways[$gateway->id] = $gateway->name; if ($gateway->code == 'manual') { $manualGateway = $gateway; } } $payment = new PaymentTransaction(); $payment->cart_id = $cart->id; $payment->cart = $cart; $payment->paymentgateway = $manualGateway; $payment->paymentgateway_id = $manualGateway->id; $payment->externalid = (string) $cart; $payment->amount = Money($cart->cost()); $payment->sender = $cart->user->email; $payment->status = 'ptsTaken'; $payment->processResponse = array('notes' => ''); if ($this->post) { $payment->paymentgateway_id = $this->postData('paymentgateway_id'); $payment->externalid = $this->postData('externalid'); $payment->sender = $this->postData('sender'); $payment->amount = $this->postData('amount'); $payment->processResponse = array('notes' => $this->postData('notes')); $payment->method = $gateways[$payment->paymentgateway_id]; if ($payment->save()) { Email::send_user_paymentconfirmation($payment); $cart->mark_paid($payment, 'Manually Paid'); Email::send_payment_complete(array(), "", $cart); Site::Flash('notice', 'The cart has been paid for'); Redirect("admin/carts/{$cart->id}"); } else { Site::InstantFlash('error', 'Invalid payment'); } echo '<pre>'; print_r($payment); die; } $this->assign('payment', $payment); $this->assign('gateways', $gateways); } $this->assign('cart', $cart); $this->title = "Cart :: {$cart->id}"; $this->render('cart/show.tpl'); }
function transactions() { $payment = PaymentTransaction::where('account_id', '=', $this->application_no)->get(); if (!empty($payment)) { return $payment; } return null; }
public function transactions() { $payments = PaymentTransaction::where('account_id', '=', $this->account_id)->get(); if (count($payments) != 0) { return $payments; } return null; }
public function sendSmsPaymentSuccess($params) { $user = User::where('account_id', '=', $this->account_id)->get()->first(); if (!is_null($user)) { $senderId = "OODOOP"; $message = "Your Payment of Rs." . $this->amount . " for Account ID " . $this->account_id . " is Successful.\n Your transaction id is" . $this->transaction_code . " \n for your future reference. Contact support@oodoo.co.in or +91 8940808080 for more info."; $mobileNumber = Config::get('custom_config.mobile'); if (is_null($mobileNumber)) { $mobileNumber = $user->mobile; } $return = PaymentTransaction::sendsms($mobileNumber, $senderId, $message); } }
public function cart_payment() { $id = ""; if ($this->GetData('id')) { $id = $this->GetData('id'); } $user_id = mysql_real_escape_string(Site::CurrentUser()->id); $cart = Cart::find("carts.user_id = {$user_id} AND carts.id = {$id}"); if ($cart->paid) { Site::Flash('error', 'The cart has already been paid'); RedirectBack('bookings'); } $cart->check_discounts(); if ($cart->cost() != 0) { Site::Flash('error', 'This cart still needs to be paid for'); RedirectBack('bookings'); } if ($cart->full_cart_discount()) { $id = mysql_real_escape_string($cart->id); $redemptions = DiscountRedemption::find_all("discount_redemptions.cart_id='{$id}' and discount_redemptions.cart_item_id IS NULL"); } // Log the payment $gateway = PaymentGateway::find_by_code('discount'); $payment = new PaymentTransaction(); $payment->cart_id = $cart->id; $payment->externalid = (string) $redemptions[0]; $payment->paymentgateway_id = $gateway->id; $payment->status = 'ptsTaken'; $payment->amount = $cart->cost() / 100; $payment->sender = Site::CurrentUser()->email; $payment->save(); $cart->mark_paid($payment, 'Discount'); // Email staff about payment Email::send_payment_complete(array(), "", $cart, $redemptions); Redirect("payments/{$id}/complete"); }
public function executePaypalSet(sfWebRequest $request) { $payment_type = $request->getParameter('payment_type'); $price_list = PaymentTransaction::getPriceList(); $payPalURL = ''; if (array_key_exists($payment_type, $price_list)) { /** @var sfGuardUser $user */ $user = $this->getUser()->getGuardUser(); $user->getLastNotPayedTransaction($payment_type); $gtw = new PaypalGateway(array('payer_id' => $user->id, 'amount' => $price_list[$payment_type], 'success_url' => $this->generateUrl('payment\\success', array('type' => $payment_type), true), 'cancel_url' => $this->generateUrl('payment\\cancel', array(), true))); $payPalURL = $gtw->setExpessCheckout(); } if ($payPalURL) { $this->redirect($payPalURL); } else { $this->getUser()->setFlash('error', 'PayPal connection error'); $this->redirect('/project/user/account'); } }
public function show($id = null) { if (isset($_GET['id'])) { $id = $_GET['id']; } if (!$id) { Error404(); } $payment = PaymentTransaction::find_by_id($id); if (!$payment) { Error404(); } $cart = Cart::find_by_id($payment->cart_id); if ($cart) { $user = User::find_by_id($cart->user_id); $this->assign("user", $user); $this->assign("cart", $cart); } $this->assign("payment", $payment); $this->title = "Payment {$payment->id}"; $this->render("paymenttransaction/show.tpl"); }
public function transactions($reload = false) { if (!$this->transactions_cache or $reload) { $id = mysql_real_escape_string($this->id); $this->transactions_cache = PaymentTransaction::find_all("paymenttransactions.cart_id = '{$id}'"); } return $this->transactions_cache; }
/** * @param int $status * @param PaymentTransaction $transaction * @throws CException */ public function changeTransactionStatus($status, PaymentTransaction $transaction) { if (!$transaction->changeStatus($status)) { throw new CException(sprintf('Failed to change payment transaction status to %d.', $status)); } PaymentLog::create(array('transactionId' => $transaction->id, 'transactionStatus' => $transaction->status)); }
public function replyMessage() { $client = $this->getClient(); $service = new Google_Service_Gmail($client); $userId = 'me'; $thread_id = Input::get('thread_id'); $assign_to = Input::get('assign_to'); $employee = Employee::where('employee_identity', $assign_to)->get()->first(); $employee_name = $employee->name; $employee_mobile = $employee->mobile; DB::table('create_mail_table')->insert(['thread_id' => $thread_id, 'label' => 'ASSIGN', 'body' => '' . Auth::employee()->get()->name . ' assigned the complaint to ' . $employee_name . '', 'from_mail' => Auth::employee()->get()->name, 'time' => Date("Y-m-d H:i:s")]); $ticket_no = TicketSupport::where('thread_id', $thread_id)->get()->first(); if (!$ticket_no) { $ticket_no = $this->generateTicketNo(); $ticketMail = new TicketSupport(); $ticketMail->thread_id = $thread_id; $ticketMail->ticket_no = $ticket_no; $ticketMail->status = 'open'; $ticketMail->assign_to = $assign_to; $ticketMail->save(); } else { $ticket_no = $ticket_no->ticket_no; } $senderDet = MailSupport::where('thread_id', $thread_id)->orderBy('time', 'ASC')->get()->first(); $from = $senderDet->to_mail; $to = $senderDet->from_mail; $subject = $senderDet->subject; $content = Input::get('body'); $body = 'Hi ' . $from . '\\n Ticket No : ' . $ticket_no . '\\n\\n' . $content . '\\n\\nSincerely\\n' . Auth::employee()->get()->name . '\\nOODOO Support team.'; $message = new Google_Service_Gmail_Message(); $text = 'From: ' . $from . ' To: ' . $to . ' Subject: Re: ' . $subject . ' ' . $body . ''; $encoded_message = rtrim(strtr(base64_encode($text), '+/', '-_'), '='); $message->setRaw($encoded_message); $message = $service->users_messages->send($userId, $message); $thread = $message->setThreadId($thread_id); #var_dump($message); die; $senderId = "OODOOS"; $content = 'compilant ' . 'Ticket No ' . $ticket_no; $return = PaymentTransaction::sendsms($employee_mobile, $senderId, $content); $inboxmail = new MailSupport(); $inboxmail->message_id = $message->getId(); $inboxmail->thread_id = $thread_id; $inboxmail->history_id = 1111; $inboxmail->label = 'SENT'; $inboxmail->subject = $subject; $inboxmail->from_mail = $from; $inboxmail->to_mail = $to; $inboxmail->body = $body; if (isset($attachment)) { $inboxmail->attachment = json_encode($attachment); } $time = Date("Y-m-d H:i:s"); $inboxmail->time = $time; if ($inboxmail->save()) { return Response::json(array('from' => $from, 'body' => $body, 'time' => $time, 'assign_to' => $assign_to)); } else { return Response::json(array('mail' => "false")); } }
public static function callInterswitch($ref, &$json) { //$ref = $_POST['txnref']; $order = Order::model()->findByAttributes(array('payment_code' => $ref)); $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $ref)); $url = UtilityHelper::yiiparam('interswitchGet') . '?productid=' . UtilityHelper::yiiparam('interswitchProductID') . '&transactionreference=' . $ref . '&amount=' . $order->total * 100; //self::sendToLog($url); try { $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPGET, true); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Hash: ' . hash('sha512', UtilityHelper::yiiparam('interswitchProductID') . $ref . UtilityHelper::yiiparam('MAC_key')))); $result = curl_exec($cURL); if (FALSE === $result) { throw new Exception(curl_error($cURL), curl_errno($cURL)); } //self::sendToLog($result,"Json things!!!"); curl_close($cURL); } catch (Exception $e) { self::sendToLog(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), "CURL Interswitch Error"); return false; } $json = json_decode($result, true); //$pay->transaction_date = $json['TransactionDate']; //$pay->reference_number = $ref; $pay->payment_reference = $json['PaymentReference']; $pay->response_description = $json['ResponseDescription']; $pay->response_code = $json['ResponseCode']; $pay->approved_amount = $json['Amount'] / 100; //$pay->customer_name = ; $pay->save(); $json['CustomerName'] = $pay->customer_name; $total = UtilityHelper::formatPrice($order->total); $siteurl = UtilityHelper::yiiparam('siteUrl'); if (empty($order->check)) { $messg = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Amount: {$total}<br/><br/>Response Description: {$json['ResponseDescription']}<br/><br/>Response Code: {$json['ResponseCode']}<br/><br/>Transaction Ref No: {$ref}<br/><br/>Payment Reference: {$json['PaymentReference']}<br/><br/>Transaction Date: {$json['TransactionDate']}<br/>"; if ($json['ResponseCode'] == '09') { } else { if ($json['ResponseCode'] == '00') { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $messg); //UtilityHelper::changeOrderStatus($order->id); $order->order_status_id = 2; $order->check = 1; $order->save(); UtilityHelper::subtractOrder($order->id); } else { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $messg); //UtilityHelper::changeOrderStatus($order->id,10); $order->order_status_id = 10; $order->check = 1; $order->save(); } } } //return $order; }
public static function _processPayment($gateway, $postData) { // Process according to SagePay $paymentTransaction = null; if (isset($_POST['VendorTxCode'])) { $paymentTransaction = PaymentTransaction::find_by_id($postData['VendorTxCode']); } if (!$paymentTransaction) { throw new PGI_SagePay_ProcessException('Unable to find a payment matching ' . $postData['VendorTxCode']); } if ($paymentTransaction->status == 'ptsTaken') { $params = array('Status' => 'OK', 'StatusDetail' => "Payment for {$paymentTransaction->cart}", 'RedirectURL' => "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->cart->id}/complete"); $output = ''; foreach ($params as $key => $value) { $output .= "{$key}={$value}\r\n"; } return $output; } if ($paymentTransaction->status != 'ptsSubmitted') { throw new PGI_SagePay_ProcessException("{$paymentTransaction} is in state {$paymentTransaction->status}", $paymentTransaction, $notify); } // Validate response if (!isset($postData['VPSTxId'])) { throw new PGI_SagePay_ProcessException('No transaction ID from SagePay'); } if ($paymentTransaction->externalid != $postData['VPSTxId']) { throw new PGI_SagePay_ProcessException("{$postData['VPSTxId']} does not match the transaction ID in " . $paymentTransaction, $paymentTransaction); } $fields = array('VPSTxId', 'VendorTxCode', 'Status', 'TxAuthNo', 'VendorName', 'AVSCV2', 'SecurityKey', 'AddressResult', 'PostCodeResult', 'CV2Result', 'GiftAid', '3DSecureStatus', 'CAVV', 'AddressStatus', 'PayerStatus', 'CardType', 'Last4Digits', 'DeclineCode', 'ExpiryDate', 'FraudResponse', 'BankAuthCode'); $sig = ''; foreach ($fields as $name) { switch ($name) { case 'SecurityKey': $sig .= $paymentTransaction->initialResponse->SecurityKey; break; case 'VendorName': $sig .= $gateway->getSetting('vendor'); break; default: $sig .= $postData[$name]; break; } } $sig = strtoupper(md5($sig)); if ($sig != $postData['VPSSignature']) { throw new PGI_SagePay_ProcessException("Signatures do not match, found {$sig}, expecting {$postData['VPSSignature']}", $paymentTransaction); } $url = "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->id}/failed"; $paymentTransaction->processResponse = $postData; // Determine our correct response switch ($postData['Status']) { case 'OK': $url = "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->cart->id}/complete"; $cart = Cart::find_by_id($paymentTransaction->cart->id); $paymentTransaction->status = 'ptsTaken'; if ($postData['CardType'] == 'PAYPAL') { $paymentTransaction->method = 'PayPal'; } else { $cardName = 'Credit Card'; $lookup = array('VISA' => 'Visa', 'DELTA' => 'Visa Debit', 'UKE' => 'Visa Electron', 'MC' => 'Mastercard', 'SWITCH' => 'UK Maestro', 'MAESTRO' => 'Maestro', 'AMEX' => 'American Express', 'DINERS' => 'Diners Club', 'JCB' => 'JCB', 'LASER' => 'LASER', 'PAYPAL' => 'PayPal'); if (isset($lookup[$postData['CardType']])) { $cardName = $lookup[$postData['CardType']]; } $paymentTransaction->method = "{$cardName} (Ending in {$postData['Last4Digits']})"; } $paymentTransaction->save(); Email::send_user_paymentconfirmation($paymentTransaction); // Mark cart as paid, this will trigger the event signup // email to the user. $cart->mark_paid(null, "SagePay"); // Email staff about payment Email::send_payment_complete($postData, $postData['Status'], $cart); // And alert on Twitter $account = TwitterAccount::find_by_code('site'); if ($account) { $signups = $cart->get_signups(); $eventsignups = array(); foreach ($signups as $signup) { $amount = sprintf("%.2f", $signup->event_ticket->cost / 100); $paidsignups = count($signup->event->participants("paid")); $message = "{$signup->user->nickname} has paid for {$signup->event->name} {$signup->event_ticket->name} [£{$amount}] ({$paidsignups}/{$signup->event->capacity}) [{$signup->id}]"; $account->add_tweet($message); } } break; case 'ABORT': $paymentTransaction->status = 'ptsCancelled'; $paymentTransaction->failurereason = $postData['StatusDetail']; break; default: $paymentTransaction->status = 'ptsFailed'; $paymentTransaction->failurereason = $postData['StatusDetail']; break; } $paymentTransaction->save(); $params = array('Status' => 'OK', 'StatusDetail' => "Payment for {$paymentTransaction->cart}", 'RedirectURL' => $url); $output = ''; foreach ($params as $key => $value) { $output .= "{$key}={$value}\r\n"; } return $output; }
public static function billChange($bill_no, $new_plan_code, $trans) { $bill = Bill::where('bill_no', $bill_no)->first(); if (count($bill) != 0) { $plan_cost_det = PlanCostDetail::where('plan_code', '=', $new_plan_code)->get()->first(); $account_id = $bill->account_id; if ($trans) { $cust_current_plan = $bill->cust_current_plan; $current_rental = $trans; } else { $cust_current_plan = $plan_cost_det->plan; $current_rental = $plan_cost_det->monthly_rental; } $bill_date = $bill->bill_date; $bill_start_date = $bill->bill_start_date; $bill_end_date = $bill->bill_end_date; $due_date = $bill->due_date; $for_month = $bill->for_month; $bill_last = Bill::where('account_id', '=', $account_id)->where('bill_no', '<', $bill_no)->orderBy('bill_no', 'desc')->first(); if ($bill_last) { $prev_bal = $bill_last->amount_before_due_date; $last_payment = $bill_last->amount_paid; } else { $prev_bal = 0; $last_payment = 0; } $security_deposit = $bill->security_deposit; if (0 < $bill->adjustments) { $adjustments = PlanChangeDetail::billadjustment($account_id, $for_month, $bill->adjustments, $bill); if ($adjustments == false) { $value = array('status' => 'false', 'name' => "adjustment"); return $value; } } else { $adjustments = $bill->adjustments; } if ($trans) { if (0 < $bill->device_cost) { $device_cost = PlanChangeDetail::billdevicecost($account_id, $for_month, $bill->device_cost, $bill); if ($device_cost == false) { $value = array('status' => 'false', 'name' => "devicecost"); return $value; } } else { $device_cost = $bill->device_cost; } if (0 < $bill->discount) { $discount = PlanChangeDetail::billdiscount($account_id, $for_month, $bill->discount, $bill); if ($discount == false) { $value = array('status' => 'false', 'name' => "discount"); return $value; } } else { $discount = $bill->discount; } if (0 < $bill->other_charges) { $othercharges = PlanChangeDetail::billothercharges($account_id, $for_month, $bill->other_charges, $bill); if ($othercharges == false) { $value = array('status' => 'false', 'name' => "othercharges"); return $value; } } else { $othercharges = $bill->other_charges; } } else { $device_cost = $bill->device_cost; $discount = $bill->discount; $othercharges = $bill->other_charges; $adjustments = $bill->adjustments; } $onetime_charges = $bill->onetime_charges; if ($bill->onetime_charges) { $sub_total = $current_rental + $othercharges + $device_cost - $discount + $onetime_charges; } else { $sub_total = $current_rental + $othercharges + $device_cost - $discount; } $service_tax = ceil($sub_total * 0.14); $total_charges = $sub_total + $service_tax; $amount_before_due_date = intval($prev_bal - $last_payment + ($total_charges - $adjustments)); $amount_after_due_date = intval($prev_bal - $last_payment + ($total_charges - $adjustments)); $amount_paid = PaymentTransaction::where('bill_no', $bill->bill_no)->where('status', 'success')->sum('amount'); if ($amount_before_due_date <= $amount_paid) { $status = "paid"; } else { if ($amount_paid == 0) { $status = "not_paid"; } else { if ($amount_before_due_date > $amount_paid) { $status = "partially_paid"; } } } DB::table('bill_det')->where('bill_no', '=', $bill->bill_no)->update(array('account_id' => $account_id, 'cust_current_plan' => $cust_current_plan, 'bill_date' => $bill_date, 'bill_start_date' => $bill_start_date, 'bill_end_date' => $bill_end_date, 'due_date' => $due_date, 'security_deposit' => $security_deposit, 'prev_bal' => $prev_bal, 'last_payment' => $last_payment, 'current_rental' => $current_rental, 'onetime_charges' => $onetime_charges, 'sub_total' => $sub_total, 'service_tax' => $service_tax, 'total_charges' => $total_charges, 'for_month' => $for_month, 'device_cost' => $device_cost, 'adjustments' => $adjustments, 'discount' => $discount, 'other_charges' => $othercharges, 'amount_before_due_date' => $amount_before_due_date, 'amount_after_due_date' => $amount_after_due_date, 'amount_paid' => $amount_paid, 'status' => $status)); return DB::table('bill_det')->where('bill_no', '=', $bill->bill_no)->first(); } }
public static function billUpdate($id, $account_id, $for_month, $adjustments_new, $device_cost_new, $discount_new, $other_charges_new, $for_month_last, $update) { if (count($for_month_last) != 0) { $bill = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month_last)->get()->first(); } else { $bill = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month)->get()->first(); } // var_dump($bill,$for_month,$account_id);die; if (count($bill) != 0) { $bill_now = Bill::where('account_id', '=', $account_id)->where('for_month', $for_month)->first(); if ($for_month_last) { $previous_balance = ceil($bill->amount_before_due_date); $last_payment = ceil($bill->amount_paid); } else { $previous_balance = ceil($bill->prev_bal); $last_payment = ceil($bill->last_payment); } $amount_paid = PaymentTransaction::where('bill_no', $bill_now->bill_no)->where('account_id', $account_id)->where('status', 'success')->sum('amount'); $account_id = $bill->account_id; $bill_date = $bill->bill_date; $bill_start_date = $bill->bill_start_date; $bill_end_date = $bill->bill_end_date; $due_date = $bill->due_date; $security_deposit = $bill->security_deposit; $status = $bill->status; if (count($update) != 0) { $adjust = Adjustment::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount'); $device = DeviceCost::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount'); $other_c = OtherCharges::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount'); $discount = Discount::where('account_id', '=', $account_id)->where('for_month', $for_month)->where('id', '!=', $id)->sum('amount'); $device_cost = $device + $device_cost_new; $other_charges = $other_c + $other_charges_new; $discount = $discount + $discount_new; $adjustments = $adjust + $adjustments_new; } else { $device_cost = $bill->device_cost + $device_cost_new; $other_charges = $bill->other_charges + $other_charges_new; $discount = $bill->discount + $discount_new; $adjustments = $bill->adjustments + $adjustments_new; } if (count($adjustments_new) != 0) { $adjustment_update = Adjustment::where('id', $id)->first(); $adjustment_update->is_considered = 'Y'; $adjustment_update->save(); } if (count($device_cost_new) != 0) { $device_cost_update = DeviceCost::where('id', $id)->first(); $device_cost_update->is_considered = 1; $device_cost_update->save(); } if (count($other_charges_new) != 0) { $other_charges_update = OtherCharges::where('id', $id)->first(); $other_charges_update->is_considered = 1; $other_charges_update->save(); } if (count($discount_new) != 0) { $discount_update = Discount::where('id', $id)->first(); $discount_update->is_considered = 1; $discount_update->save(); } $bill_count = Bill::where('account_id', $account_id)->get(); if ($for_month_last) { if (count($bill_count) == 1) { $current_rental = $bill->current_rental; $onetime_charges = $bill->onetime_charges; $sub_total = $current_rental; $service_tax = ceil($sub_total * 0.14); $plan_name = $bill->cust_current_plan; $total_charges = ceil($sub_total + $service_tax); $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost + $onetime_charges); } else { $current_rental = $bill_now->current_rental; $sub_total = $current_rental; $onetime_charges = $bill_now->onetime_charges; $service_tax = ceil($sub_total * 0.14); $plan_name = $bill_now->cust_current_plan; $total_charges = ceil($sub_total + $service_tax); $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost); } } else { $current_rental = $bill_now->current_rental; $onetime_charges = $bill_now->onetime_charges; $sub_total = $current_rental; $service_tax = ceil($sub_total * 0.14); $total_charges = ceil($sub_total + $service_tax); $plan_name = $bill_now->cust_current_plan; if (count($bill_count) == 1) { $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost + $onetime_charges); } else { $total_amount = ceil($sub_total + $service_tax - $adjustments + $other_charges - $discount + $device_cost); } } $amount_before_due_date = intval($previous_balance - $last_payment + $total_amount); $amount_after_due_date = intval($previous_balance - $last_payment + $total_amount); if ($amount_paid == 0) { $status = "not_paid"; } else { if ($amount_before_due_date > $amount_paid) { $status = "partially_paid"; } else { if ($amount_before_due_date <= $amount_paid) { $status = "paid"; } } } DB::table('bill_det')->where('bill_no', '=', $bill_now->bill_no)->update(array('prev_bal' => $previous_balance, 'last_payment' => $last_payment, 'current_rental' => $current_rental, 'service_tax' => $service_tax, 'total_charges' => $total_charges, 'sub_total' => $sub_total, 'device_cost' => $device_cost, 'adjustments' => $adjustments, 'discount' => $discount, 'other_charges' => $other_charges, 'amount_before_due_date' => $amount_before_due_date, 'amount_after_due_date' => $amount_after_due_date, 'amount_paid' => $amount_paid, 'status' => $status)); } }
public function destroy() { $this->deleted = true; if (!$this->id) { return; } $id = mysql_real_escape_string($this->id); $count = PaymentTransaction::count("paymentgateways.id = '{$id}'"); if ($count > 0) { throw new Excpetion('Unable to delete payment gateway, there are transactions that are using it'); } mysql_query("UPDATE `paymentgateways` SET `deleted` = true WHERE `id` = '{$id}' LIMIT 1;"); }
/** * Creates a new payment transaction. * @param array $attributes * @return PaymentTransaction * @throws CException */ public static function create(array $attributes) { $model = new PaymentTransaction(); $model->attributes = $attributes; $model->userIdentifier = isset($attributes['userIdentifier']) ? $attributes['userIdentifier'] : Yii::app()->user->id; $model->locale = isset($attributes['locale']) ? $attributes['locale'] : Yii::app()->language; if (!$model->save()) { throw new CException('Failed to save payment transaction.'); } return $model; }
<?php ini_set('display_errors', 1); error_reporting(E_ALL & ~E_STRICT); require_once 'init.php'; /* $services = array( (object) array( 'name' => 'My Service' ), (object) array( 'name' => 'Another Thing' ) ); $payment = PaymentTransaction::find_by_id(3059); $data = (array) $payment->processResponse; Email::send_topup_complete($data, 'IPN OK'); die(); */ $ids = array(3279, 3278, 3277, 3276); foreach ($ids as $id) { $payment = PaymentTransaction::find_by_id($id); $data = (array) $payment->processResponse; Email::send_payment_complete($data, $data['Status'], $payment->cart); }
public static function callGlobalPay($txnref, &$trans) { //$txnref = $_GET["txnref"]; $client = new SoapClient('https://www.globalpay.com.ng/globalpaywebservice/service.asmx?wsdl', array('exceptions' => 0, 'encoding' => 'UTF-8')); $soapaction = "https://www.eazypaynigeria.com/globalpay/getTransactions"; $namespace = "https://www.eazypaynigeria.com/globalpay/"; $order = Order::model()->findByAttributes(array('payment_code' => $txnref)); $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $txnref)); $merch_txnref = $txnref; $channel = ""; //change the merchantid to the one sent to you $merchantID = "174"; $start_date = ""; $end_date = ""; //change the uid and pwd to the one sent to you $uid = "yl_ws_user"; $pwd = "yl_ws_password"; $payment_status = ""; /* $err = $client->getError(); if ($err) { $this->render('view2',array('response'=>$err, 'error'=>1)); }*/ // Doc/lit parameters get wrapped $MethodToCall = "getTransactions"; //$MethodToCall= "Checkcenter"; $param = array('merch_txnref' => $merch_txnref, 'channel' => $channel, 'merchantID' => $merchantID, 'start_date' => $start_date, 'end_date' => $end_date, 'uid' => $uid, 'pwd' => $pwd, 'payment_status' => $payment_status); $result = $client->__soapCall($MethodToCall, array('parameters' => $param), array('uri' => $namespace, 'soapaction' => $soapaction)); // Check for a fault if (is_soap_fault($result)) { //"SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})"; return false; } else { //This gives getTransactionsResult $WebResult = $MethodToCall . "Result"; // Pass the result into XML if (is_object($result)) { $xresult = $result->{$WebResult}; } else { $xresult = $result[$WebResult]; } $xml = simplexml_load_string($xresult); //self::sendToLog($xml); //$trans = array(); $trans['amount'] = $xml->record->amount; $trans['txn_date'] = $xml->record->payment_date; $trans['pmt_method'] = $xml->record->channel; $trans['pmt_status'] = $xml->record->payment_status; $trans['pmt_txnref'] = $xml->record->txnref; $trans['currency'] = $xml->record->field_values->field_values->field[2]->currency; // $pnr = 'PNR'; $trans['trans_status'] = $xml->record->payment_status_description; $trans['merch_name'] = $pay->customer_name; $trans['merch_phoneno'] = $order->telephone; $trans['merch_amt'] = $pay->transaction_amount; //$pay = new PaymentTransaction; $pay->transaction_date = $trans['txn_date']; //$pay->reference_number = ; $pay->payment_reference = $trans['pmt_txnref']; if ($trans['amount'] != $trans['merch_amt']) { $trans['pmt_status'] .= " ( Amount does not match and no service will be rendered)"; $pay->response_code = $trans['pmt_status']; } else { $pay->response_code = $trans['pmt_status']; } $pay->response_description = $trans['trans_status']; $pay->approved_amount = $trans['amount']; //$pay->transaction_amount = $trans['merch_amt']; $pay->transaction_currency = $trans['currency']; //$pay->customer_name = $trans['merch_name']; $pay->save(); if (empty($order->check)) { $message = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Name : {$order->firstname} {$order->lastname} <br/><br/>Phone number : {$order->telephone} <br/><br/>Amount : " . UtilityHelper::formatPrice($trans['amount']) . " <br/><br/>Transaction Date : {$trans['txn_date']} <br/><br/>Payment Method : {$trans['pmt_method']} <br/><br/>Payment Status : {$pay->response_code} <br/><br/>Transaction Reference Number : {$trans['pmt_txnref']} <br/><br/>Currency : {$trans['currency']} <br/><br/>Transaction Status : {$trans['trans_status']} <br/><br/>"; if ($trans['pmt_status'] == 'successful' && $trans['amount'] == $trans['merch_amt']) { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $message); //UtilityHelper::changeOrderStatus($order->id); $order->order_status_id = 2; $order->check = 1; $order->save(); UtilityHelper::subtractOrder($order->id); } else { if ($trans['pmt_status'] == 'pending') { } else { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $message); //UtilityHelper::changeOrderStatus($order->id,10); $order->order_status_id = 10; $order->check = 1; $order->save(); } } } return $order; } return false; }
<?php require_once 'init.php'; ini_set('display_errors', 1); //1826 $transaction = PaymentTransaction::find_by_id(1); Email::send_user_paymentconfirmation($transaction);
protected function completePaymentTransaction($response) { $order = Order::model()->findByAttributes(array('payment_code' => $response['invoice'])); $pay = PaymentTransaction::model()->findByAttributes(array('reference_number' => $response['invoice'])); $pay->query_code = $response['process_code']; $pay->response_description = $response['message']; $pay->response_code = $response['status']; $pay->approved_amount = $response['total']; $pay->save(); $total = UtilityHelper::formatPrice($order->total); $siteurl = UtilityHelper::yiiparam('siteUrl'); if (empty($order->check)) { $messg = "Dear {$order->firstname} {$order->lastname},<br/><br/>You have just attempted making payment for order #{$order->id} on {$order->store_url}. Find the details below.<br/><br/>Amount: {$total}<br/><br/>Response Description: {$response['message']}<br/><br/>Response Code: {$response['process_code']}<br/><br/>Transaction Ref No: {$response['invoice']}<br/><br/>Payment Reference: {$response['transaction_id']}<br/><br/>Transaction Date: " . date("D/M/Y") . "<br/>"; } else { if ($response['status'] == 'SUCCESS') { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Successful Payment Notification', $messg); $order->order_status_id = 2; $order->check = 1; $order->save(); UtilityHelper::subtractOrder($order->id); } else { UtilityHelper::sendMail(UtilityHelper::yiiparam('salesEmail'), $order->email, 'Failed Payment Notification', $messg); $order->order_status_id = 10; $order->check = 1; $order->save(); } } $this->logResults($response['status']); }
/** * Processes an IPN request. * * @param type $postData HTTP POST data from the request * @return string Any output for the notification page */ public static function processPayment($gateway, $postData) { $responseData = array_merge(array('cmd' => '_notify-validate'), $postData); $qs = http_build_query($responseData); $curl = curl_init($gateway->getSetting('endpoint')); global $config; if ($config['dev'] or true) { // Paypal sandbox certificate is apparently invalid curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); } curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $qs); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); if (!isset($postData['transaction_subject'])) { // No transaction subject } $ref = explode("-", $postData['custom']); if (count($ref) < 2) { return; } $type = $ref[0]; $id = $ref[1]; if ($type != 'cart') { // Not a cart, nothing to do here return; } $id = mysql_real_escape_string($id); $cart = Cart::find_by_id($id); $payment = new PaymentTransaction(); $payment->processResponse = $postData; $payment->paymentgateway_id = $gateway->id; $payment->amount = $postData['mc_gross']; $payment->externalid = $postData['txn_id']; $payment->status = 'ptsFailed'; $payment->sender = $postData['payer_email']; $payment->method = "PayPal ({$postData['payer_email']})"; if (!$cart) { // Cart not found $payment->failurereason = "Transaction specified a cart, but the cart was not found"; $payment->save(); Email::send_payment_alert($postData, $payment->failurereason, $response); return; } $cart->check_discounts(); // Make Payment Object $payment->cart_id = $cart->id; if ($response != 'VERIFIED') { // IPN response is not verified $payment->failurereason = "The transaction was not verified"; $payment->save(); Email::send_payment_alert($postData, $payment->failurereason, $response, $cart); return; } if ($postData['payment_status'] != "Completed") { // Payment status is not completed $payment->failurereason = "Payment status is not completed"; $payment->save(); Email::send_payment_alert($postData, $payment->failurereason, $response, $cart); return; } if ($postData['receiver_email'] != $gateway->getSetting('email')) { // Sent to the wrong email $payment->failurereason = "Payment was sent to a different email address"; $payment->save(); Email::send_payment_alert($postData, $payment->failurereason, $response, $cart); return; } $total = $cart->cost() + $cart->card_fee(); if ($postData['mc_gross'] * 100 < $total) { // Cart is not enough $payment->failurereason = "Payment was not enough for the cart"; $payment->save(); Email::send_payment_alert($postData, $payment->failurereason, $response, $cart); return; } if ($cart->paid) { // Cart is already marked paid $payment->failurereason = "The cart has already been paid for"; $payment->save(); Email::send_payment_alert($postData, $payment->failurereason, $response, $cart); return; } // Payment is valid and for the right amount for our cart! $payment->status = 'ptsTaken'; $payment->save(); Email::send_user_paymentconfirmation($payment); // Mark cart as paid, this will trigger the event signup // email to the user. $cart->mark_paid($payment, "Paypal"); // Email staff about payment Email::send_payment_complete($postData, $response, $cart); // And alert on Twitter $account = TwitterAccount::find_by_code('site'); if ($account) { $signups = $cart->get_signups(); $eventsignups = array(); foreach ($signups as $signup) { $amount = sprintf("%.2f", $signup->event_ticket->cost / 100); $paidsignups = count($signup->event->participants("paid")); $message = "{$signup->user->nickname} has paid for {$signup->event->name} {$signup->event_ticket->name} [£{$amount}] ({$paidsignups}/{$signup->event->capacity}) [{$signup->id}]"; $account->add_tweet($message); } } }
case 'Denied': $status = 'ptsFailed'; break; default: $status = 'ptsCancelled'; break; } $method = $gateway->name; if ($gateway->code == 'paypal') { $method = "PayPal ({$payment->sender})"; } $response = array('notes' => $payment->extra); if ($payment->method == 'Paypal') { $response = unserialize($payment->extra); } $t = new PaymentTransaction(); $t->cart_id = $payment->cart_id; $t->paymentgateway_id = $gateway->id; $t->status = $status; $t->failurereason = ''; $t->amount = $payment->amount; if (!$t->amount) { $t->amount = 0; } $t->externalid = $payment->transaction_id; $t->processResponse = $response; $t->sender = $payment->sender; $t->method = $method; $result = $t->save(); if ($result) { $newID = mysql_real_escape_string($t->id);