コード例 #1
0
 public function index()
 {
     $gateways = PaymentGateway::find_all('', 'paymentgateways.position ASC');
     $this->assign('gateways', $gateways);
     $this->title = 'Payment Gateways';
     $this->render('paymentgateway/index.tpl');
 }
コード例 #2
0
 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');
 }
コード例 #3
0
<?php

require_once 'init.php';
ini_set('display_errors', 1);
$limit = 500;
$filename = "lastid.txt";
$last = 0;
if (file_exists($filename)) {
    $last = file_get_contents($filename);
}
$last = mysql_real_escape_string($last);
$total = Payment::count("payments.id > '{$last}'");
$payments = Payment::find_all("payments.id > '{$last}'", "payments.id ASC", $limit);
$count = count($payments);
$allGateways = PaymentGateway::find_all();
foreach ($allGateways as $gateway) {
    $gateways[$gateway->code] = $gateway;
}
$gwLookup = array('BACS' => 'bacs', 'Cash' => 'manual', 'Discount' => 'discount', 'Other' => 'manual', 'Paypal' => 'paypal');
echo "Processing {$count} / {$total} payments\r\n\r\n";
foreach ($payments as $payment) {
    $last = $payment->id;
    $transactionid = mysql_real_escape_string($payment->transaction_id);
    $transaction = PaymentTransaction::find("paymenttransactions.externalid = '{$transactionid}'");
    if ($transaction) {
        continue;
    }
    $gateway = $gateways[$gwLookup[$payment->method]];
    switch ($payment->status) {
        case 'Completed':
        case 'PAID':