public function sendPayment()
 {
     $data = array();
     //        if ($x = Booking::find(Booking::max('id'))) {
     //            $data['reference_number'] = ++$x->reference_number;
     //        } else {
     //            $data['reference_number'] = 10000000;
     //        }
     //        $reference_number = $data['reference_number'];
     $data = array('details' => 'thilina', 'ip_address' => $_SERVER['REMOTE_ADDR'], 'amount' => 0.1, 'payment_status' => 0, 'my_booking' => 2);
     $reserv_id = Payment::create($data);
     $data_tab_HSBC_payment = array('currency' => 'USD');
     $tab_HSBC_payment_id = HsbcPayment::create($data_tab_HSBC_payment);
     $stamp = strtotime("now");
     $payment_id = Payment::orderBy('created_at', 'desc')->first()->id;
     $orderid = "{$stamp}" . 'B' . "{$payment_id}";
     $last_res_resid = str_replace(".", "", $orderid);
     $hsbc_id = HsbcPayment::orderBy('created_at', 'desc')->first()->id;
     $hsbc_payment_id_pre = "{$stamp}" . 'HSBC' . "{$hsbc_id}";
     $hsbc_payment_id = str_replace(".", "", $hsbc_payment_id_pre);
     if ($last_res_resid) {
         $payment = DB::table('payments')->where('id', $payment_id)->update(array('reference_number' => $last_res_resid, 'HSBC_payment_id' => $hsbc_payment_id));
         $data_tab_HSBC_payment = DB::table('hsbc_payments')->where('id', $hsbc_id)->update(array('HSBC_payment_id' => $hsbc_payment_id));
     }
     $amount = Input::get('amount');
     Session::put('payment_amount', $amount);
     // $hsbc_payment_id = 1000;
     $currency = 'USD';
     $total_price_all_hsbc = 0.1 * 100;
     // $last_res_resid = 101;
     //dd($hsbc_payment_id.'/'.$currency.'/'.$total_price_all_hsbc.'/'.$last_res_resid);
     HsbcPayment::goto_hsbc_gateway($hsbc_payment_id, $currency, $total_price_all_hsbc, $last_res_resid);
 }
