public function updatePayment() { $request = Ajde::app()->getRequest(); $username = $request->getParam('Username'); $password = $request->getParam('Password'); $id = $request->getParam('ID'); $secret = $request->getParam('Reference'); $paymentMethod = $request->getParam('PaymentMethod'); $state = $request->getParam('PaymentState'); $description = $request->getParam('Description'); if ($username != config('shop.transaction.wedeal.callbackUsername')) { Ajde_Log::log('Invalid username for callback of transaction ' . $secret); return false; } if ($password != config('shop.transaction.wedeal.callbackPassword')) { Ajde_Log::log('Invalid password for callback of transaction ' . $secret); return false; } $transaction = new TransactionModel(); if (!$transaction->loadByField('secret', $secret)) { Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } $request = ['type' => 'query', 'merchant' => ['username' => config('shop.transaction.wedeal.username'), 'password' => config('shop.transaction.wedeal.password'), 'reference' => $secret]]; // Pause a little before request is made to allow for processing on provider // as this request will be made synchronously after payment sleep(3); $res = $this->sendRequest($request); if ($res['success'] === true) { $response = $res['response']->paymentinfo; $count = (int) $res['response']->count; // get transaction details if ($count == 0) { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('iDeal callback didn\'t return any transaction for ' . $secret); } elseif (self::isPaid((string) $response->state)) { if ((string) $response->id != $id) { Ajde_Log::log('IDs don\'t match for iDeal callback of transaction ' . $secret); } else { $details = 'AMOUNT: ' . (string) $response->amount . PHP_EOL . 'PAYER_NAME: ' . (string) $response->consumername . PHP_EOL . 'PAYER_ACCOUNT: ' . (string) $response->consumeraccount . PHP_EOL . 'PAYER_CITY: ' . (string) $response->consumercity . PHP_EOL . 'PAYER_COUNTRY: ' . (string) $response->consumercountry . PHP_EOL . 'WEDEAL_ID: ' . (string) $response->id; $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); return ['success' => true, 'transaction' => $transaction]; } } elseif (self::isRefused((string) $response->state)) { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('iDeal payment refused with state ' . (string) $response->state); } else { Ajde_Log::log('iDeal payment callback called with state ' . (string) $response->state . ' but no status change for transaction ' . $secret . ' detected'); } } else { Ajde_Log::log('Wedeal::updatePayment() failed because: ' . $res['response']); } return ['success' => false, 'transaction' => $transaction]; }
public function updatePayment() { $request = Ajde::app()->getRequest(); $username = $request->getParam('Username'); $password = $request->getParam('Password'); $id = $request->getParam('ID'); $secret = $request->getParam('Reference'); $paymentMethod = $request->getParam('PaymentMethod'); $state = $request->getParam('PaymentState'); $description = $request->getParam('Description'); if ($username != Config::get('shopWedealCallbackUsername')) { Ajde_Log::log('Invalid username for callback of transaction ' . $secret); return false; } if ($password != Config::get('shopWedealCallbackPassword')) { Ajde_Log::log('Invalid password for callback of transaction ' . $secret); return false; } Ajde_Model::register('shop'); $transaction = new TransactionModel(); if (!$transaction->loadByField('secret', $secret)) { Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } $request = array("type" => 'query', "merchant" => array("username" => Config::get('shopWedealUsername'), "password" => Config::get('shopWedealPassword'), "reference" => $secret)); $res = $this->sendRequest($request); if ($res['success'] === true) { $response = $res['response']->paymentinfo; // get transaction details if ((int) $response->count == 0) { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('iDeal callback didn\'t return any transaction for ' . $secret); return false; } elseif (self::isPaid((string) $response->state)) { if ((string) $response->id != $id) { Ajde_Log::log('IDs don\'t match for iDeal callback of transaction ' . $secret); return false; } $details = 'AMOUNT: ' . (string) $response->amount . PHP_EOL . 'PAYER_NAME: ' . (string) $response->consumername . PHP_EOL . 'PAYER_ACCOUNT: ' . (string) $response->consumeraccount . PHP_EOL . 'PAYER_CITY: ' . (string) $response->consumercity . PHP_EOL . 'PAYER_COUNTRY: ' . (string) $response->consumercountry . PHP_EOL . 'WEDEAL_ID: ' . (string) $response->id; $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); return true; } elseif (self::isRefused((string) $response->state)) { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log("iDeal payment refused with state " . (string) $response->state); return false; } Ajde_Log::log("iDeal payment callback called with state " . (string) $response->state . " but no status change for transaction " . $secret . " detected"); return false; } else { Ajde_Log::log("Wedeal::updatePayment() failed because: " . $res['response']); return false; } }
public function onTransactionPaid(TransactionModel $transaction) { /** @var TransactionItemModel $item */ foreach ($transaction->getItems() as $item) { $entity = $item->getEntity(); $qty = $item->qty; if ($entity instanceof ProductModel) { $entity->stock = $entity->stock - $qty; $entity->save(); } } }
public function updatePayment() { $txn_id = $_GET['txn']; $transaction = new TransactionModel(); $transaction->loadByPK($txn_id); $result = (bool) $_GET['r']; if ($result) { $transaction->payment_status = 'requested'; $transaction->save(); return ['success' => true, 'changed' => true, 'transaction' => $transaction]; } else { return ['success' => false, 'changed' => true, 'transaction' => $transaction]; } }
public function checkout() { Ajde_Model::register($this); // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function markPaidJson() { $id = Ajde::app()->getRequest()->getPostParam('id', false); $transaction = new TransactionModel(); if (!is_array($id)) { $id = [$id]; } $c = 0; foreach ($id as $elm) { $transaction->loadByPK($elm); if ($transaction->payment_status !== 'completed') { $transaction->paid(); $c++; } } return ['success' => true, 'message' => Ajde_Component_String::makePlural($c, 'transaction') . ' marked as paid']; }
public function updatePayment() { // PHP 4.1 // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; $post = Ajde_Http_Request::globalPost(); foreach ($post as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // post back to PayPal system to validate $header = ''; $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= 'Content-Length: ' . strlen($req) . "\r\n\r\n"; $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables to local variables $item_name = issetor($post['item_name']); $item_number = issetor($post['item_number']); $payment_status = issetor($post['payment_status']); $payment_amount = issetor($post['mc_gross']); $payment_currency = issetor($post['mc_currency']); $txn_id = issetor($post['txn_id']); $receiver_email = issetor($post['receiver_email']); $payer_email = issetor($post['payer_email']); $secret = issetor($post['custom']); $transaction = new TransactionModel(); $changed = false; if (!$fp) { // HTTP ERROR } else { fwrite($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, 'VERIFIED') == 0) { if (!$transaction->loadByField('secret', $secret)) { Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); return ['success' => false, 'transaction' => null]; } // check the payment_status is Completed // accept Pending from PayPal (eChecks?) $acceptPending = true; if ($payment_status == 'Completed' || $acceptPending && $payment_status == 'Pending') { $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL; // update transaction only once if ($transaction->payment_status != 'completed') { $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); $changed = true; } // Write pending to Log if ($payment_status == 'Pending') { Ajde_Log::log('Status is Pending but accepting now. PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } return ['success' => true, 'changed' => $changed, 'transaction' => $transaction]; } else { if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else { if (strcmp($res, 'INVALID') == 0) { if (!$transaction->loadByField('secret', $secret)) { // secret not found anyway $transaction = null; Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } else { // log for manual investigation if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id); } } } } fclose($fp); } return ['success' => false, 'changed' => $changed, 'transaction' => $transaction]; }
public function chargeMoneyAction() { $params = $this->_arrParam; Zend_Loader::loadClass('TransactionModel'); $transaction_model = new TransactionModel(); $transaction_model->updateAppota($params); exit("ok"); }
public function updatePayment() { // PHP 4.1 // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // post back to PayPal system to validate $header = ''; $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen($this->isSandbox() ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; Ajde_Model::register('shop'); $secret = $_POST['custom']; $transaction = new TransactionModel(); if (!$transaction->loadByField('secret', $secret)) { Ajde_Log::log('Could not find transaction for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } if (!$fp) { // HTTP ERROR } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { // check the payment_status is Completed if ($payment_status == 'Completed') { $details = 'AMOUNT: ' . $payment_amount . PHP_EOL . 'CURRENCY: ' . $payment_currency . PHP_EOL . 'PAYER_EMAIL: ' . $payer_email . PHP_EOL . 'RECEIVER_EMAIL: ' . $receiver_email . PHP_EOL . 'TXN_ID: ' . $txn_id . PHP_EOL; $transaction->payment_details = $details; $transaction->payment_status = 'completed'; $transaction->save(); } else { $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('Status is not Completed but ' . $payment_status . ' for PayPal payment with txn id ' . $txn_id . ' and transaction secret ' . $secret); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment } else { if (strcmp($res, "INVALID") == 0) { // log for manual investigation $transaction->payment_status = 'refused'; $transaction->save(); Ajde_Log::log('Validation failed for PayPal payment with txn id ' . $txn_id); } } } fclose($fp); } }
public function mailUpdateAdmin(TransactionModel $transaction, $subject = null) { $recipient = config('app.email'); $mailer = new Ajde_Mailer(); $mailer->SendQuickMail($recipient, $recipient, config('app.title'), isset($subject) ? $subject : 'Order update', $transaction->getOverviewHtml()); }
public function __construct() { parent::__construct(); }
public function getGiftPreparations($giftid) { $this->db->select('gp.GiftPreparationID, p.PreparationID, co.CollectionObjectID, co.CatalogNumber, pt.Name AS PrepType, p.CountAmt AS Quantity, pa.Text1 AS DuplicateString'); $this->db->from('giftpreparation gp'); $this->db->join('preparation p', 'gp.PreparationID=p.PreparationID'); $this->db->join('preptype pt', 'p.PrepTypeID=pt.PrepTypeID'); $this->db->join('preparationattribute pa', 'p.PreparationAttributeID=pa.PreparationAttributeID'); $this->db->join('collectionobject co', 'p.CollectionObjectID=co.CollectionObjectID'); $this->db->where('gp.giftID', $giftid); $query = $this->db->get(); if ($query->num_rows()) { $giftpreps = array(); foreach ($query->result() as $row) { $giftprep = new GiftPreparation(); $giftprep->GiftPreparationID = $row->GiftPreparationID; $giftprep->PreparationID = $row->PreparationID; $giftprep->CatalogNumber = $row->CatalogNumber; $giftprep->PrepType = $row->PrepType; $giftprep->Quantity = $row->Quantity; $giftprep->DuplicateString = $row->DuplicateString; $giftprep->TaxonName = parent::getFormattedNameString($row->CollectionObjectID); if ($other = $this->getOtherGiftInfo($row->PreparationID)) { $giftprep->QuantitySent = $other->QuantitySent; $giftprep->DuplicatesSentTo = $other->DuplicatesSentTo; } $giftpreps[] = $giftprep; } return $giftpreps; } else { return FALSE; } }
public function checkout() { // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); // Can we skip this step? if (!$transaction->hasLoaded() && !config('shop.offerLogin') && $cart->hasItems()) { $this->redirect('shop/transaction:setup'); } $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }
public function updatePayment() { $payment = false; $mollie = new Mollie_API_Client(); $mollie->setApiKey($this->getApiKey()); $transaction = new TransactionModel(); $changed = false; // see if we are here for the webhook or user return url $mollie_id = Ajde::app()->getRequest()->getPostParam('id', false); // from webhook $order_id = Ajde::app()->getRequest()->getParam('order_id', false); // from user request if (!$mollie_id && $order_id) { // load from order_id $transaction->loadByField('secret', $order_id); $mollie_id = $transaction->payment_providerid; try { $payment = $mollie->payments->get($mollie_id); } catch (Mollie_API_Exception $e) { Ajde_Exception_Log::logException($e); $payment = false; } } else { if ($mollie_id) { // laod from mollie transaction id try { $payment = $mollie->payments->get($mollie_id); $order_id = $payment->metadata->order_id; $transaction->loadByField('secret', $order_id); } catch (Mollie_API_Exception $e) { Ajde_Exception_Log::logException($e); $payment = false; } } } if (!$payment || !$mollie_id || !$order_id || !$transaction->hasLoaded()) { Ajde_Log::log('Could not find transaction for Mollie payment for mollie id ' . $mollie_id . ' and transaction secret ' . $order_id); return ['success' => false, 'changed' => $changed, 'transaction' => $transaction]; } // what to return? $paid = false; $payment_details = $payment->details; if (is_object($payment_details) || is_array($payment_details)) { $payment_details = json_encode($payment_details); } // save details $details = 'PAYMENT STATUS: ' . (string) $payment->status . PHP_EOL . 'PAYMENT AMOUNT: ' . (string) $payment->amount . PHP_EOL . 'PAYMENT AT: ' . (string) $payment->paidDatetime . PHP_EOL . 'CANCELLED AT: ' . (string) $payment->cancelledDatetime . PHP_EOL . 'EXPIRED AT: ' . (string) $payment->expiredDatetime . PHP_EOL . 'PAYER DETAILS: ' . (string) $payment_details; $transaction->payment_details = $details; switch ($payment->status) { case 'open': if ($transaction->payment_status != 'requested') { $transaction->payment_status = 'requested'; $transaction->save(); $changed = true; } break; case 'paidout': case 'paid': $paid = true; // update transaction only once if ($transaction->payment_status != 'completed') { $transaction->paid(); $changed = true; } break; case 'cancelled': // update transaction only once if ($transaction->payment_status != 'cancelled') { $transaction->payment_status = 'cancelled'; $transaction->save(); $changed = true; } break; case 'expired': // update transaction only once if ($transaction->payment_status != 'refused') { $transaction->payment_status = 'refused'; $transaction->save(); $changed = true; } break; } return ['success' => $paid, 'changed' => $changed, 'transaction' => $transaction]; }
public function paymentJson() { $request = Ajde::app()->getRequest(); $provider = $request->getPostParam('provider', false); if (empty($provider)) { return array('success' => false, 'message' => __('Please choose a payment provider')); } // Check for current transaction Ajde_Model::register($this); $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { if ($transaction->payment_status !== 'pending') { return array('success' => false, 'message' => __('Payment already initiated, please refresh this page')); } } else { return array('success' => false, 'message' => __('No current transaction found')); } $transaction->payment_provider = $provider; $provider = $transaction->getProvider(); $redirectUrl = $provider->getRedirectUrl(); if ($redirectUrl !== false) { $transaction->payment_status = 'requested'; $transaction->save(); $cart = new CartModel(); $cart->loadCurrent(); $cart->emptyItems(); if ($provider->usePostProxy()) { $this->setAction('postproxy'); $proxy = $this->getView(); $proxy->assign('provider', $provider); return array('success' => true, 'postproxy' => $proxy->render()); } return array('success' => true, 'redirect' => $redirectUrl); } return array('success' => false, 'message' => 'Could not contact the payment provider, please try again'); }
function __construct() { parent::Model(); // connect to database $this->load->database(); }