<?php require_once '../../../web_construction_set/autoload.php'; $proxy = new \WebConstructionSet\ContentModifier\Proxy($_SERVER['QUERY_STRING']); $mod = new \WebConstructionSet\ContentModifier\Proxy\Modifier\Html(); $mod->base(function ($href) { $href = preg_replace('/^\\s+/', '', $href); if (preg_match('~^\\w+://~', $href)) { return $href; } if (preg_match('~^//~', $href)) { return $href; } if (preg_match('~^/~', $href)) { return \WebConstructionSet\Url\Tools::makeServerUrl($_SERVER['QUERY_STRING']) . $href; } if ($href) { return dirname($_SERVER['QUERY_STRING']) . '/' . $href; } return $_SERVER['QUERY_STRING']; }); $jq = new \WebConstructionSet\ContentModifier\JQuery(); $mod->addScript(null, $jq->getJs('jQuery_proxy')); $mod->addScript(\WebConstructionSet\Url\Tools::getNeighbourUrl('proxy.js')); $proxy->addModifier($mod); $proxy->run();
/** * @param [integer] $ids * @return [][id => integer, key => integer, time => integer, invnum => integer, amt => double, currencycode => string, token => string, url => string] */ public function getTransactions($ids = null) { $fields = ['id', 'user_key', 'time', 'invnum', 'amt', 'currencycode', 'token']; if ($ids === null) { $data = $this->transactions->select($fields); } else { $data = []; foreach ($ids as $id) { $data1 = $this->transactions->select($fields, ['id' => $id]); if ($data1) { $data[] = $data1[0]; } } } foreach ($data as &$data1) { $data1['key'] = $data1['user_key']; unset($data1['user_key']); $data1['url'] = \WebConstructionSet\Url\Tools::addParams($this->redirectUrl, ['token' => $data1['token']]); } return $data; }
/** * @param string $orderNumber * @param double $amount * @param string $currency * @param boolean $subscription recurring payments * @param [key => value] $addParams * @return integer|null Transaction ID */ public function initiateTransaction($orderNumber, $amount, $currency, $subscription = false, $addParams = []) { $transaction = ['time' => time(), 'order_number' => $orderNumber, 'amount' => $amount, 'currency' => $currency]; $params = ['Merchant_ID' => $this->merchantId, 'OrderNumber' => $orderNumber, 'OrderAmount' => $amount, 'OrderCurrency' => $currency, 'URL_RETURN' => \WebConstructionSet\Url\Tools::getMyUrl()]; if ($subscription) { $params['RecurringIndicator'] = 1; $params['RecurringMinAmount'] = 0.01; $params['RecurringMaxAmount'] = 1000; $params['RecurringPeriod'] = 1; $params['RecurringMaxDate'] = date('d.m.Y', time() + 86400 * 365 * 2); $transaction['recurring'] = 1; } $params = array_merge($params, $addParams); $data = md5($this->secretWord) . md5($params['Merchant_ID'] . ';' . $params['OrderNumber'] . ';' . $params['OrderAmount'] . ';' . $params['OrderCurrency']); $checkvalue = strtoupper(md5(strtoupper($data))); $params['Checkvalue'] = $checkvalue; if ($this->secretKey) { $data = md5($params['Merchant_ID'] . ';' . $params['OrderNumber'] . ';' . $params['OrderAmount'] . ';' . $params['OrderCurrency'], true); if (!openssl_sign($data, $signature, $this->secretKey)) { error_log(new \ErrorException('openssl_sign failed, order_number: ' . $orderNumber, null, null, __FILE__, __LINE__)); return null; } $signature = base64_encode($signature); $params['Signature'] = $signature; } $result = $this->call('/pay/order.cfm', $params, true); if (!$result || !isset($result['location'])) { error_log(new \ErrorException('Location is missing, result: ' . json_encode($result), null, null, __FILE__, __LINE__)); return null; } $transaction['url'] = $result['location']; if (strpos($transaction['url'], '://') === false) { $transaction['url'] = 'https://' . $this->server . $transaction['url']; } if (preg_match('/ErrorID=/', $transaction['url'])) { $data = @file_get_contents($transaction['url'], false); error_log(new \ErrorException('Url contains error description, order_number: ' . $orderNumber . ', transaction: ' . json_encode($transaction) . ', result: ' . json_encode($result) . ', data: ' . $data, null, null, __FILE__, __LINE__)); return null; } $params = ['Merchant_ID' => $this->merchantId, 'Login' => $this->login, 'Password' => $this->password, 'Format' => 3, 'OrderNumber' => $orderNumber]; $result = $this->call('/orderstate/orderstate.cfm', $params, false); if (!$result) { return null; } if (!isset($result['order'])) { error_log(new \ErrorException('Order is missing, result: ' . json_encode($result), null, null, __FILE__, __LINE__)); return null; } $order = $result['order']; $checkvalue = md5($this->secretWord) . md5($this->merchantId . $order['ordernumber'] . $order['orderamount'] . $order['ordercurrency'] . $order['orderstate']); $checkvalue = strtoupper(md5(strtoupper($checkvalue))); if ($checkvalue != $order['checkvalue']) { error_log(new \ErrorException('checkvalue mismatch, computed: ' . $checkvalue . ', actual: ' . $order['checkvalue'] . ', result: ' . json_encode($result), null, null, __FILE__, __LINE__)); return null; } $transaction['bill_number'] = $order['billnumber']; if ($order['orderstate'] != 'In Process') { error_log(new \ErrorException('Bad order state, order: ' . json_encode($order), null, null, __FILE__, __LINE__)); return null; } return $this->transactions->insert($transaction); }
<?php require_once '../../../web_construction_set/autoload.php'; $authData = ['client_id' => \Config::CLIENT_ID, 'client_secret' => \Config::CLIENT_SECRET, 'scope' => \Config::SCOPE, 'redirect_uri' => \WebConstructionSet\Url\Tools::getMyUrlName()]; $oauth = new \WebConstructionSet\Accounting\OAuth\Google($authData); if ($oauth->process()) { $token = $oauth->getToken(); $error = $oauth->getError(); ?> <html><body> Token: <?php echo $token; ?> <br/> Error: <?php echo $error; ?> <br/> </body></html> <?php }
<?php require_once '../../../web_construction_set/autoload.php'; if (empty($_GET['client_customer_id']) && empty($_GET['callback'])) { ?> <html><body> <form> <a href="https://support.google.com/adwords/answer/29198" target="blank">Client Customer Id</a>:<input type="text" name="client_customer_id" value="000-000-0000"/> <input type="submit" value="Get"/> </form> </body></html> <?php } else { $authData = ['client_id' => \Config::CLIENT_ID, 'client_secret' => \Config::CLIENT_SECRET, 'scope' => 'https://www.googleapis.com/auth/adwords', 'redirect_uri' => \WebConstructionSet\Url\Tools::getMyUrlName() . '?callback=1']; $auth = new \WebConstructionSet\Accounting\OAuth\Google($authData); if (isset($_GET['client_customer_id'])) { $auth->setState(['client_customer_id' => $_GET['client_customer_id']]); } if ($auth->process()) { header('Content-Type: text/plain'); if ($auth->getError()) { echo 'Error: ', $auth->getError(); } else { $authData['access_token'] = $auth->getToken(); $clientCustomerId = $auth->getState()['client_customer_id']; $strings = new \WebConstructionSet\Advertising\CampaignStrings\Google($authData, \Config::DEVELOPER_TOKEN, \Config::COMPANY_NAME, $clientCustomerId); echo implode("\n", $strings->get()); } } }