Exemplo n.º 2
0
 /**
  * Store a newly created payment in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Payment::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if (Input::hasFile('attachment')) {
         $no = Payment::max('id') + 1;
         $noinvoice = 'AT' . date('Ymd') . $no;
         $uploaded_file = Input::file('attachment');
         $extension = $uploaded_file->getClientOriginalExtension();
         $filename = Sentry::getUser()->first_name . '.' . $extension;
         $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'uploads/payments';
         $uploaded_file->move($destinationPath, $filename);
         // 25
         $data['noinvoice'] = $noinvoice;
         $data['attachment'] = $filename;
         $data['school'] = Sentry::getUser()->first_name;
         $data['year'] = date('Y');
         $data['verifikasi'] = 0;
         $data['user_id'] = Sentry::getUser()->id;
         Payment::create($data);
         return Redirect::to('user/cost')->with("successMessage", "Konfirmasi Pembayaran berhasil dimasukkan");
     }
 }
Exemplo n.º 3
0
 public function addNew()
 {
     //verify the user input and create account
     $validator = Validator::make(Input::all(), array('Amount' => 'required|numeric'));
     if ($validator->fails()) {
         return Redirect::route('withdraw-get')->withErrors($validator)->withInput();
     } else {
         $amount = Input::get('Amount');
         $todaysdate = date("Y-m-d");
         $totalvisits = Link::where('username', '=', Auth::user()->username)->where('active', '=', TRUE)->sum('clicks');
         $totalearned = $totalvisits * 0.1;
         $withdrawn = Payment::where('user_id', '=', Auth::user()->id)->sum('amount');
         $balance = $totalearned - $withdrawn;
         if ($amount <= $balance) {
             if ($amount >= 500) {
                 //register the new user
                 $newwithdrawal = Payment::create(array('user_id' => Auth::user()->id, 'amount' => $amount, 'withdrawal_date' => $todaysdate, 'paid' => FALSE));
                 if ($newwithdrawal) {
                     return Redirect::route('withdraw-get')->with('global', 'Success! Your Withdrawal request is being processed.');
                 }
             } else {
                 return Redirect::route('withdraw-get')->with('global', 'Failed!! You are allowed to withdraw a minimum of Ksh 500.')->withInput();
             }
         } else {
             return Redirect::route('withdraw-get')->with('global', 'Failed!! The amount exceeds your balance.')->withInput();
         }
     }
 }
Exemplo n.º 4
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Payment::create([]);
     }
 }
 public function testAuthorizedPaymentCreatesCustomer()
 {
     $this->mockResponse($this->success_authorize_with_customer_response());
     $params = array('card_number' => '4000000000000002', 'expiration_month' => '01', 'expiration_year' => date('Y') + 1, 'cvv' => '123', 'holder_name' => 'John Doe', 'amount' => 100, 'create_customer' => true, 'capture' => false);
     $payment = Payment::create($params);
     $this->assertPaymentProperties($payment);
     $this->assertObjectHasAttribute('customer', $payment);
 }
Exemplo n.º 6
0
 /**
  * Store a newly created payment in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Payment::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     Payment::create($data);
     return Redirect::route('payments.index');
 }
 public function testPaymentCreate()
 {
     $this->mockResponse($this->success_payment_create_response());
     $params = array('card_number' => '4111111111111111', 'expiration_month' => '01', 'expiration_year' => date('Y') + 1, 'cvv' => '123', 'holder_name' => 'John Doe', 'amount' => 100);
     $payment = Payment::create($params);
     $this->assertObjectHasAttribute('token', $payment);
     $this->assertObjectHasAttribute('status', $payment);
     $this->assertObjectHasAttribute('amount', $payment);
     $this->assertObjectHasAttribute('fee_amount', $payment);
 }
 public function setUp()
 {
     parent::setUp();
     Payment::config()->allowed_gateways = array('PayPal_Express', 'PaymentExpress_PxPay', 'Manual', 'Dummy');
     Payment::config()->parameters = array('PaymentExpress_PxPay' => array('username' => 'EXAMPLEUSER', 'password' => '235llgwxle4tol23l'));
     //set up a payment here to make tests shorter
     $this->payment = Payment::create()->setGateway("Dummy")->setAmount(1222)->setCurrency("GBP");
     PaymentService::set_http_client($this->getHttpClient());
     PaymentService::set_http_request($this->getHttpRequest());
 }
Exemplo n.º 9
0
 public function post_process()
 {
     Log::write('PayPal', 'Trying to process IPN');
     Bundle::start('paypal-ipn');
     $listener = new IpnListener();
     //        $listener->use_sandbox = true;
     try {
         $listener->requirePostMethod();
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         Log::info($e->getMessage());
     }
     if ($verified) {
         Log::write('PayPal', 'IPN payment looks verified');
         $data = Input::get();
         $settings = IniHandle::readini();
         if (!in_array($data['payment_status'], array('Completed', 'COMPLETED', 'completed'))) {
             Log::write('PayPal', 'payment not completed');
             return View::make('msg.error')->with('error', 'PayPal: payment not completed');
         }
         if (strtolower($data['receiver_email']) != strtolower($settings['ppemail'])) {
             Log::write('PayPal', 'receive email not same as set in settings. Settings: ' . $settings['ppemail'] . ' ||| PayPal email: ' . $data['receiver_email']);
             return View::make('msg.error')->with('error', 'PayPal: receive email not same as set in settings');
         }
         if (Payment::where('transaction_id', '=', $data['txn_id'])->count() != 0) {
             Log::write('PayPal', 'transaction ID already exists');
             return View::make('msg.error')->with('error', 'PayPal: transaction ID already exists');
         }
         if (strtolower($data['mc_currency']) != strtolower($settings['ppcurrency'])) {
             Log::write('PayPal', 'Currencies do not match');
             return View::make('msg.error')->with('error', 'PayPal: currencies do not match');
         }
         Log::write('PayPal', 'Got past all PLAN controller checks now going into CUSTOM');
         if (strtolower($data['custom']) == 'plan') {
             $result = Payment::verifyPlan($data);
             if (!$result) {
                 return $result;
             }
         } elseif (strtolower($data['custom']) == 'blacklist_skype' || strtolower($data['custom']) == 'blacklist_ip') {
             $result = Payment::verifyBlacklist($data);
             if (!$result) {
                 return $result;
             }
         } else {
             Log::write('PayPal', 'Custom not found, can\'t verify anything');
             return View::make('msg.error')->with('error', 'Fraudulent payment?');
         }
         Log::write('PayPal', 'Now trying to add Payment info to DB');
         $payment = Payment::create(array('user_id' => $data['option_selection1'], 'token' => $data['ipn_track_id'], 'date' => date('Y-m-d H:i:s', time()), 'ack' => $data['payment_status'], 'transaction_id' => $data['txn_id'], 'amount' => $data['mc_gross'], 'paypal_fee' => $data['mc_fee'], 'status' => $data['payment_status'], 'description' => $data['custom']));
         Log::write('PayPal', 'Successful payment, DB id: ' . $payment->id);
     } else {
         Log::write('PayPal', 'IPN listener returns false on check');
     }
     return 'handled';
 }
Exemplo n.º 10
0
 /**
  * create payment for order
  * 
  * @param string $success_url Url of page to display after successful payment
  * @param string $cancel_url  Url of page to display after canceled payment
  * @param string $subject     Subject of the payment
  * 
  * @return Payment
  */
 public function createPayment($success_url, $cancel_url, $subject = null)
 {
     $paymentdata = new PaypalPaymentData();
     $paymentdata->subject = is_null($subject) ? 'Order #' . $this->getId() : $subject;
     $paymentdata->cancel_url = $cancel_url;
     $paymentdata->return_url = $success_url;
     $payment = Payment::create($this->getGrossSum('de'), 'EUR', $paymentdata);
     $payment->setOrder($this);
     $payment->save();
     return $payment;
 }
 public function submit($data, $form)
 {
     $invoice = new PaymentPage_Invoice();
     $invoice->write();
     $form->saveInto($invoice);
     $payment = Payment::create()->init($data['Gateway'], $invoice->Amount, $this->Currency)->setReturnUrl($this->Link('complete') . "?invoice=" . $invoice->ID)->setCancelUrl($this->Link() . "?message=payment cancelled");
     $payment->write();
     $invoice->ParentID = $this->ID;
     $invoice->PaymentID = $payment->ID;
     $invoice->write();
     $payment->purchase($form->getData())->redirect();
 }
 /**
  * create payment for order
  * @return Payment
  */
 public function createPayment($action)
 {
     sfContext::getInstance()->getLogger()->log('Zahlung wird angelegt', 6);
     $paymentdata = new PaypalPaymentData();
     $paymentdata->subject = 'Test Payment #' . $this->getId();
     $paymentdata->cancel_url = $action->generateUrl('timpany_cart', array(), true);
     $paymentdata->return_url = $action->generateUrl('payment_approve', array(), true);
     $payment = Payment::create($this->getGrossSum('de'), 'EUR', $paymentdata);
     $payment->setOrder($this);
     $payment->save();
     return $payment;
 }
