public function failed() { $id = $this->getData('id'); if (!$id) { Site::Flash('error', 'Your payment was not successful'); Redirect(); } $id = mysql_real_escape_string($id); $user = mysql_real_escape_string(Site::CurrentUser()->id); $transaction = PaymentTransaction::find("paymenttransactions.id = '{$id}' AND carts.user_id = '{$user}'"); if (!$transaction) { throw new Error404('Unable to find the payment'); } switch ($transaction->status) { case 'ptsTaken': Redirect("payments/{$transaction->cart_id}/complete"); break; case 'ptsCancelled': Site::Flash('error', "Your payment has been cancelled"); break; default: Site::Flash('error', 'Your payment was not successful'); break; } Redirect("bookings/pay/{$transaction->cart_id}"); }
public function getPaymentTransaction($baseuri = null) { // Try and find a valid payment transaction for this cart $id = mysql_real_escape_string($this->id); $hash = mysql_real_escape_string($this->hash); $amount = round($this->cost(true, false) / 100, 2); $escapedAmount = mysql_real_escape_string($amount); $transaction = PaymentTransaction::find("paymenttransactions.cart_id = '{$id}' AND paymenttransactions.amount = '{$escapedAmount}' AND paymenttransactions.status IN ('ptsNew', 'ptsTaken') AND paymentgateways.enabled = 1"); if (!$transaction) { $transaction = new PaymentTransaction(); $transaction->amount = $amount; $transaction->hash = $this->hash; $transaction->cart = $this; $transaction->cart_id = $this->id; $transaction->paymentgateway = PaymentGateway::getActive(); $transaction->paymentgateway_id = $transaction->paymentgateway->id; $transaction->baseuri = $baseuri; if (!$transaction->save()) { throw new Error500('Unable to create payment transaction'); } } return $transaction; }
$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': case 'Refunded': case 'Reversed': $status = 'ptsTaken'; break; case 'Failed': case 'Denied': $status = 'ptsFailed'; break;