private static function sendData($data) { $pest = new \PestJSON(Functions::BASE_URL); try { $pest->post('/import/orders.json', $data); } catch (\Pest_Json_Decode $e) { // can be safely ignored } }
public function getTokens($options) { // Generate merchant hash code $hash = \HashGenerator::generate($this->veritrans->merchant_id, $this->veritrans->merchant_hash_key, $this->veritrans->order_id); // populate parameters for the post request $data = array('version' => $this->veritrans->version, 'merchant_id' => $this->veritrans->merchant_id, 'merchanthash' => $hash, 'order_id' => $this->veritrans->order_id, 'billing_different_with_shipping' => $this->veritrans->billing_different_with_shipping, 'required_shipping_address' => $this->veritrans->required_shipping_address, 'email' => $this->veritrans->email, 'first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'city' => $this->_sanitize($this->veritrans->city, 'city'), 'country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'phone' => $this->_sanitize($this->veritrans->phone, 'phone'), 'finish_payment_return_url' => $this->veritrans->finish_payment_return_url, 'unfinish_payment_return_url' => $this->veritrans->unfinish_payment_return_url, 'error_payment_return_url' => $this->veritrans->error_payment_return_url); if ($this->veritrans->required_shipping_address && $this->veritrans->billing_different_with_shipping) { $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->shipping_first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->shipping_last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->shipping_address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->shipping_address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->shipping_city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->shipping_country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->shipping_postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->shipping_phone, 'phone'))); } else { if ($this->veritrans->required_shipping_address && !$this->veritrans->billing_different_with_shipping) { $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->phone, 'phone'))); } } $optional_features = array('enable_3d_secure', 'bank', 'installment_terms', 'promo_bins', 'point_banks', 'payment_methods', 'installment_banks'); foreach ($optional_features as $feature) { if (!is_null($this->veritrans->{$feature})) { $data[$feature] = $this->veritrans->{$feature}; } } // Populate items $data['repeat_line'] = 0; foreach ($this->veritrans->items as $item) { $item_id[] = $this->_sanitize($item['item_id'], 'itemId'); $item_name1[] = $this->_sanitize($item['item_name1'], 'itemName'); $item_name2[] = $this->_sanitize($item['item_name2'], 'itemName'); $price[] = $this->_sanitize($item['price'], 'price'); $quantity[] = $item['quantity']; $data['repeat_line']++; } $data['item_id'] = $item_id; $data['item_name1'] = $item_name1; $data['item_name2'] = $item_name2; $data['price'] = $price; $data['quantity'] = $quantity; // Call Veritrans API try { $pest = new \PestJSON(''); $result = $pest->post(self::REQUEST_KEY_URL, $data); } catch (Exception $e) { throw $e; } // Check result if (!empty($result['token_merchant'])) { // OK return $result; } else { // Veritrans doesn't return tokens $this->veritrans->errors = $result['errors']; return false; } }
/** * Request a token from the OAuth server * * @param string $code An authorization code provided by the OAuth server * @param string $tokenType Type of token being requested (IDENTITY_TOKEN|API_TOKEN) * * @return void Updates session variables * * @throws OAuthNegotiator_Exception TOKEN_RESPONSE if a token no token is received or on any other uanticipated response from the OAuth server **/ private function requestToken($code, $tokenType) { $authApi = new PestJSON("{$_SESSION[self::SESSION][self::OAUTH_ENDPOINT]}"); try { $response = $authApi->post('token', array(self::CLIENT_ID => $_SESSION[self::SESSION][self::CLIENT_ID], self::REDIRECT_URI => $_SESSION[self::SESSION][self::REDIRECT_URI], self::STATE => self::$SCOPES[$tokenType][self::TOKEN_PROVIDED], self::CLIENT_SECRET => $_SESSION[self::SESSION][self::CLIENT_SECRET], self::CODE => $code)); } catch (Pest_ServerError $e) { echo $e->getMessage(); exit; } if ($response) { if (isset($response['access_token'])) { $_SESSION[self::SESSION][self::TOKEN] = $response['access_token']; return true; } else { throw new OAuthNegotiator_Exception('Access token not received', OAuthNegotiator_Exception::TOKEN_RESPONSE); } } else { throw new OAuthNegotiator_Exception('Unexpected OAuth response', OAuthNegotiator_Exception::TOKEN_RESPONSE); } }
//Update login user if ($_POST['login_user'] != $login_user) { $sth = $dbcore->prepare("UPDATE EMAIL SET LOGIN_USER = ? WHERE ID = '0'"); $sth->bindParam(1, $_POST['login_user']); $sth->execute(); $updates .= '"Login User" '; } // Update auth password if ($_POST["password"] != "nochange" && strlen($_POST["password"]) > 0) { // do passwords match ? if ($_POST["password"] != $_POST["password2"]) { throw new Exception('Passwords do not match!'); } //Connect to internal webservice $pest = new PestJSON('http://127.0.0.1:5380'); $authhash = $pest->post('/api/v1.0/crypto/encrypt/', array('string' => $_POST["password"])); // insert into DB $sth = $dbcore->prepare("UPDATE EMAIL SET LOGIN_PASS = ? WHERE ID = '0'"); $sth->bindParam(1, $authhash['result']); $sth->execute(); $updates .= '"Login User Password" '; } //Reset vars to new (or keep as old) values // If exception happens on any item new values // will get thrown out (never makes it here) $enabled = $_POST['enabled']; $sender = $_POST['sender']; $sender_title = $_POST['sender_title']; $recipients = $_POST['recipients']; $subject = $_POST['subject']; $hide = $_POST['hide'];
public static function pageSlurp() { require_once CART66_PATH . "/models/Pest.php"; require_once CART66_PATH . "/models/PestJSON.php"; $page_id = Cart66Common::postVal('page_id'); $page = get_page($page_id); $slurp_url = get_permalink($page->ID); $html = false; $job_id = $slurp_url; if (wp_update_post(array('ID' => $page->ID, 'post_status' => 'publish'))) { $access_key = Cart66Setting::getValue('mijireh_access_key'); $rest = new PestJSON(MIJIREH_CHECKOUT); $rest->setupAuth($access_key, ''); $data = array('url' => $slurp_url, 'page_id' => $page->ID, 'return_url' => add_query_arg('task', 'mijireh_page_slurp', $slurp_url)); try { $response = $rest->post('/api/1/slurps', $data); $job_id = $response['job_id']; } catch (Pest_Unauthorized $e) { header('Bad Request', true, 400); die; } } else { $job_id = 'did not update post successfully'; } echo $job_id; die; }
public function initCheckout($amount) { $cart = Cart66Session::get('Cart66Cart'); $tax = $this->getTaxAmount(); $order = array('return_url' => Cart66Common::appendWurlQueryString('task=mijireh_notification'), 'tax' => $tax, 'shipping' => $cart->getShippingCost(), 'discount' => $cart->getDiscountAmount(), 'subtotal' => $cart->getSubTotal(), 'total' => number_format($cart->getGrandTotal() + $tax, 2, '.', ''), 'items' => array()); // Prepare the shipping address if it is available if (strlen($this->_shipping['address']) > 3) { $order['shipping_address'] = array('first_name' => $this->_shipping['firstName'], 'last_name' => $this->_shipping['lastName'], 'street' => $this->_shipping['address'], 'apt_suite' => $this->_shipping['address2'], 'city' => $this->_shipping['city'], 'state_province' => $this->_shipping['state'], 'zip_code' => $this->_shipping['zip'], 'country' => $this->_shipping['country'], 'phone' => $this->_payment['phone']); } // Add shipping method and promotion code as meta_data $order['meta_data'] = array('shipping_method' => Cart66Session::get('Cart66Cart')->getShippingMethodName(), 'coupon' => Cart66Common::getPromoMessage(), 'custom-field' => $this->_payment['custom-field']); // Add logged in users id to the meta_data for membership product upgrades/extensions $account_id = Cart66Common::isLoggedIn(); if ($account_id) { $order['meta_data']['account_id'] = $account_id; } // Add coupon code as meta_data foreach ($cart->getItems() as $key => $item) { $sku = $item->getItemNumber(); $order_item_data = array('sku' => $sku, 'name' => $item->getFullDisplayName(), 'price' => $item->getProductPrice(), 'quantity' => $item->getQuantity()); if ($custom_desc = $item->getCustomFieldDesc()) { $order_item_data['name'] .= "\n" . $custom_desc; } if ($custom_info = $item->getCustomFieldInfo()) { $order_item_data['name'] .= "\n" . $custom_info; } $order['items'][$key] = $order_item_data; $option_info = trim($item->getOptionInfo()); if (!empty($option_info)) { $order['meta_data']['options_' . $sku] = $option_info; } if ($item->hasAttachedForms()) { $form_ids = $item->getFormEntryIds(); if (is_array($form_ids) && count($form_ids)) { $form_ids = implode(',', $form_ids); $order['meta_data'][$key]['gforms_' . $sku] = $form_ids; } } } // DBG /* echo "<pre>"; print_r($order); echo "</pre>"; die(); */ try { //Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Sending Order To Mijireh" . print_r($order, true)); $access_key = Cart66Setting::getValue('mijireh_access_key'); $rest = new PestJSON(MIJIREH_CHECKOUT); $rest->setupAuth($access_key, ''); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Sending Order To Mijireh: " . print_r($order, true)); $result = $rest->post('/api/1/orders', $order); wp_redirect($result['checkout_url']); //wp_redirect(MIJIREH_CHECKOUT . '/checkout/' . $result['order_number']); exit; } catch (Pest_Unauthorized $e) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] REST Request Failed because it was unauthorized: " . $e->getMessage()); $this->response['error_message'] = __("Your Mijireh Access key is invalid, please check your access settings and try again", "cart66"); $this->response['error_code'] = 1; if (strlen($this->_shipping['address']) < 3) { $gatewayResponse = $this->getTransactionResponseDescription(); $exception = Cart66Exception::exceptionMessages(66500, __('Your order could not be processed for the following reasons:', 'cart66'), array('error_code' => 'Error: ' . $gatewayResponse['errorcode'], strtolower($gatewayResponse['errormessage']))); echo Cart66Common::getView('views/error-messages.php', $exception); } } catch (Exception $e) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] REST Request Failed: " . $e->getMessage()); } }
private function send($endpoint, $operation, $request) { $pest = new PestJSON($this->url); $pest->setupAuth($this->username, $this->password); $pest->curl_opts[CURLOPT_FOLLOWLOCATION] = false; // Not supported on hosts running safe_mode! $pest->curl_opts[CURLOPT_HTTPHEADER] = "Content-Type: application/json"; $pest->curl_opts[CURLOPT_USERAGENT] = $this->USER_AGENT . " (v" . $this->CLIENT_VERSION . ")"; $response = ""; try { // Send request to rest service switch ($operation) { case $this->OP_PUT: $response = $pest->put("/{$endpoint}", $request); break; case $this->OP_GET: $response = $pest->get("/{$endpoint}", $request); break; case $this->OP_POST: $response = $pest->post("/{$endpoint}", $request); break; case $this->OP_DELETE: $response = $pest->delete("/{$endpoint}", $request); break; } } catch (Exception $e) { echo "Caught exception when sending request : " . $e->getMessage(); } return $response; }
$error = "Login Failed."; } } else { // other user login // What auth mode is set ? $sth = $dbh->prepare("SELECT MODE FROM AUTH"); $sth->execute(); $mode = $sth->fetchColumn(); switch ($mode) { case "ad": // AD auth mode // Make ad call to API require_once '/opt/f5backup/ui/include/PestJSON.php'; $data = array('user' => $_POST["username"], 'passwd' => $_POST["password"]); $pest = new PestJSON('http://127.0.0.1:5380'); $auth = $pest->post('/api/v1.0/adauth/authenticate/', $data); // Valid login if ($auth['result'] == "True") { // Get auth groups $sth = $dbh->query("SELECT STRING,ROLE FROM AUTHGROUPS ORDER BY ORD"); $sth->execute(); $groups = $sth->fetchAll(); //lowercase memberOf array $membership = array_map("strtolower", $auth['memberOf']); //loop through list until match is found foreach ($groups as $i) { $string = strtolower($i['STRING']); // If auth group is in user's group membership allow login if (preg_grep("/{$string}/", $membership)) { $login = 1; $role = $i['ROLE'];