Exemplo n.º 13
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Started...');
     Subscription::chunk(200, function ($subscriptions) {
         $accepted = 0;
         $declined = 0;
         $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2');
         foreach ($subscriptions as $subscription) {
             $expiration = Carbon::createFromTimeStamp(strtotime($subscription->expires_at));
             if ($expiration->isToday() || $expiration->isPast()) {
                 $sale = $subscription->payment()->orderBy('id', 'desc')->where('is_success', '=', 1)->orWhere('is_success', '=', 2)->first();
                 if ($sale->is_success == 2) {
                     $resale_params = array('id_authorization' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                     $status = $client->resaleByAuthorization($resale_params);
                 } else {
                     if ($sale->is_success == 1) {
                         $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                         $status = $client->resaleBySale($params);
                     }
                 }
                 if ($client->isSuccess()) {
                     $accepted++;
                     $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     $subscription->is_active = 1;
                     $subscription->save();
                     $user = User::find($subscription->user_id);
                     $user->level = 2;
                     $user->save();
                     $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
                     if ($configs->count() > 0) {
                         foreach ($configs as $config) {
                             $config->is_active = 1;
                             $config->save();
                         }
                     }
                     EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                     $faktura = $subscription->company_id == 0 ? false : true;
                     Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura));
                 } else {
                     $declined++;
                     $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0, 'sale_id' => $status['error']['error_number']));
                     Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at));
                 }
             }
         }
         $this->info('Accepted:' . $accepted);
         $this->info('Declined:' . $declined);
     });
     $this->info('Done');
 }
Exemplo n.º 14
0
 public function testIndex()
 {
     $controller = $this->getController();
     //default is dataform
     $output = $controller->index();
     $this->assertInstanceOf("Form", $output['Form']);
     $this->assertEquals("GatewaySelectForm", $output['Form']->getName());
     //start a payment
     $newpayment = Payment::create()->init("Dummy", 100, "NZD");
     $controller->getPayable()->Payments()->add($newpayment);
     //index switches to data form
     $output = $controller->index();
     $this->assertInstanceOf("Form", $output['Form']);
     $this->assertEquals("GatewayDataForm", $output['Form']->getName());
 }
 /**
  * The initial action where the amount which should be processed by PayPal is
  * determined.
  * 
  * @param sfWebRequest $request
  * @return void
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->approvedPayments = Doctrine_Core::getTable('Payment')->createQuery('p')->leftJoin('p.Transactions t')->leftJoin('p.DataContainer d')->where('p.state = ? OR p.state = ?', array(Payment::STATE_APPROVED, Payment::STATE_DEPOSITING))->execute();
     $this->form = new mySimpleAmountForm();
     if ($request->hasParameter('simpleAmountForm')) {
         $this->form->bind($request->getParameter('simpleAmountForm'));
         if ($this->form->isValid()) {
             $data = new PaypalPaymentData();
             $data->subject = 'Test Payment #ABC344';
             $payment = Payment::create($this->form->getValue('amount'), $this->form->getValue('currency'), $data);
             $data->cancel_url = $this->context->getController()->genUrl(array('module' => 'paypalDemo', 'action' => 'cancelPayment', 'reference' => $payment->id), true);
             $data->return_url = $this->context->getController()->genUrl(array('module' => 'paypalDemo', 'action' => 'completePayment', 'reference' => $payment->id), true);
             $data->save();
             $this->redirect('paypalDemo/completePayment?reference=' . $payment->id);
         }
     }
 }
Exemplo n.º 16
0
function doInsert()
{
    if (isset($_POST['save'])) {
        //primary Details
        $AMOUNT = $_POST['amount'];
        $DESCRIPTION = $_POST['description'];
        $INSTALLMENT = $_POST['installment'];
        $PROJECT = $_POST['project'];
        $payment = new Payment();
        //$payment->S_ID	= "null";
        $payment->amount = $AMOUNT;
        $payment->description = $DESCRIPTION;
        $payment->installment_number = $INSTALLMENT;
        $payment->project_id = $PROJECT;
    }
    //course infor
    /*$course	= $_POST['course'];
    $semester = $_POST['semester'];
    $ay		= $_POST['AY'];
    $sy = new Schoolyr();
    $sy->AY 		= $ay;
    $sy->SEMESTER 	= $semester;
    $sy->COURSE_ID	= $course;
    $sy->IDNO 		= $IDNO;*/
    /*if ($istrue) {
    	output_message('course info successfully added!');
    	redirect ('newpayment.php');
    }
    
    */
    //
    /*if ($istrue) {
    	output_message('Seccondary details successfully added!');
    	redirect ('newpayment.php');
    }
    */
    //$istrue = $requirements->create();
    /*if ($istrue) {
    	output_message('payment requirements successfully added!');
    	redirect ('newpayment.php');
    } 
    */
    if ($AMOUNT == "") {
        message('Amount is required!', "error");
        redirect('index.php?view=add');
    } elseif ($DESCRIPTION == "") {
        message('Description is required!', "error");
        redirect('index.php?view=add');
    } elseif ($INSTALLMENT == "") {
        message('Installment number  is required!', "error");
        redirect('index.php?view=add');
    } elseif ($PROJECT == "") {
        message('project id is required!', "error");
        redirect('index.php?view=add');
    } else {
        $payment->create();
        #$sy->create();
        //$studdetails->create();
        //$requirements->create();
        message('New payment addedd successfully!', "success");
        redirect('index.php?view=list');
    }
}
 /**
  * 
  * Add ticket Payment
  * 
  * @param array $aryTicket	Ticket data array
  */
 private function addPayment($aryTicket)
 {
     global $db, $langs;
     require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
     $now = dol_now();
     $userstatic = new User($db);
     if (!$aryTicket['employeeId']) {
         $employee = $_SESSION['uid'];
     } else {
         $employee = $aryTicket['employeeId'];
     }
     $userstatic->fetch($employee);
     if ($aryTicket['type'] == 1) {
         $aryTicket['total'] = $aryTicket['total'] * -1;
         $aryTicket['customerpay1'] = $aryTicket['customerpay1'] * -1;
         $aryTicket['customerpay2'] = $aryTicket['customerpay2'] * -1;
         $aryTicket['customerpay3'] = $aryTicket['customerpay3'] * -1;
     }
     $cash = new Cash($db);
     $terminal = $_SESSION['TERMINAL_ID'];
     $cash->fetch($terminal);
     if ($aryTicket['customerpay1'] != 0) {
         $bankaccountid[1] = $cash->fk_paycash;
         $modepay[1] = $cash->fk_modepaycash;
         $amount[1] = $aryTicket['customerpay1'] + ($aryTicket['difpayment'] < 0 ? $aryTicket['difpayment'] : 0);
     }
     if ($aryTicket['customerpay2'] != 0) {
         $bankaccountid[2] = $cash->fk_paybank;
         $modepay[2] = $cash->fk_modepaybank;
         $amount[2] = $aryTicket['customerpay2'];
     }
     if ($aryTicket['customerpay3'] != 0) {
         $bankaccountid[3] = $cash->fk_paybank_extra;
         $modepay[3] = $cash->fk_modepaybank_extra;
         $amount[3] = $aryTicket['customerpay3'];
     }
     $i = 1;
     $payment = new Payment($db);
     while ($i <= 3) {
         $payment->datepaye = $now;
         $payment->bank_account = $bankaccountid[$i];
         $payment->amounts[$aryTicket['id']] = $amount[$i];
         $payment->note = $langs->trans("Payment") . ' ' . $langs->trans("Ticket") . ' ' . $aryTicket['ref'];
         $payment->paiementid = $modepay[$i];
         $payment->num_paiement = '';
         if ($amount[$i] != 0) {
             $paiement_id = $payment->create($userstatic);
             if ($paiement_id > 0) {
                 $result = $payment->addPaymentToBank($userstatic, 'payment', '(CustomerFacturePayment)', $bankaccountid[$i], $aryTicket['customerId'], '', '');
                 if (!$result > 0) {
                     $error++;
                 }
             } else {
                 $error++;
             }
         }
         $i++;
     }
     if ($error) {
         return -1;
     } else {
         return $paiement_id;
     }
 }
