$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = $this->parseHeader(substr($output, 0, $header_size)); $body = substr($output, $header_size); curl_close($ch); //Print the response header var_dump($header); /* If we get any of this X-GGe4-Content-SHA1 X-GGe4-Date Authorization * then the API call is valid */ if (isset($header['authorization'])) { //Ovbiously before we do anything we should validate the hash var_dump(json_decode($body)); } else { echo $body; } } private function parseHeader($rawHeader) { $header = array(); //http://blog.motane.lu/2009/02/16/exploding-new-lines-in-php/ $lines = preg_split('/\\r\\n|\\r|\\n/', $rawHeader); foreach ($lines as $key => $line) { $keyval = explode(': ', $line, 2); if (isset($keyval[0]) && isset($keyval[1])) { $header[strtolower($keyval[0])] = $keyval[1]; } } return $header; } } $firstdata = new FirstData(); $firstdata->request();
<?php require_once 'config.php'; require_once 'FirstData.class.php'; $cc = new FirstData($postingURL, $store, $userID, $password, $sslCert, $sslKey, $sslKeyPass); $cc->setCardInfo('V', '4111111111111111', '12', '2014', '123'); $cc->setTotals(1.01); $cc->setBillingInfo(array('name' => 'Test Name', 'addr1' => '123 Fake St.', 'city' => 'City', 'state' => 'AZ', 'country' => 'US', 'zip' => '85080')); if ($cc->systemCheckAPI()) { echo "System Alive<br/><br/>\n\n"; } else { die('The System Is Down: http://youtu.be/hXhjQn_gssI'); } $charged = $cc->chargeIt(); if ($charged['approved']) { echo "Sale Approved!<br /><br/>\n\n"; echo 'Transaction Time: ' . $charged['transactionTime'] . "<br/>\n"; echo 'Order ID: ' . $charged['oid'] . "<br/>\n"; echo 'Reference: ' . $charged['reference'] . "<br/>\n"; echo 'Approval Code: ' . $charged['approvalCode']; } else { echo "Sale Declined: " . $charged['errorMessage'] . "<br/><br/>\n\n"; echo 'Transaction Time: ' . $charged['transactionTime']; }
<?php /* * @author PrestaShop SA <*****@*****.**> * @copyright 2007-2013 PrestaShop SA * @version Release: $Revision: 1.2 $ * * International Registered Trademark & Property of PrestaShop SA */ require_once dirname(__FILE__) . '/../../config/config.inc.php'; require_once dirname(__FILE__) . '/../../init.php'; require_once dirname(__FILE__) . '/firstdata.php'; $firstData = new FirstData(); if ($firstData->active) { $firstData->validation(); }
/** * Checkout */ public function checkout() { $output = ''; if ($_SERVER['REQUEST_METHOD'] != 'POST') { $output = $this->_checkout_step_1(); } else { //valid helper include 'classes/valid.class.php'; $valid = new Valid(); //validation class include 'classes/validation.class.php'; $step = $_POST['step']; if ($step == '1') { //step 1 validation $post = new Validation($_POST['order']); $post->add_rules('first_name', 'required'); $post->add_rules('last_name', 'required'); $post->add_rules('company', 'required'); $post->add_rules('address', 'required'); $post->add_rules('city', 'required'); $post->add_rules('state', 'required'); $post->add_rules('country', 'required'); $post->add_rules('zip', 'required'); $post->add_rules('phone', 'required', array($valid, 'phone')); $post->add_rules('email', 'required', array($valid, 'email')); if (!isset($_POST['billing_is_shipping'])) { $post->add_rules('ship_first_name', 'required'); $post->add_rules('ship_last_name', 'required'); $post->add_rules('ship_company', 'required'); $post->add_rules('ship_address', 'required'); $post->add_rules('ship_city', 'required'); $post->add_rules('ship_state', 'required'); $post->add_rules('ship_country', 'required'); $post->add_rules('ship_zip', 'required'); $post->add_rules('ship_phone', 'required', array($valid, 'phone')); } $post->pre_filter('trim'); //success, go to step 2 if ($post->validate()) { //save order data $_SESSION['order'] = $_POST['order']; $output = $this->_checkout_step_2(); } else { $errors = $post->errors(); $output = $this->_checkout_step_1($_POST, $errors); } } elseif ($step == '2') { //step 2 validation $post = new Validation($_POST['order']); $post->add_rules('cc_name', 'required'); $post->add_rules('cc_type', 'required'); $post->add_rules('cc_number', 'required', array($valid, 'credit_card')); $post->add_rules('cc_cvv', 'required', 'length[3,4]', array($valid, 'digit')); $post->add_rules('cc_exp_month', 'required'); $post->add_rules('cc_exp_year', 'required'); if (isset($_POST['order']['cc_exp_month']) && isset($_POST['order']['cc_exp_year'])) { $post->add_callbacks('cc_exp_year', array($this, '_validate_cc_exp_date')); } $post->pre_filter('trim'); if ($post->validate()) { $cart = new Cart('shopping_cart'); //order data array $order_arr = array_merge($_SESSION['order'], $_POST['order']); $full_cc_number = $order_arr['cc_number']; $order_arr['cc_number'] = substr($order_arr['cc_number'], -4); $order_arr['promo_discount'] = $cart->getDiscount($order_arr['promo_code']); $order_arr['subtotal'] = $cart->getTotal(); $order_arr['tax'] = $cart->getTax(); //process payment include 'merchants/firstdata.class.php'; $merchant = new FirstData(); //billing info $merchant->name = $order_arr['first_name'] . ' ' . $order_arr['last_name']; $merchant->company = $order_arr['company']; $merchant->address = $order_arr['address']; $merchant->address2 = $order_arr['address2']; $merchant->city = $order_arr['city']; $merchant->state = $order_arr['state']; $merchant->country = $order_arr['country']; $merchant->phone = $order_arr['phone']; $merchant->fax = $order_arr['fax']; $merchant->email = $order_arr['email']; $merchant->zip = $order_arr['zip']; //shipping info $merchant->ship_name = $order_arr['ship_first_name'] . ' ' . $order_arr['ship_last_name']; $merchant->ship_address = $order_arr['ship_address']; $merchant->ship_saddress2 = $order_arr['ship_address2']; $merchant->ship_city = $order_arr['ship_city']; $merchant->ship_state = $order_arr['ship_state']; $merchant->ship_country = $order_arr['ship_country']; $merchant->ship_zip = $order_arr['ship_zip']; //payment info $merchant->cc_number = $full_cc_number; $merchant->cc_exp_month = $order_arr['cc_exp_month']; $merchant->cc_exp_year = substr($order_arr['cc_exp_year'], -2); $merchant->cc_cvv = $order_arr['cc_cvv']; $merchant->subtotal = $order_arr['subtotal']; $merchant->shipping = 0; $merchant->tax = $order_arr['tax']; $merchant->total = $order_arr['subtotal'] + $order_arr['tax'] - $order_arr['promo_discount']; // set to GOOD for test or LIVE $merchant->result = 'LIVE'; $merchant_success = false; $result = $merchant->sale(); if ($result['r_approved'] == "APPROVED") { $merchant_success = true; } //merchant error if (!$merchant_success) { $errors = $post->errors(); $this->set_flash($result['r_error'], 'error'); $output = $this->_checkout_step_2($_POST, $errors); } else { //save order to database $record = Record::insert('ecommerce_order', $order_arr); $order_id = Record::lastInsertId(); //save order items to database foreach ($cart->getItems() as $variant_id => $quantity) { //get variant data $variant = Record::findByIdFrom('ProductVariant', $variant_id); $variant->order_id = $order_id; $variant->quantity = $quantity; $variant_arr = (array) $variant; //remove unneeded fields unset($variant_arr['id']); unset($variant_arr['created_on']); unset($variant_arr['updated_on']); unset($variant_arr['position']); //insert $record = Record::insert('ecommerce_order_variant', $variant_arr); } //save log $this->_insert_log('Order <a href="' . get_url('plugin/ecommerce/order_show/' . $order_id) . '">' . $order_id . '</a> was placed.'); //send emails to client and buyer $this->_send_order_email('*****@*****.**', $order_id, $order_arr, $variant_arr); $this->_send_order_email($order_arr['email'], $order_id, $order_arr, $variant_arr); //success $this->set_flash('Thank you for your order. You will receive a confirmation email shortly.', 'success'); //clear cart and order session unset($_SESSION['order']); unset($_SESSION['Cart']); } } else { $errors = $post->errors(); $output = $this->_checkout_step_2($_POST, $errors); } } } return $output; }