static function getInstance() { $q = new QIWI(array('shopID' => sfConfig::get('app_qiwi_shop_id'), 'password' => sfConfig::get('app_qiwi_password'), 'lifetime' => sfConfig::get('app_qiwi_lifetime'), 'txn-prefix' => '', 'encrypt' => true, 'url' => sfConfig::get('app_qiwi_url'), 'create-client' => sfConfig::get('app_qiwi_create_client'), 'create-agt' => 0, 'alarm-sms' => sfConfig::get('app_qiwi_alarm_sms'), 'alarm-call' => sfConfig::get('app_qiwi_alarm_call'), 'log' => sfConfig::get('app_qiwi_log'))); $q->setRequester(new QIWICurlRequester()); $q->setEncrypter(new QIWIMcryptEncrypter()); if (!function_exists('simplexml_load_string')) { return null; } return $q; }
static function getInstance($config) { $q = new QIWI($config); if (function_exists('curl_init')) { $q->setRequester(new QIWICurlRequester()); } else { if (function_exists('QueryGetData')) { $q->setRequester(new QIWIBitrixRequester()); } else { $q->setRequester(new QIWISocketRequester()); } } if (function_exists('mcrypt_encrypt')) { $q->setEncrypter(new QIWIMcryptEncrypter()); } else { $q->setEncrypter(new QIWINativeEncrypter()); } if (!function_exists('simplexml_load_string')) { return NULL; } return $q; }
public function executeCreate() { $invoice = $this->getRoute()->getObject(); $invoice->setTransactionId(time() + rand(1, 99) . $invoice->getId()); $invoice->setPaymentSystem('qiwi'); $invoice->save(); $qiwi = QIWI::getInstance(); try { $result = $qiwi->createBill(array('phone' => substr($invoice->getUser()->getProfile()->getMobilePhone(), -10, 10), 'amount' => Currency::convertByAbbr($invoice->getAmount(), 'RUR'), 'comment' => $invoice->getDescription(), 'txn-id' => $invoice->getTransactionId())); if ($result) { $this->redirect('payment_qiwi_success'); } else { $this->redirect('payment_qiwi_fail'); } } catch (QIWIMortalCombatException $e) { $this->redirect('payment_qiwi_fail'); } }
protected function execute($arguments = array(), $options = array()) { new sfDatabaseManager($this->configuration); $invoices = Doctrine::getTable('Invoice')->createQuery('a')->where('a.is_paid = 0')->andWhere('a.payment_system = ?', 'qiwi')->execute(); $this->logSection('invoices found', $invoices->count()); $qiwi = QIWI::getInstance(); $bills = array(); foreach ($invoices as $invoice) { $bills[$invoice->getTransactionId()] = $invoice; } if (count($bills)) { $result = $qiwi->billStatus(array_keys($bills)); foreach ($result as $billId => $billStatus) { if ($billStatus['status'] == QIWI::STATUS_PAID) { $bills[$billId]->doPay($billStatus); $this->logSection('success', '#' . $bills[$billId]->getId()); } } } }
/* * QIWI Rest PHP - Simple library * * Copyright 2013 - 2015 EasyCoding Team (ECTeam). * Copyright 2005 - 2015 EasyCoding Team. * * License: GNU GPL version 3. * * EasyCoding Team's official blog: http://www.easycoding.org/ * */ //Connecting main class require_once "qiwi.class.php"; //Starting the QIWI class - ShopID, Rest API ID, Rest API Password $shop = new QIWI("123456", "12345678", "StrongPassword1"); //Setting parameters to create a new invoice $shop->setInvoiceID(123); //The unique identifier of the account that is used on your website - up to 200 characters $shop->setPhone("+79123456789"); //The Visa QIWI Wallet user’s ID, to whom the invoice is issued $shop->setAmount(120); //The invoice amount - rounded up to 2 or 3 decimal places after the comma $shop->setCurency("RUB"); //Invoice currency identifier (Alpha-3 ISO 4217 code) $shop->setComment("Creating a test invoice by using the QIWI REST PHP library by EC Team"); //Comment to the invoice which is shown on the payment page $shop->setLifeTime(120); //Еime up to which the invoice is available for payment. Enter the number of seconds to count down from the current time or date+time in UNIX format $shop->setPaySource(QCONST::QIWI); //Set the way to pay the invoice. QCONST::QIWI - to pay using QIWI website or QCONST::MOBILE to pay with mobile phone bills
function action_status() { //1) Выбираем новые платежи квики $q = QIWI::getInstance($this->qiwiConfig); $invoice_list = DB::select("id")->from('invoice')->where('status', '=', 'N')->where('payment_id', '=', 2)->execute()->as_array(); $i_request = array(); foreach ($invoice_list as $i) { $i_request[] = $i['id']; } $q_result = $q->billStatus($i_request, true); $email = ""; foreach ($q_result as $id => $v) { if ($v['status'] != 60) { continue; } // не оплачен $content = "Order:{$id}\nAmount:{$v['amount']}\nDetails: " . print_r($v, true) . "\n\n"; $status = "success"; try { $invoice = ORM::factory('invoice', $id); if (!$invoice->loaded()) { throw new Exception("Cannot find invoice (" . $id . ")"); } // проверяем фактические параметры if (floatval($invoice->amount) != floatval($v['amount'])) { throw new Exception("Payment Data error ({$v['amount']} != {$invoice->amount})"); } // проверяем статус платежа - чтоб не проплачивать уже проведенные платежи if ($invoice->status != 'N') { throw new Exception("Invoice already processed (" . $invoice->status . ")"); } $user = ORM::factory('user', $invoice->user_id); if (!$user->loaded()) { throw new Exception("Cannot find user (" . $invoice->user_id . ")"); } // если у пользователя просрочен аккаунт - в качестве начальной даты ставим текущую. // в противном случае - дату макс. срока (если захотели докупить)!! $old_value = $user->expires; if (empty($user->expires) || Date::diff($user->expires) <= 0) { $user_date = new DateTime(); } else { $user_date = new DateTime($user->expires); } $user_date->modify("+ " . intval($invoice->days_amount) . " days"); $user->expires = $user_date->format("Y-m-d 23:59:59"); $user->user_type = 'service'; $invoice->status = 'P'; // оплачен $invoice->modify_date = Date::formatted_time('now', "Y-m-d H:i:s"); $invoice->update(); $user->update(); DB::insert('payment_log', array('user_id', 'type', 'old_value', 'new_value', 'cdate'))->values(array($invoice->user_id, "-", $old_value, $user->expires, Date::formatted_time()))->execute(); } catch (Exception $e) { $status = 'error'; $content .= $e->getMessage(); } DB::insert('invoice_log', array('invoice_id', 'status', 'content', 'cdate'))->values(array($id, $status, $content, Date::formatted_time()))->execute(); $email .= "<br>{$content}<br><hr><br>\n"; } if (!empty($email)) { // Email::send('*****@*****.**', array('*****@*****.**', 'Ассоциация автосервисов'), $feedback->title, $email_view, TRUE); Email::send('*****@*****.**', array('*****@*****.**', 'Ассоциация автосервисов'), "Уведопление об платежах QIWI", $email, TRUE); Email::send('*****@*****.**', array('*****@*****.**', 'Ассоциация автосервисов'), "Уведопление об платежах QIWI", $email, TRUE); } exit; }