Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // we assume the order class and all the other classes are stored
- // in a file that we can then include where we need it
- require_once "./orderclass.php";
- // tax you pay or not, should be per order not per item
- $tax = $_POST['with_gst'] === "1" ? new tax("GST", 5) : new tax();
- $order = new order($tax);
- if (isset($_POST["submit"])){
- $order->store_id = "store3";
- $order->api_token = "yesguy";
- $order->checkout_id = "chktGLFZQtore3";
- $order->environment = "qa";
- $order->action = "preload";
- foreach($_POST['quantity'] as $key => $quantity) {
- if($quantity === 0) {
- continue; // we will get the next product
- }
- // All products cost 60
- $item = new item($_POST['id'][$key], $_POST['description'][$key], 60, $_POST['quantity'][$key]);
- $order-AddItem($item);
- }
- // Add contact details
- $order->contact_details->first_name = $_POST['bill_first_name'];
- $order->contact_details->last_name = $_POST['bill_last_name'];
- $order->contact_details->email = $_POST['email'];
- $order->contact_details->phone = $_POST['bill_phone'];
- // Add billing details
- $address = new address();
- $address->address_1 = $_POST['bill_address_one'];
- $address->address_2 = $_POST['bill_address_two'];
- $address->city = $_POST['bill_city'];
- $address->province = $_POST['bill_state_or_province'];
- $address->country = "CA"; // only ship to Canada
- $address->postal_code = $_POST['bill_postal_code'];
- $order->billing_details = $address;
- if($_POST['ship_to_billing'] === "1")
- {
- $order->shipping_details = $address;
- } else {
- $order->shipping_details->address_1 = $_POST['ship_address_one'];
- $order->shipping_details->address_2 = $_POST['ship_address_two'];
- $order->shipping_details->city = $_POST['ship_city'];
- $order->shipping_details->province = $_POST['ship_state_or_province'];
- $order->shipping_details->country = "CA";
- $order->shipping_details->postal_code = $_POST['ship_postal_code'];
- }
- }
- $myObj = $arr;
- $myJSON = json_encode($order);
- echo $myJSON;
- // Prepare new cURL resource
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://gatewayt.moneris.com/chkt/request/request.php");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLINFO_HEADER_OUT, true);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $myJSON);
- $array_length = count($arr, COUNT_RECURSIVE);
- // Set HTTP Header for POST request
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json' ,'Content-Length: ' . strlen($myJSON)
- )
- );
- // Submit the POST request
- $result = curl_exec($ch);
- // Close cURL session handle
- curl_close($ch);
- print_r($arr);
- print_r($result);
- $response_data = json_decode($result);
- print_r($response_data);
- $result_data = json_decode($result, true);
- print_r($result_data);
- if( isset($result_data['response']['error']) && ( ! (bool) $result_data['response']['success'] ) ){
- echo 'error message';
- }
- $token = $result_data['response']['ticket'];
- ?>
Advertisement
Add Comment
Please, Sign In to add comment