Exemplo n.º 18
0
 /**
  * Store a newly created booking in storage.
  * This includes Clients, FlightDetails
  *
  * @return Response
  */
 public function store()
 {
     if (Auth::check()) {
         $user = Auth::user();
         if (Entrust::hasRole('Agent')) {
             $rules = Booking::$agentRules;
         }
     } else {
         $rules = Booking::$guestRules;
     }
     $data = Input::all();
     if (Auth::check()) {
         $data['user_id'] = Auth::id();
     }
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         //dd($validator->errors());
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $data['val'] = 1;
     if ($x = Booking::find(Booking::max('id'))) {
         $data['reference_number'] = ++$x->reference_number;
     } else {
         $data['reference_number'] = 10000000;
     }
     Session::put('MyBookingData', $data);
     $clients = null;
     $newBooking = $this->storeAllData();
     $booking_name = $newBooking->booking_name;
     $booking_amount = Booking::getTotalBookingAmount($newBooking);
     $data = array('details' => $booking_name, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'amount' => $booking_amount, 'payment_status' => 0, 'my_booking' => 2);
     $reserv_id = Payment::create($data);
     $data_tab_HSBC_payment = array('currency' => 'USD');
     $tab_HSBC_payment_id = HsbcPayment::create($data_tab_HSBC_payment);
     $stamp = strtotime("now");
     $payment_id = Payment::orderBy('created_at', 'desc')->first()->id;
     $orderid = "{$stamp}" . 'A' . "{$payment_id}";
     $last_res_resid = str_replace(".", "", $orderid);
     $hsbc_id = HsbcPayment::orderBy('created_at', 'desc')->first()->id;
     $hsbc_payment_id_pre = "{$stamp}" . 'HSBC' . "{$hsbc_id}";
     $hsbc_payment_id = str_replace(".", "", $hsbc_payment_id_pre);
     if ($last_res_resid) {
         $payment = DB::table('payments')->where('id', $payment_id)->update(array('reference_number' => $last_res_resid, 'HSBC_payment_id' => $hsbc_payment_id));
         $data_tab_HSBC_payment = DB::table('hsbc_payments')->where('id', $hsbc_id)->update(array('HSBC_payment_id' => $hsbc_payment_id));
     }
     $currency = 'USD';
     //$x = Booking::getTotalBookingAmount($newBooking) * 100 * 1.037;
     // $x = 2 * 100 * 1.037;
     //$total_price_all_hsbc = round($x, 2);
     $total_price_all_hsbc = $booking_amount * 100;
     dd($total_price_all_hsbc);
     //        dd($hsbc_payment_id . '/' . $currency . '/' . $total_price_all_hsbc . '/' . $last_res_resid);
     HsbcPayment::goto_hsbc_gateway($hsbc_payment_id, $currency, $total_price_all_hsbc, $last_res_resid);
 }
