Beispiel #1
0
            //work out how much we will be paying to this invoice:
            $curr_owing = $curr_inv['all_charge'] - $curr_inv['all_pay'];

            if ( $curr_owing < $extrapayment) { //we have more money to pay than on invoice
                $revert = 'more'; // for use if a rollback is needed
                $sub_payment_data['ac_amount'] = $curr_owing;
                $extrapayment = $extrapayment - $curr_owing;
            } elseif ($curr_owing >= $extrapayment) { //no more money
                $sub_payment_data['ac_amount'] = $extrapayment;
                $extrapayment = 0.0;
                $revert = 'nomore';
            }

            // Insert subpayment
            $sub_result = $SI_PAYMENTS->insert($sub_payment_data);

            //revert variables back to previous state if payment insert fails
            $sub_saved = !empty($sub_result) ? "true" : "false";
            if($sub_saved =='false') {
                if ($revert == 'more') {
                    //rollback amount we have to pay
                    $extrapayment = $extrapayment + $curr_owing;
                } elseif ($revert == 'nomore') {
                    $extrapayment = $sub_payment_data['ac_amount'];
                }

            } else { //payment succesful, record data in array and note html
                $paid_to[$SI_PAYMENTS->getLastInsertId()] = $sub_payment_data['ac_amount'];
                $inv_info .= sprintf($inv_info_format,$sub_payment_data['ac_inv_id'],$sub_payment_data['ac_amount']);
            }
            
        $payment_type_data = array(
            'type'  => 'Paypal'
        );

        $db_payment_type = $SI_PAYMENT_TYPES->findByName($payment_type_data['type']);
        if (!$db_payment_type) {
            $SI_PAYMENT_TYPES->insert($payment_type_data);
            $db_payment_type = $SI_PAYMENT_TYPES->findByName($payment_type_data['type']);
        }
        $payment_data['ac_payment_type'] = $db_payment_type['pt_id'];
        
		$logger->log('Paypal - payment_type='.$payment_data['ac_payment_type'], Zend_Log::INFO);
		
        // Insert the payment
        $SI_PAYMENTS->insert($payment_data);

		$invoice = invoice::select($p->ipn_data['invoice']);
		#$invoice = invoice::select($_POST['invoice']);
		$biller = $SI_BILLER->getBiller($invoice['biller_id']);

		//send email
		$body =  "A Paypal instant payment notification was successfully recieved into Simple Invoices\n";
		$body .= "from ".$p->ipn_data['payer_email']." on ".date('m/d/Y');
		$body .= " at ".date('g:i A')."\n\nDetails:\n";
		$body .= $paypal_data;

		$email = new email();
		$email -> notes = $body;
		$email -> to = $biller['email'];
		$email -> from = "*****@*****.**";