Пример #1
0
 public function confirm()
 {
     $this->log->write('Starting');
     if (!isset($this->request->request['invoiceId'])) {
         $json['error'] = "Unexpected error";
     } else {
         Transaction::addPayment($this->customer->getId(), $this->request->request['invoiceId'], $this->registry);
         $invoice = InvoiceDAO::getInstance()->getInvoice($this->request->request['invoiceId']);
         $json['newStatus'] = $this->load->model('localisation/invoice')->getInvoiceStatus($invoice->getStatusId(), $this->session->data['language_id']);
     }
     //        $this->log->write(print_r($json, true));
     $this->getResponse()->setOutput(json_encode($json));
 }
Пример #2
0
 public static function addCredit($customerId, $amount, $currency, $registry, $description = "")
 {
     //        Transaction::$instance->log->write("Starting");
     //        $customer = CustomerDAO::getInstance()->getCustomer($customerId);
     //        Transaction::$instance->log->write("Adding transaction");
     Transaction::addTransaction(0, $customerId, -$amount, $currency, $description);
     /// Try to pay all payment awaiting invoices
     $invoices = InvoiceDAO::getInstance()->getInvoices(array("filterCustomerId" => array((int) $customerId), "filterInvoiceStatusId" => array(IS_AWAITING_PAYMENT)));
     if ($invoices) {
         foreach ($invoices as $invoice) {
             Transaction::addPayment($customerId, $invoice['invoice_id'], $registry);
         }
     }
 }
Пример #3
0
include '../lib/txn.php';
include '../lib/eps-express.php';
$id = (int) $_REQUEST['id'];
$amount = $_REQUEST['amount'];
if (!$id || !$amount) {
    die_jsonp("Either transaction or amount was not specified.");
}
$person_id = (int) $_REQUEST['person'];
$person = $person_id ? person_load($db, $person_id) : false;
$account = $person['payment_account_id'];
if (!$person_id || !$person || !$account) {
    die_jsonp("No person specified or no card stored for person.");
}
$eps = new EPS_Express();
$response = $eps->CreditCardSalePaymentAccount($id, $amount, $account);
$xml = new SimpleXMLElement($response);
if ($xml->Response->ExpressResponseCode != 0) {
    die_jsonp((string) $xml->Response->ExpressResponseMessage);
}
$method = 'credit';
$cc = array();
$cc['cc_txn'] = $xml->Response->Transaction->TransactionID;
$cc['cc_approval'] = $xml->Response->Transaction->ApprovalNumber;
$cc['cc_type'] = $xml->Response->Card->CardLogo;
$txn = new Transaction($db, $id);
try {
    $payment = $txn->addPayment($method, $amount, $cc);
} catch (Exception $e) {
    die_jsonp($e->getMessage());
}
echo jsonp(array('payment' => $payment, 'txn' => txn_load($db, $id), 'payments' => txn_load_payments($db, $id)));
Пример #4
0
include '../scat.php';
include '../lib/txn.php';
include '../lib/eps-express.php';
$id = (int) $_REQUEST['txn'];
$payment = (int) $_REQUEST['payment'];
if (!$id) {
    die_jsonp("Transaction not specified.");
}
if (!$payment) {
    die_jsonp("Payment to reverse from not specified.");
}
$q = "SELECT cc_txn, amount FROM payment WHERE id = {$payment}";
list($cc_txn, $cc_amount) = $db->get_one_row($q) or die_jsonp("Unable to find transaction information.");
$eps = new EPS_Express();
$response = $eps->CreditCardVoid($id, $cc_txn);
$xml = new SimpleXMLElement($response);
if ($xml->Response->ExpressResponseCode != 0) {
    die_jsonp((string) $xml->Response->ExpressResponseMessage);
}
$method = 'credit';
$cc = array();
$cc['cc_txn'] = $xml->Response->Transaction->TransactionID;
$cc['cc_approval'] = $xml->Response->Transaction->ApprovalNumber;
$cc['cc_type'] = $xml->Response->Card->CardLogo;
$txn = new Transaction($db, $id);
try {
    $payment = $txn->addPayment($method, bcmul($cc_amount, -1), $cc);
} catch (Exception $e) {
    die_jsonp($e->getMessage());
}
echo jsonp(array('payment' => $payment, 'txn' => txn_load($db, $id), 'payments' => txn_load_payments($db, $id)));
Пример #5
0
}
$method = $_REQUEST['method'];
$amount = $_REQUEST['amount'];
// validate method
if (!in_array($method, array('cash', 'credit', 'square', 'stripe', 'dwolla', 'gift', 'check', 'discount', 'bad', 'donation', 'internal'))) {
    die_jsonp("Invalid method specified.");
}
$txn = new Transaction($db, $id);
$extra = array();
// extra payment info
// handle % discounts
if ($method == 'discount') {
    if (preg_match('!^(/)?\\s*(\\d+)(%|/)?\\s*$!', $amount, $m)) {
        if ($m[1] || $m[3]) {
            $amount = round($txn->total * $m[2] / 100, 2, PHP_ROUND_HALF_EVEN);
            $extra['discount'] = $m[2];
        }
    }
}
if ($method == 'credit') {
    $cc = array();
    foreach (array('cc_txn', 'cc_approval', 'cc_lastfour', 'cc_expire', 'cc_type') as $field) {
        $extra[$field] = $_REQUEST[$field];
    }
}
try {
    $payment = $txn->addPayment($method, $amount, $extra);
} catch (Exception $e) {
    die_jsonp($e->getMessage());
}
echo jsonp(array('payment' => $payment, 'txn' => txn_load($db, $id), 'payments' => txn_load_payments($db, $id)));
Пример #6
0
 private function handleCredit($invoiceId)
 {
     //        $modelTransaction = $this->getLoader()->model('sale/transaction');
     $invoice = InvoiceDAO::getInstance()->getInvoice($invoiceId);
     //        $customer = CustomerDAO::getInstance()->getCustomer($invoice['customer_id']);
     $temp = $invoice->getCustomer();
     if ($temp['await_invoice_confirmation']) {
         InvoiceDAO::getInstance()->setInvoiceStatus($invoiceId, IS_AWAITING_CUSTOMER_CONFIRMATION);
     } else {
         $totalToPay = $this->getCurrency()->convert($invoice->getTotalCustomerCurrency(), $invoice->getCurrencyCode(), $temp['base_currency_code']);
         if ($temp['balance'] < $totalToPay) {
             if ($temp['allow_overdraft']) {
                 Transaction::addPayment($temp['customer_id'], $invoiceId, $this->registry);
                 InvoiceDAO::getInstance()->setInvoiceStatus($invoiceId, IS_PAID);
             } else {
                 InvoiceDAO::getInstance()->setInvoiceStatus($invoiceId, IS_AWAITING_PAYMENT);
             }
         } else {
             Transaction::addPayment($temp['customer_id'], $invoiceId, $this->registry);
             InvoiceDAO::getInstance()->setInvoiceStatus($invoiceId, IS_PAID);
         }
     }
     $this->getLoader()->model('tool/communication')->sendMessage($temp['customer_id'], sprintf($this->getLanguage()->get('INVOICE_STATUS_NOTIFICATION'), $this->getLoader()->model('localisation/invoice')->getInvoiceStatus($invoiceId), $this->getCurrency()->format($invoice->getTotalCustomerCurrency(), $invoice->getCurrencyCode(), 1), $this->getCurrency()->format(CustomerDAO::getInstance()->getCustomerBalance($temp['customer_id']), $temp['base_currency_code'], 1)), SYS_MSG_INVOICE_CREATED);
 }