Exemplo n.º 19
0
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    $is_ajax = true;
}
$user_id = $_COOKIE['user_id'];
$total = 0;
// Connect to database
$con = mysql_connect(DB_HOST, DB_USER, DB_PW);
if (!$con) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db(DB_NAME, $con);
// if the form has been submitted
if (isset($_POST['submit_check'])) {
    $paymentObj = new Payment();
    $paymentObj->setUser_id($user_id);
    $paymentObj->create();
    $payment_id = mysql_insert_id();
    $debtObj = new Debt();
    $debtObj->setOwed_to($user_id);
    $debtObj->setPayment_id($payment_id);
    $total = 0;
    for ($i = 0; $i < count($_POST["user_id"]); $i++) {
        $debtObj->setOwed_by($_POST['user_id'][$i]);
        $debt_total = $_POST['drinks_owed'][$i] + $_POST['food_owed'][$i];
        $total += $debt_total;
        $debtObj->setAmount($debt_total);
        $debtObj->create();
        //echo "<p>" . $_POST['user_id'][$i] . " owes " . $_COOKIE['user_id'] . " &pound;" . $_POST['drinks_owed'][$i] . " for drinks and &pound;" . $_POST['food_owed'][$i] . " for food for a total of &pound;" . $total . "</p>";
    }
    $paymentObj->setId($payment_id);
    $paymentObj->setTotal($total);
Exemplo n.º 20
0
 public static function createNewPaymentForBill($bill, $amount, $lab_config_id)
 {
     $payment = new Payment($amount, $bill->id);
     $payment->create($lab_config_id);
     return $payment;
 }
 /**
  * Process the form that is submitted through the site. Note that omnipay fields are NOT saved to the database.
  * This is intentional (so we don't save credit card details) but should be fixed in future, so we save all fields,
  * but only save the last 3 digits of the credit card (and not the CVV/exp date)
  *
  * @todo: save all fields to database except credit card fields
  *
  * @param array $data
  * @param Form  $form
  *
  * @return Redirection
  */
 public function process($data, $form)
 {
     Session::set("FormInfo.{$form->FormName()}.data", $data);
     Session::clear("FormInfo.{$form->FormName()}.errors");
     foreach ($this->Fields() as $field) {
         $messages[$field->Name] = $field->getErrorMessage()->HTML();
         $formField = $field->getFormField();
         if ($field->Required && $field->CustomRules()->Count() == 0) {
             if (isset($data[$field->Name])) {
                 $formField->setValue($data[$field->Name]);
             }
             if (!isset($data[$field->Name]) || !$data[$field->Name] || !$formField->validate($form->getValidator())) {
                 $form->addErrorMessage($field->Name, $field->getErrorMessage(), 'bad');
             }
         }
     }
     if (Session::get("FormInfo.{$form->FormName()}.errors")) {
         Controller::curr()->redirectBack();
         return;
     }
     // if there are no errors, create the payment
     $submittedForm = Object::create('SubmittedPaymentForm');
     $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
     $submittedForm->ParentID = $this->ID;
     // if saving is not disabled save now to generate the ID
     if (!$this->DisableSaveSubmissions) {
         $submittedForm->write();
     }
     $attachments = array();
     $submittedFields = new ArrayList();
     foreach ($this->Fields() as $field) {
         if (!$field->showInReports()) {
             continue;
         }
         $submittedField = $field->getSubmittedFormField();
         $submittedField->ParentID = $submittedForm->ID;
         $submittedField->Name = $field->Name;
         $submittedField->Title = $field->getField('Title');
         // save the value from the data
         if ($field->hasMethod('getValueFromData')) {
             $submittedField->Value = $field->getValueFromData($data);
         } else {
             if (isset($data[$field->Name])) {
                 $submittedField->Value = $data[$field->Name];
             }
         }
         if (!empty($data[$field->Name])) {
             if (in_array("EditableFileField", $field->getClassAncestry())) {
                 if (isset($_FILES[$field->Name])) {
                     $foldername = $field->getFormField()->getFolderName();
                     // create the file from post data
                     $upload = new Upload();
                     $file = new File();
                     $file->ShowInSearch = 0;
                     try {
                         $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
                     } catch (ValidationException $e) {
                         $validationResult = $e->getResult();
                         $form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
                         Controller::curr()->redirectBack();
                         return;
                     }
                     // write file to form field
                     $submittedField->UploadedFileID = $file->ID;
                     // attach a file only if lower than 1MB
                     if ($file->getAbsoluteSize() < 1024 * 1024 * 1) {
                         $attachments[] = $file;
                     }
                 }
             }
         }
         $submittedField->extend('onPopulationFromField', $field);
         if (!$this->DisableSaveSubmissions) {
             $submittedField->write();
         }
         $submittedFields->push($submittedField);
     }
     /** Do the payment **/
     // move this up here for our redirect link
     $referrer = isset($data['Referrer']) ? '?referrer=' . urlencode($data['Referrer']) : "";
     // set amount
     $currency = $this->data()->PaymentCurrency;
     $paymentfieldname = $this->PaymentAmountField()->Name;
     $amount = $data[$paymentfieldname];
     $postdata = $data;
     // request payment
     $payment = Payment::create()->init($this->data()->PaymentGateway, $amount, $currency);
     $payment->write();
     $response = PurchaseService::create($payment)->setReturnUrl($this->Link('finished') . $referrer)->setCancelUrl($this->Link('finished') . $referrer)->purchase($postdata);
     // save payment to order
     $submittedForm->PaymentID = $payment->ID;
     $submittedForm->write();
     $emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields);
     $this->extend('updateEmailData', $emailData, $attachments);
     $submittedForm->extend('updateAfterProcess');
     Session::clear("FormInfo.{$form->FormName()}.errors");
     Session::clear("FormInfo.{$form->FormName()}.data");
     // set a session variable from the security ID to stop people accessing the finished method directly
     if (isset($data['SecurityID'])) {
         Session::set('FormProcessed', $data['SecurityID']);
     } else {
         // if the form has had tokens disabled we still need to set FormProcessed
         // to allow us to get through the finshed method
         if (!$this->Form()->getSecurityToken()->isEnabled()) {
             $randNum = rand(1, 1000);
             $randHash = md5($randNum);
             Session::set('FormProcessed', $randHash);
             Session::set('FormProcessedNum', $randNum);
         }
     }
     if (!$this->DisableSaveSubmissions) {
         Session::set('userformssubmission' . $this->ID, $submittedForm->ID);
     }
     return $response->redirect();
 }
