public function show($id = null) { if (isset($_GET['id'])) { $id = $_GET['id']; } if (!$id) { Error404(); } $payment = PaymentTransaction::find_by_id($id); if (!$payment) { Error404(); } $cart = Cart::find_by_id($payment->cart_id); if ($cart) { $user = User::find_by_id($cart->user_id); $this->assign("user", $user); $this->assign("cart", $cart); } $this->assign("payment", $payment); $this->title = "Payment {$payment->id}"; $this->render("paymenttransaction/show.tpl"); }
<?php ini_set('display_errors', 1); error_reporting(E_ALL & ~E_STRICT); require_once 'init.php'; /* $services = array( (object) array( 'name' => 'My Service' ), (object) array( 'name' => 'Another Thing' ) ); $payment = PaymentTransaction::find_by_id(3059); $data = (array) $payment->processResponse; Email::send_topup_complete($data, 'IPN OK'); die(); */ $ids = array(3279, 3278, 3277, 3276); foreach ($ids as $id) { $payment = PaymentTransaction::find_by_id($id); $data = (array) $payment->processResponse; Email::send_payment_complete($data, $data['Status'], $payment->cart); }
<?php require_once 'init.php'; ini_set('display_errors', 1); //1826 $transaction = PaymentTransaction::find_by_id(1); Email::send_user_paymentconfirmation($transaction);
public static function _processPayment($gateway, $postData) { // Process according to SagePay $paymentTransaction = null; if (isset($_POST['VendorTxCode'])) { $paymentTransaction = PaymentTransaction::find_by_id($postData['VendorTxCode']); } if (!$paymentTransaction) { throw new PGI_SagePay_ProcessException('Unable to find a payment matching ' . $postData['VendorTxCode']); } if ($paymentTransaction->status == 'ptsTaken') { $params = array('Status' => 'OK', 'StatusDetail' => "Payment for {$paymentTransaction->cart}", 'RedirectURL' => "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->cart->id}/complete"); $output = ''; foreach ($params as $key => $value) { $output .= "{$key}={$value}\r\n"; } return $output; } if ($paymentTransaction->status != 'ptsSubmitted') { throw new PGI_SagePay_ProcessException("{$paymentTransaction} is in state {$paymentTransaction->status}", $paymentTransaction, $notify); } // Validate response if (!isset($postData['VPSTxId'])) { throw new PGI_SagePay_ProcessException('No transaction ID from SagePay'); } if ($paymentTransaction->externalid != $postData['VPSTxId']) { throw new PGI_SagePay_ProcessException("{$postData['VPSTxId']} does not match the transaction ID in " . $paymentTransaction, $paymentTransaction); } $fields = array('VPSTxId', 'VendorTxCode', 'Status', 'TxAuthNo', 'VendorName', 'AVSCV2', 'SecurityKey', 'AddressResult', 'PostCodeResult', 'CV2Result', 'GiftAid', '3DSecureStatus', 'CAVV', 'AddressStatus', 'PayerStatus', 'CardType', 'Last4Digits', 'DeclineCode', 'ExpiryDate', 'FraudResponse', 'BankAuthCode'); $sig = ''; foreach ($fields as $name) { switch ($name) { case 'SecurityKey': $sig .= $paymentTransaction->initialResponse->SecurityKey; break; case 'VendorName': $sig .= $gateway->getSetting('vendor'); break; default: $sig .= $postData[$name]; break; } } $sig = strtoupper(md5($sig)); if ($sig != $postData['VPSSignature']) { throw new PGI_SagePay_ProcessException("Signatures do not match, found {$sig}, expecting {$postData['VPSSignature']}", $paymentTransaction); } $url = "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->id}/failed"; $paymentTransaction->processResponse = $postData; // Determine our correct response switch ($postData['Status']) { case 'OK': $url = "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->cart->id}/complete"; $cart = Cart::find_by_id($paymentTransaction->cart->id); $paymentTransaction->status = 'ptsTaken'; if ($postData['CardType'] == 'PAYPAL') { $paymentTransaction->method = 'PayPal'; } else { $cardName = 'Credit Card'; $lookup = array('VISA' => 'Visa', 'DELTA' => 'Visa Debit', 'UKE' => 'Visa Electron', 'MC' => 'Mastercard', 'SWITCH' => 'UK Maestro', 'MAESTRO' => 'Maestro', 'AMEX' => 'American Express', 'DINERS' => 'Diners Club', 'JCB' => 'JCB', 'LASER' => 'LASER', 'PAYPAL' => 'PayPal'); if (isset($lookup[$postData['CardType']])) { $cardName = $lookup[$postData['CardType']]; } $paymentTransaction->method = "{$cardName} (Ending in {$postData['Last4Digits']})"; } $paymentTransaction->save(); Email::send_user_paymentconfirmation($paymentTransaction); // Mark cart as paid, this will trigger the event signup // email to the user. $cart->mark_paid(null, "SagePay"); // Email staff about payment Email::send_payment_complete($postData, $postData['Status'], $cart); // And alert on Twitter $account = TwitterAccount::find_by_code('site'); if ($account) { $signups = $cart->get_signups(); $eventsignups = array(); foreach ($signups as $signup) { $amount = sprintf("%.2f", $signup->event_ticket->cost / 100); $paidsignups = count($signup->event->participants("paid")); $message = "{$signup->user->nickname} has paid for {$signup->event->name} {$signup->event_ticket->name} [£{$amount}] ({$paidsignups}/{$signup->event->capacity}) [{$signup->id}]"; $account->add_tweet($message); } } break; case 'ABORT': $paymentTransaction->status = 'ptsCancelled'; $paymentTransaction->failurereason = $postData['StatusDetail']; break; default: $paymentTransaction->status = 'ptsFailed'; $paymentTransaction->failurereason = $postData['StatusDetail']; break; } $paymentTransaction->save(); $params = array('Status' => 'OK', 'StatusDetail' => "Payment for {$paymentTransaction->cart}", 'RedirectURL' => $url); $output = ''; foreach ($params as $key => $value) { $output .= "{$key}={$value}\r\n"; } return $output; }