/** * Constructor * * @param Interkassa_Shop $shop * @param array $source the data source to use, e.g. $_POST. * * @throws Interkassa_Exception if some data not received, received shop id * does not match current shop id or received * signature is invalid */ public function __construct(Interkassa_Shop $shop, array $source) { $this->_shop = $shop; foreach (array('ik_co_id' => 'Shop id', 'ik_pm_no' => 'Payment id', 'ik_am' => 'Payment amount', 'ik_desc' => 'Payment description', 'ik_pw_via' => 'Payway Via', 'ik_sign' => 'Payment Signature', 'ik_cur' => 'Currency', 'ik_inv_prc' => 'Payment Time', 'ik_inv_st' => 'Payment State', 'ik_trn_id' => 'Transaction', 'ik_ps_price' => 'PaySystem Price', 'ik_co_rfn' => 'Checkout Refund') as $field => $title) { if (!isset($source[$field])) { throw new Interkassa_Exception($title . ' not received'); } } $received_id = strtoupper($source['ik_co_id']); $shop_id = strtoupper($shop->getId()); if ($received_id !== $shop_id) { throw new Interkassa_Exception('Received shop id does not match current shop id'); } if ($this->_checkSignature($source)) { $this->_verified = true; } else { throw new Interkassa_Exception('Signature does not match the data'); } $payment = $shop->createPayment(array('id' => $source['ik_pm_no'], 'amount' => $source['ik_am'], 'description' => $source['ik_desc'])); if (!empty($source['ik_x_baggage'])) { $payment->setBaggage($source['ik_x_baggage']); } $this->_payment = $payment; $this->_timestamp = $source['ik_inv_prc']; $this->_state = (string) $source['ik_inv_st']; $this->_trans_id = (string) $source['ik_trn_id']; $this->_currency = $source['ik_cur']; $this->_fees_payer = $source['ik_ps_price'] - $source['ik_co_rfn']; }
private function viewInterkassa() { if (!extension::getInstance()->getConfig('balance_use_ik', 'user', extension::TYPE_COMPONENT, 'boolean')) { exit("Interkassa API disabled"); } $post_kasa_id = system::getInstance()->post('ik_co_id'); if ($post_kasa_id != extension::getInstance()->getConfig('balance_ik_id', 'user', extension::TYPE_COMPONENT, 'str')) { exit("undefined id"); } require_once root . '/resource/payments/interkassa2/interkassa.php'; Interkassa::register(); $shop = Interkassa_Shop::factory(array('id' => extension::getInstance()->getConfig('balance_ik_id', 'user', extension::TYPE_COMPONENT, 'str'), 'secret_key' => extension::getInstance()->getConfig('balance_ik_key', 'user', extension::TYPE_COMPONENT, 'str'))); try { $status = $shop->receiveStatus(system::getInstance()->post(null)); // POST is used by default } catch (Interkassa_Exception $e) { logger::getInstance()->log(logger::LEVEL_WARN, "Interkassa payment check signature fail. From ip: " . system::getInstance()->getRealIp() . ", post_data : " . json_encode(system::getInstance()->post(null))); header('HTTP/1.0 400 Bad Request'); exit; } $payment = $status->getPayment(); $mul_c = extension::getInstance()->getConfig('balance_ik_mul', 'user', extension::TYPE_COMPONENT, 'float'); $user_id = system::getInstance()->toInt($payment->getId()); $amount = (double) $payment->getAmount(); $amount *= $mul_c; user::getInstance()->addBalance($user_id, $amount); $payparam = array('currency' => $payment->getCurrency(), 'amount' => $amount, 'sys_invs_id' => system::getInstance()->post('ik_inv_id'), 'sys_trans_id' => system::getInstance()->post('ik_trn_id'), 'date' => system::getInstance()->post('ik_inv_prc')); user::getInstance()->putLog($user_id, 'balance.ikadd', $payparam, 'Recharge balance via interkassa'); }