Exemplo n.º 22
0
 private function addOrUpdatePayments($id, $postedData){            
     try{
         try{
             $data = \Payment::find($id);
         }catch (\ActiveRecord\RecordNotFound $ex) {
             $data = null;
         }
         $attributes = $this->getAttrForpaymentsFromPost($postedData);
         $oldamount = 0;
         if(is_null($data)){
             $data = \Payment::create($attributes);                                        
         }else{
             $oldamount = $data->amount;
             $data->update_attributes($attributes);
         }
         $paid = $data->account->paid + $data->amount - $oldamount;
         $this->updatePaidamntInAccount($data->account, $paid);
         if(strtolower($data->direction) === Menu::payment_inwards){
             $paid = $data->order->paid + $data->amount - $oldamount;
             $this->updatePaidamntInOrder($data->order, $paid);
         }
         $rtnmsg = "OK";
     }catch (\Slim\Exception $ex) {
         $rtnmsg = "Error";
     }
     catch (\Exception $ex) {
         $rtnmsg = "Error";
     }
     return $rtnmsg;
 }
Exemplo n.º 23
0
 /**
  * Store a newly created payment in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     $user_id = Auth::id();
     $validator = Validator::make(Input::all(), array('amount' => 'required|numeric'));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     /**
      * Payments are starting from "BK" numbers
      */
     if ($x = Payment::find(Payment::max('id'))) {
         $y = (int) substr($x->reference_number, 2);
         $data['reference_number'] = 'BK' . ++$y;
     } else {
         $data['reference_number'] = 'BK10000000';
     }
     $data['agent_id'] = User::getAgentOfUser(Auth::id());
     if (Entrust::hasRole('Agent')) {
         $agent_id = $data['agent_id']->user_id;
         $name = User::where('id', $user_id)->first()->first_name . ' ' . User::where('id', $user_id)->first()->last_name;
         $email = User::where('id', $user_id)->first()->email;
         $phone = Agent::where('user_id', $user_id)->first()->phone;
         $amount = Input::get('amount');
         $details = Input::get('details');
         $data = array('details' => $name, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'amount' => $amount, 'payment_status' => 0, 'my_booking' => 2);
         $reserv_id = Payment::create($data);
         $data_tab_HSBC_payment = array('currency' => 'USD');
         $tab_HSBC_payment_id = HsbcPayment::create($data_tab_HSBC_payment);
         $stamp = strtotime("now");
         $payment_id = Payment::orderBy('created_at', 'desc')->first()->id;
         $orderid = "{$stamp}" . 'AP' . "{$payment_id}";
         $last_res_resid = str_replace(".", "", $orderid);
         $hsbc_id = HsbcPayment::orderBy('created_at', 'desc')->first()->id;
         $hsbc_payment_id_pre = "{$stamp}" . 'HSBC' . "{$hsbc_id}";
         $hsbc_payment_id = str_replace(".", "", $hsbc_payment_id_pre);
         if ($last_res_resid) {
             $payment = DB::table('payments')->where('id', $payment_id)->update(array('reference_number' => $last_res_resid, 'HSBC_payment_id' => $hsbc_payment_id));
             $data_tab_HSBC_payment = DB::table('hsbc_payments')->where('id', $hsbc_id)->update(array('HSBC_payment_id' => $hsbc_payment_id));
             $client = array('booking_name' => $name, 'email' => $email, 'phone' => $phone, 'remarks' => $details, 'val' => 0, 'payment_reference_number' => $last_res_resid);
             $client_payment_id = Booking::create($client);
         }
         $currency = 'USD';
         $x = $amount * 1.037;
         $total_price_all_hsbc = round($x, 2) * 100;
         //dd($hsbc_payment_id . '/' . $currency . '/' . $total_price_all_hsbc . '/' . $last_res_resid);
         HsbcPayment::goto_hsbc_gateway($hsbc_payment_id, $currency, $total_price_all_hsbc, $last_res_resid);
         //  return $this->storeAllDataAndSendEmails();
     }
     //Payment::create($data);
     return Redirect::route('accounts.payments.index');
 }
 /**
  * Create a partial payment that will be based on the current payment.
  * This new payment will inherit the Gateway, TransactionReference, SuccessUrl and FailureUrl
  * of the initial payment.
  * @param float $amount the amount that the partial payment should have
  * @param string $status the desired payment status
  * @param boolean $write whether or not to directly write the new Payment to DB (optional)
  * @return \Payment the newly created payment (already written to the DB)
  */
 protected function createPartialPayment($amount, $status, $write = true)
 {
     /** @var \Payment $payment */
     $payment = \Payment::create(array('Gateway' => $this->payment->Gateway, 'TransactionReference' => $this->payment->TransactionReference, 'SuccessUrl' => $this->payment->SuccessUrl, 'FailureUrl' => $this->payment->FailureUrl, 'InitialPaymentID' => $this->payment->ID));
     $payment->setCurrency($this->payment->getCurrency());
     $payment->setAmount($amount);
     // set status later, because otherwise amount and currency become immutable
     $payment->Status = $status;
     // allow extensions to update/modify the partial payment
     Helper::safeExtend($this, 'updatePartialPayment', $payment, $this->payment);
     if ($write) {
         Helper::safeguard(function () use(&$payment) {
             $payment->write();
         }, 'Unable to write newly created partial Payment!');
     }
     return $payment;
 }
