Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class token {
- public $data_key;
- public $issuer_id;
- }
- class recur {
- public $bill_now;
- public $recur_amount;
- public $start_date;
- public $recur_unit;
- public $recur_period;
- public $number_of_recurs;
- }
- class item {
- public $url;
- public $description;
- public $product_code;
- public $unit_cost;
- public $quantity;
- }
- class tax {
- public $amount;
- public $description;
- public $rate;
- }
- class cart {
- function __construct() {
- $this->tax = new tax();
- }
- public $items = array(); // for item objects
- public $subtotal;
- public $tax;
- }
- class contactdetails {
- public $first_name;
- public $last_name;
- public $email;
- public $phone;
- }
- class address {
- public $address_1;
- public $address_2;
- public $city;
- public $province;
- public $country;
- public $postal_code;
- }
- class order {
- function __construct() {
- // just to simply init things for you
- $this->recur = new recur();
- $this->cart = new cart();
- $this->contact_details = new contactdetails();
- $this->shipping_details = new address();
- $this->billing_details = new address();
- }
- public $store_id;
- public $api_token;
- public $checkout_id;
- public $txn_total;
- public $environment;
- public $action;
- public $token = array(); // for token objects
- public $ask_cvv;
- public $order_no;
- public $cust_id;
- public $dynamic_descriptor;
- public $language;
- public $recur;
- public $cart;
- public $contact_details;
- public $shipping_details;
- public $billing_details;
- }
- $order = new order();
- // To add new items do, we assume $itemid is posted together with $quantity
- // $item = new item();
- // $item->url = "https://domain.example.net/item/$itemid";
- // $item->description = fetch_item_description_from_db($itemid);
- // $item->product_code = $itemid;
- // $item->unit_cost = fetch_item_unit_cost_from_db($itmeid);
- // $item->quantity = $quantity;
- // don't forget to calculate the tax and add it to the $order->cart->tax->amount
- // update also $order->txn_total and also $order->cart->subtotal
- // $order->cart->items[] = $item;
- // we add two tokens
- $token1 = new token();
- $token1->data_key = "1234";
- $token1->issuer_id = "645sddfvdrt4tefd";
- $order->token[] = $token1;
- $token2 = new token();
- $token2->data_key = "5678";
- $token2->issuer_id = "645sddfvdrt4tefd";
- $order->token[] = $token2;
- // we add two items, we do not update other values in this example
- $item1 = new item();
- $item1->product_code = "1";
- $item1->url = "https://example.net/item?id=1";
- $item1->description = "item 1";
- $item1->unit_cost = "100";
- $item1->quantity = "1";
- $order->cart->items[] = $item1;
- $item2 = new item();
- $item2->product_code = "2";
- $item2->url = "https://example.net/item?id=2";
- $item2->description = "item 2";
- $item2->unit_cost = "200";
- $item2->quantity = "1";
- $order->cart->items[] = $item2;
- echo json_encode($order, JSON_PRETTY_PRINT);
- echo "\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment