コード例 #1
0
ファイル: sfGuardUser.class.php プロジェクト: sensorsix/app
 public function getLastNotPayedTransaction($type)
 {
     $payment = Doctrine_Query::create()->from('PaymentTransaction')->where('user_id = ? AND type = ?', array($this->id, '"' . $type . '"'))->andWhere('is_payed = ?', false)->andWhere('date_payed IS NULL')->orderBy('id DESC')->fetchOne();
     if (!$payment) {
         $payment = new PaymentTransaction();
         $payment->user_id = $this->id;
         $payment->type = $type;
         $payment->save();
     }
     $price_list = PaymentTransaction::getPriceList();
     $payment->amount = $price_list[$type];
     return $payment;
 }
コード例 #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
ファイル: Global_pay.php プロジェクト: Rudianasaja/cycommerce
 public function regPaymentTransaction($order)
 {
     $pay = new PaymentTransaction();
     $pay->type = self::NAME;
     $pay->transaction_date = date('Y-m-d H:i:s');
     $pay->reference_number = $order['payment_code'];
     $pay->response_description = '';
     $pay->response_code = 'pending';
     $pay->transaction_amount = $order['total'];
     //$pay->transaction_currency = UtilityHelper::yiiparam('currencyText'); NEED TO WORK AROUND THIS
     $pay->transaction_currency = 'NGN';
     $pay->customer_name = $order['firstname'] . ' ' . $order['lastname'];
     $pay->order_id = $order['id'];
     $pay->save();
 }