Exemplo n.º 25
0
 public function postPayment()
 {
     if (Auth::check()) {
         $rules = array('paylane_token' => 'required', 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'address' => 'required', 'zip' => 'required', 'city' => 'required', 'state' => 'required', 'company_name' => 'required_with:faktura', 'company_id' => 'required_with:faktura', 'company_address' => 'required_with:faktura', 'company_zip' => 'required_with:faktura', 'company_city' => 'required_with:faktura', 'company_state' => 'required_with:faktura');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             $messages = $validator->messages();
             return Redirect::to('/konto/pro/platnosci')->withInput(Input::flash())->withErrors($validator)->with('alert', array('type' => 'error', 'content' => 'Błąd! Sprawdź wszystkie pola.'));
         } else {
             $user = Auth::user();
             $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2');
             $card_params = array('sale' => array('amount' => 189.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'), 'customer' => array('name' => Input::get('first_name') . ' ' . Input::get('last_name'), 'email' => Input::get('email'), 'ip' => '127.0.0.1', 'address' => array('street_house' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'), 'country_code' => 'PL')), 'card' => array('token' => Input::get('paylane_token')));
             $status = $client->cardSaleByToken($card_params);
             if ($client->isSuccess()) {
                 $subscription = Subscription::where('user_id', '=', $user->id);
                 $faktura = false;
                 if ($subscription->count() > 0) {
                     $subscription = $subscription->first();
                     $subscription->user_id = $user->id;
                     $subscription->is_active = 1;
                     $subscription->first_name = Input::get('first_name');
                     $subscription->last_name = Input::get('last_name');
                     $subscription->email = Input::get('email');
                     $subscription->address = Input::get('address');
                     $subscription->zip = Input::get('zip');
                     $subscription->city = Input::get('city');
                     $subscription->state = Input::get('state');
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     if (Input::has('faktura')) {
                         $faktura = true;
                         $subscription->is_active = 1;
                         $subscription->company_name = Input::get('company_name');
                         $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id'));
                         $subscription->company_address = Input::get('company_address');
                         $subscription->company_city = Input::get('company_city');
                         $subscription->company_state = Input::get('company_state');
                         $subscription->company_zip = Input::get('company_zip');
                     }
                     $subscription->save();
                 } else {
                     $subscription = new Subscription();
                     $subscription->user_id = $user->id;
                     $subscription->first_name = Input::get('first_name');
                     $subscription->last_name = Input::get('last_name');
                     $subscription->email = Input::get('email');
                     $subscription->address = Input::get('address');
                     $subscription->zip = Input::get('zip');
                     $subscription->city = Input::get('city');
                     $subscription->state = Input::get('state');
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     if (Input::has('faktura')) {
                         $faktura = true;
                         $subscription->company_name = Input::get('company_name');
                         $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id'));
                         $subscription->company_address = Input::get('company_address');
                         $subscription->company_city = Input::get('company_city');
                         $subscription->company_state = Input::get('company_state');
                         $subscription->company_zip = Input::get('company_zip');
                     }
                     $subscription->save();
                 }
                 $payment = Payment::create(array('user_id' => $user->id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale'], 'is_success' => 1));
                 Event::fire('invoice.email', array($user->id, $subscription->id, $payment->id, $faktura));
                 EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                 //here
                 $user->level = 2;
                 $user->save();
                 return Redirect::to('/konto/pro/subskrypcja')->with('alert', array('type' => 'success', 'content' => 'Dziękujemy! Płatność zaakceptowana.'));
             } else {
                 if (isset($status['error'])) {
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['error_description']));
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['description']));
                 } else {
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak!'));
                 }
             }
         }
     }
 }
Exemplo n.º 26
0
 public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl)
 {
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // Specify the payment amount.
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($total);
     // ###Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a 'Payee' and 'Amount' types
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($paymentDesc);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($returnUrl);
     $redirectUrls->setCancelUrl($cancelUrl);
     $payment = new Payment();
     $payment->setRedirectUrls($redirectUrls);
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $payment->create(getApiContext());
     return $payment;
 }