コード例 #4
0
ファイル: Paga.php プロジェクト: Rudianasaja/cycommerce
 public function regPaymentTransaction($order)
 {
     $onlinePaymentOptions = OnlinePaymentOptions::model()->findByAttributes(array('name' => $this->getPaymentName()));
     $resultSet = OnlinePaymentSettings::model()->findAllByAttributes(array('online_payment_options_id' => $onlinePaymentOptions->id));
     foreach ($resultSet as $result) {
         $settings[$result->field] = $result->value;
     }
     $pay = new PaymentTransaction();
     $pay->type = $pay->type = self::NAME;
     $pay->transaction_date = date('Y-m-d H:i:s');
     $pay->reference_number = $order['payment_code'];
     $pay->response_code = 'pending';
     $pay->transaction_amount = $order['total'];
     //$pay->transaction_currency = UtilityHelper::yiiparam('currencyText'); NEED TO WORK AROUND THIS
     $pay->transaction_currency = $settings['currency'];
     $pay->customer_name = $order['firstname'] . ' ' . $order['lastname'];
     $pay->order_id = $order['id'];
     $pay->save();
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 public function cart_payment()
 {
     $id = "";
     if ($this->GetData('id')) {
         $id = $this->GetData('id');
     }
     $user_id = mysql_real_escape_string(Site::CurrentUser()->id);
     $cart = Cart::find("carts.user_id = {$user_id} AND carts.id = {$id}");
     if ($cart->paid) {
         Site::Flash('error', 'The cart has already been paid');
         RedirectBack('bookings');
     }
     $cart->check_discounts();
     if ($cart->cost() != 0) {
         Site::Flash('error', 'This cart still needs to be paid for');
         RedirectBack('bookings');
     }
     if ($cart->full_cart_discount()) {
         $id = mysql_real_escape_string($cart->id);
         $redemptions = DiscountRedemption::find_all("discount_redemptions.cart_id='{$id}' and discount_redemptions.cart_item_id IS NULL");
     }
     // Log the payment
     $gateway = PaymentGateway::find_by_code('discount');
     $payment = new PaymentTransaction();
     $payment->cart_id = $cart->id;
     $payment->externalid = (string) $redemptions[0];
     $payment->paymentgateway_id = $gateway->id;
     $payment->status = 'ptsTaken';
     $payment->amount = $cart->cost() / 100;
     $payment->sender = Site::CurrentUser()->email;
     $payment->save();
     $cart->mark_paid($payment, 'Discount');
     // Email staff about payment
     Email::send_payment_complete(array(), "", $cart, $redemptions);
     Redirect("payments/{$id}/complete");
 }
コード例 #7
0
ファイル: paypal.php プロジェクト: ItsHaden/epicLanBootstrap
 /**
  * Processes an IPN request.
  * 
  * @param type $postData HTTP POST data from the request
  * @return string Any output for the notification page
  */
 public static function processPayment($gateway, $postData)
 {
     $responseData = array_merge(array('cmd' => '_notify-validate'), $postData);
     $qs = http_build_query($responseData);
     $curl = curl_init($gateway->getSetting('endpoint'));
     global $config;
     if ($config['dev'] or true) {
         // Paypal sandbox certificate is apparently invalid
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     }
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $qs);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($curl);
     curl_close($curl);
     if (!isset($postData['transaction_subject'])) {
         // No transaction subject
     }
     $ref = explode("-", $postData['custom']);
     if (count($ref) < 2) {
         return;
     }
     $type = $ref[0];
     $id = $ref[1];
     if ($type != 'cart') {
         // Not a cart, nothing to do here
         return;
     }
     $id = mysql_real_escape_string($id);
     $cart = Cart::find_by_id($id);
     $payment = new PaymentTransaction();
     $payment->processResponse = $postData;
     $payment->paymentgateway_id = $gateway->id;
     $payment->amount = $postData['mc_gross'];
     $payment->externalid = $postData['txn_id'];
     $payment->status = 'ptsFailed';
     $payment->sender = $postData['payer_email'];
     $payment->method = "PayPal ({$postData['payer_email']})";
     if (!$cart) {
         // Cart not found
         $payment->failurereason = "Transaction specified a cart, but the cart was not found";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response);
         return;
     }
     $cart->check_discounts();
     // Make Payment Object
     $payment->cart_id = $cart->id;
     if ($response != 'VERIFIED') {
         // IPN response is not verified
         $payment->failurereason = "The transaction was not verified";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     if ($postData['payment_status'] != "Completed") {
         // Payment status is not completed
         $payment->failurereason = "Payment status is not completed";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     if ($postData['receiver_email'] != $gateway->getSetting('email')) {
         // Sent to the wrong email
         $payment->failurereason = "Payment was sent to a different email address";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     $total = $cart->cost() + $cart->card_fee();
     if ($postData['mc_gross'] * 100 < $total) {
         // Cart is not enough
         $payment->failurereason = "Payment was not enough for the cart";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     if ($cart->paid) {
         // Cart is already marked paid
         $payment->failurereason = "The cart has already been paid for";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     // Payment is valid and for the right amount for our cart!
     $payment->status = 'ptsTaken';
     $payment->save();
     Email::send_user_paymentconfirmation($payment);
     // Mark cart as paid, this will trigger the event signup
     // email to the user.
     $cart->mark_paid($payment, "Paypal");
     // Email staff about payment
     Email::send_payment_complete($postData, $response, $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);
         }
     }
 }
コード例 #8
0
ファイル: sagepay.php プロジェクト: ItsHaden/epicLanBootstrap
 /**
  * Initialises a payment for the supplied payment transaction using SagePay.
  * Returns a URL to redirect the user to (normally a hosted payment form).
  * 
  * @param PaymentTransaction $paymentTransaction The payment transaction we've created
  * @return string The URL to forward the user to 
  */
 public static function initialisePayment($paymentTransaction)
 {
     if ($paymentTransaction->status == 'ptsSubmitted') {
         return $paymentTransaction->initialResponse->NextURL;
     }
     // Generate a unique TX code
     $cart = $paymentTransaction->cart;
     $user = User::find_by_id($cart->user_id);
     $gateway = $paymentTransaction->paymentgateway;
     $paymentTransaction->sender = $user->email;
     // We need to build the basket data
     $basket = '';
     $count = 0;
     // Item Discounts
     foreach ($cart->items() as $item) {
         $count++;
         $amount = self::formatMoney($item->initial_cost());
         $desc = str_replace(':', '', $item->description);
         $basket .= ":{$desc}:1:::{$amount}:{$amount}";
         if ($item->discount->id) {
             $item->discount->reload();
             $count++;
             if ($item->discount->discount->type == "percentage") {
                 $amount = self::formatMoney($item->discount->discount->calculate_saving($item->initial_cost()));
             } else {
                 $amount = self::formatMoney($item->discount->discount->value);
             }
             $desc = str_replace(':', '', "{$item->discount->discount->code}) {$item->discount->discount->description}");
             $basket .= ":{$desc}:1:::-{$amount}:-{$amount}";
         }
     }
     // Full Cart Discounts
     if ($cart->full_cart_discount()) {
         foreach ($cart->discounts(true) as $discount) {
             if ($discount->cart_item_id) {
                 continue;
             }
             $count++;
             if ($discount->discount->type == "percentage") {
                 $amount = self::formatMoney($discount->discount->calculate_saving($cart->cost(0, 1)));
             } else {
                 $amount = self::formatMoney($discount->discount->value);
             }
             $desc = str_replace(':', '', "Discount ({$discount->discount->code}) {$discount->discount->description}");
             $basket .= ":{$desc}:1:::-{$amount}:-{$amount}";
         }
     }
     $basket = "{$count}{$basket}";
     // Prepare our parameters
     $params = array('VPSProtocol' => '3.00', 'TxType' => 'PAYMENT', 'Vendor' => $gateway->getSetting('vendor'), 'VendorTxCode' => $paymentTransaction->id, 'Amount' => $paymentTransaction->getFormattedAmount(), 'Currency' => 'GBP', 'Description' => "epic.LAN Cart {$cart->id}", 'NotificationURL' => $gateway->getSetting('notificationurl'), 'BillingSurname' => $user->surname, 'BillingFirstnames' => $user->firstname, 'BillingAddress1' => $user->address1, 'BillingAddress2' => $user->address2, 'BillingCity' => $user->towncity, 'BillingPostCode' => $user->postcode, 'BillingCountry' => strtoupper($user->country->code), 'DeliverySurname' => $user->surname, 'DeliveryFirstnames' => $user->firstname, 'DeliveryAddress1' => $user->address1, 'DeliveryAddress2' => $user->address2, 'DeliveryCity' => $user->towncity, 'DeliveryPostCode' => $user->postcode, 'DeliveryCountry' => strtoupper($user->country->code), 'Basket' => $basket);
     if (strtoupper($user->country->code) == 'US') {
         $params['BillingState'] = $user->county;
         $params['DeliveryState'] = $user->county;
     }
     // Make our request
     $url = $gateway->getSetting('endpoint');
     $output = self::httpPost($url, $params);
     // Parse the response
     $lines = explode("\r\n", $output);
     $response = new stdClass();
     foreach ($lines as $line) {
         $line = explode('=', $line);
         $key = array_shift($line);
         $response->{$key} = implode('=', $line);
     }
     if (property_exists($response, 'VPSTxId')) {
         $paymentTransaction->externalid = $response->VPSTxId;
     }
     $paymentTransaction->initialResponse = $response;
     if ($response->Status == 'OK') {
         $paymentTransaction->status = 'ptsSubmitted';
         $paymentTransaction->save();
         return $response->NextURL;
     }
     $paymentTransaction->failurereason = $response->StatusDetail;
     $paymentTransaction->status = 'ptsFailed';
     $paymentTransaction->save();
     throw new PGI_Exception('Unable to establish payment session');
 }
コード例 #9
0
 /**
  * Creates a new payment transaction.
  * @param array $attributes
  * @return PaymentTransaction
  * @throws CException
  */
 public static function create(array $attributes)
 {
     $model = new PaymentTransaction();
     $model->attributes = $attributes;
     $model->userIdentifier = isset($attributes['userIdentifier']) ? $attributes['userIdentifier'] : Yii::app()->user->id;
     $model->locale = isset($attributes['locale']) ? $attributes['locale'] : Yii::app()->language;
     if (!$model->save()) {
         throw new CException('Failed to save payment transaction.');
     }
     return $model;
 }
コード例 #10
0
        $method = "PayPal ({$payment->sender})";
    }
    $response = array('notes' => $payment->extra);
    if ($payment->method == 'Paypal') {
        $response = unserialize($payment->extra);
    }
    $t = new PaymentTransaction();
    $t->cart_id = $payment->cart_id;
    $t->paymentgateway_id = $gateway->id;
    $t->status = $status;
    $t->failurereason = '';
    $t->amount = $payment->amount;
    if (!$t->amount) {
        $t->amount = 0;
    }
    $t->externalid = $payment->transaction_id;
    $t->processResponse = $response;
    $t->sender = $payment->sender;
    $t->method = $method;
    $result = $t->save();
    if ($result) {
        $newID = mysql_real_escape_string($t->id);
        $timestamp = $payment->created_at;
        mysql_query("UPDATE paymenttransactions SET created_at = FROM_UNIXTIME('{$timestamp}'), updated_at = FROM_UNIXTIME('{$timestamp}') WHERE id = '{$newID}' LIMIT 1");
        echo "Added {$payment}\r\n";
    } else {
        echo "Failed to add {$payment}\r\n";
        print_r($t);
    }
}
file_put_contents($filename, $last);