Exemplo n.º 27
0
 /**
  * 生成订单
  */
 public function action_paymoney()
 {
     $this->template->pageTitle = '订单支付';
     $info = explode(',', base64_decode(trim($this->getQuery('t'))));
     if (!empty($info)) {
         $upgrade = new Upgrade($this->auth, (int) $info[0], (int) $info[1]);
         try {
             $upgrade->check_place();
         } catch (Exception $e) {
             $this->show_message('创建订单失败:' . $e->getMessage());
         }
         $this->template->payPrice = $payPrice = ceil($upgrade->calculate()->getMoney());
         // 订单金额
         $this->template->getGroupPrice = $getGroupPrice = $upgrade->getGroupPrice();
         // 获取升级组需要金额
         if ($payPrice < 1) {
             $links[] = array('text' => '返回付费中心', 'href' => '/pay/upgrade');
             $this->show_message('抱歉,所在用户组无法升级。。。', 0, $links);
         }
         $this->template->group = $upgrade->getGroup();
         switch ($info[0]) {
             default:
                 $gift = '';
                 break;
         }
         $this->template->gift = $gift;
         if ($info[1] == 12) {
             $unit = "1年";
         } else {
             $unit = $info[1] . "个月";
         }
         $this->template->unit = $unit;
         # 计算付款后到期时间
         if ($this->auth['rank'] == $info[0]) {
             $expire = time() - $this->auth['expire_time'];
             if ($expire > 604800) {
                 $will_exceed = date('Y-m-d', strtotime(date('Y-m-d H:i:s') . ' + ' . $info[1] . ' ' . 'month') - 604800);
             } else {
                 $will_exceed = date('Y-m-d', strtotime(date('Y-m-d H:i:s', $this->auth['expire_time']) . ' + ' . $info[1] . ' ' . 'month'));
             }
         } else {
             $will_exceed = date('Y-m-d', strtotime('+' . $info[1] . ' month '));
         }
         $this->template->will_exceed = $will_exceed;
         $this->template->order_id = $order_id = $upgrade->generateOrderSn();
         $data = array('uid' => $this->auth['uid'], 'dest_group' => $info[0], 'save_time' => date('Y-m-d H:i:s'), 'fee' => $payPrice, 'current_group' => $this->auth['rank'], 'orderno' => $order_id, 'consume_type' => 1, 'will_exceed' => $will_exceed, 'month' => $info[1]);
         # 创建订单
         DB::insert('imgup_upgrade', array_keys($data))->values(array_values($data))->execute();
         try {
             $order_id = (int) $order_id;
             $info = $data;
             $adapter = $this->template->adapter = 'alipay';
             if ($info['uid'] != $this->auth['uid']) {
                 throw new Exception('您不能查看别人的订单。');
             }
             $payConf = $this->template->payConf = Payment::get_all();
             // 支付方式
             $adapter = 'alipay';
             if ($payConf->{$adapter}->online) {
                 // 在线支付
                 $title = $this->auth['username'] . '购买外链吧相册服务';
                 $body = $this->auth['username'] . '于' . date('Y年m月d日') . '购买外链吧网络相册服务,订单号:' . $info['orderno'];
                 $payment = Payment::create('alipay', $payConf->{$adapter}->config);
                 $payment->set_id($info['orderno'])->set_subject($title)->set_body($body)->set_amount($info['fee'])->set_key($payConf->{$adapter}->pay_key);
                 if (!$payment->is_valid()) {
                     throw new Exception($payment->get_message());
                 }
                 $this->template->payment = $payment;
             }
         } catch (Exception $e) {
             $this->show_message('订单支付失败:' . $e->getMessage());
         }
     } else {
         $this->request->redirect('/pay/upgrade');
     }
 }
Exemplo n.º 28
0
 /**
  * Create a new payment for an order
  */
 public function createPayment($gateway)
 {
     if (!GatewayInfo::isSupported($gateway)) {
         $this->error(_t("PaymentProcessor.InvalidGateway", "`{gateway}` isn't a valid payment gateway.", 'gateway is the name of the payment gateway', array('gateway' => $gateway)));
         return false;
     }
     if (!$this->order->canPay(Member::currentUser())) {
         $this->error(_t("PaymentProcessor.CantPay", "Order can't be paid for."));
         return false;
     }
     $payment = Payment::create()->init($gateway, $this->order->TotalOutstanding(true), ShopConfig::get_base_currency());
     $this->order->Payments()->add($payment);
     return $payment;
 }
Exemplo n.º 29
0
 /**
  * Create a new payment for an order
  */
 public function createPayment($gateway)
 {
     if (!GatewayInfo::is_supported($gateway)) {
         $this->error(_t("PaymentProcessor.INVALIDGATEWAY", "`{$gateway}` isn't a valid payment gateway."));
         return false;
     }
     if (!$this->order->canPay(Member::currentUser())) {
         $this->error(_t("PaymentProcessor.CANTPAY", "Order can't be paid for."));
         return false;
     }
     $payment = Payment::create()->init($gateway, $this->order->TotalOutstanding(), ShopConfig::get_base_currency());
     $this->order->Payments()->add($payment);
     return $payment;
 }
Exemplo n.º 30
0
                        $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                        $status = $client->resaleBySale($params);
                    }
                }
                if ($client->isSuccess()) {
                    $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
                    $subscription->expires_at = Carbon::now()->addDays(30);
                    $subscription->is_active = 1;
                    $subscription->save();
                    $user = User::find($subscription->user_id);
                    $user->level = 2;
                    $user->save();
                    $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
                    if ($configs->count() > 0) {
                        foreach ($configs as $config) {
                            $config->is_active = 1;
                            $config->save();
                        }
                    }
                    EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                    $faktura = $subscription->company_id == 0 ? false : true;
                    Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura));
                } else {
                    $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0));
                    Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at));
                }
            }
        }
    });
});
require app_path() . '/helpers.php';