From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
But in testng I am gettingHealth Study","product_code":"AHS-1298","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}},{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Pesticide Applicator
[{"store_id":"store3","api_token":"yesguy","checkout_id":"chkt23NGFtore3","txn_total":"126.00","environment":"qa","action":"preload"},[{"cart":[[[{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Agricultural
How can I carefully strip unnecessary punctuation?
doctor@doctor.nl2k.ab.ca (The Doctor) writes:
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
What you pasted as what you "need" is not even valid JSON and has a huge number of pointless spaces in it making it almost unreadable (in my news client).
Health Study","product_code":"AHS-1298","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}},{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Pesticide ApplicatorBut in testng I am getting
[{"store_id":"store3","api_token":"yesguy","checkout_id":"chkt23NGFtore3","txn_total":"126.00","environment":"qa","action":"preload"},[{"cart":[[[{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Agricultural
How can I carefully strip unnecessary punctuation?
But that one is (a) valid and (b) has no unnecessary punctuation, so I
don't know what it is you mean.
Ben Bacarisse, 2023-02-01 17:09:
doctor@doctor.nl2k.ab.ca (The Doctor) writes:
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
What you pasted as what you "need" is not even valid JSON and has a huge
number of pointless spaces in it making it almost unreadable (in my news
client).
First of all - to all of you: learn how to use validators and
beautifiers.
doctor@doctor.nl2k.ab.ca (The Doctor) writes:As I saw it, the OP post was more about the formatting of the json that
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
What you pasted as what you "need" is not even valid JSON and has a huge number of pointless spaces in it making it almost unreadable (in my news client).
I don't know what it is you mean.
On 01/02/2023 17:09, Ben Bacarisse wrote:
doctor@doctor.nl2k.ab.ca (The Doctor) writes:
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnetWhat you pasted as what you "need" is not even valid JSON and has a huge
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
number of pointless spaces in it making it almost unreadable (in my news
client). I don't know what it is you mean.
As I saw it, the OP post was more about the formatting of the json
that is generated than about if his json was correct or not, he wants
a multi line json with indentations instead of a single line
compressed json.
Arno Welzel <usenet@arnowelzel.de> writes:
Ben Bacarisse, 2023-02-01 17:09:
doctor@doctor.nl2k.ab.ca (The Doctor) writes:
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
What you pasted as what you "need" is not even valid JSON and has a huge >>> number of pointless spaces in it making it almost unreadable (in my news >>> client).
First of all - to all of you: learn how to use validators and
beautifiers.
You think I don't? Now that you've got that off your chest, what's the second thing we -- all of us -- need to learn? ;-)
On 01/02/2023 17:09, Ben Bacarisse wrote:
doctor@doctor.nl2k.ab.ca (The Doctor) writes:As I saw it, the OP post was more about the formatting of the json that
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
What you pasted as what you "need" is not even valid JSON and has a huge
number of pointless spaces in it making it almost unreadable (in my news
client).
I don't know what it is you mean.
is generated than about if his json was correct or not, he wants a multi
line json with indentations instead of a single line compressed json.
Ben Bacarisse, 2023-02-04 00:56:
Arno Welzel <usenet@arnowelzel.de> writes:
Ben Bacarisse, 2023-02-01 17:09:
doctor@doctor.nl2k.ab.ca (The Doctor) writes:
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
What you pasted as what you "need" is not even valid JSON and has a huge >>>> number of pointless spaces in it making it almost unreadable (in my news >>>> client).
First of all - to all of you: learn how to use validators and
beautifiers.
You think I don't? Now that you've got that off your chest, what's the
second thing we -- all of us -- need to learn? ;-)
What I told you.
Then you could have seen, that the invalid example only
missed a comma.
Arno Welzel <usenet@arnowelzel.de> writes:[...]
Then you could have seen, that the invalid example only
missed a comma.
Yes, I spotted that too. You'll never guess how...
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
[{"store_id":"store3","api_token":"yesguy","checkout_id":"chkt23NGFtore3","txn_total":"126.00","environment":"qa","action":"preload"},[{"cart":[[[{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"AgriculturalHealth Study","product_code":"AHS-1298","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}},{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Pesticide Applicator
How can I carefully strip unnecessary punctuation?
store_id = "123";// add item to cart that cast an array to object
api_token = "432";
cart = array();
cart[] = (object)[ "value" => "12.01", "item" => "banana" ];// add item to cat that is an undefined object
cart[] = $itemObj;echo json_encode($a, JSON_PRETTY_PRINT);
Ben Bacarisse, 2023-02-05 01:06:
Arno Welzel <usenet@arnowelzel.de> writes:[...]
Then you could have seen, that the invalid example only
missed a comma.
Yes, I spotted that too. You'll never guess how...
Well, then I wonder why you just wrote this:
"But that one is (a) valid and (b) has no unnecessary punctuation, so I don't know what it is you mean."
Arno Welzel <usenet@arnowelzel.de> writes:
Ben Bacarisse, 2023-02-05 01:06:
Arno Welzel <usenet@arnowelzel.de> writes:[...]
Then you could have seen, that the invalid example only
missed a comma.
Yes, I spotted that too. You'll never guess how...
Well, then I wonder why you just wrote this:
"But that one is (a) valid and (b) has no unnecessary punctuation, so I
don't know what it is you mean."
Because "that one" (the second sample shown) was (a) valid and (b) had
no unnecessary punctuation. As result, I could not tell what the OP
meant by their question. What's bothering you about this?
On 01/02/2023 16:45, The Doctor wrote:
From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
I need a JSON as follows:
{
"store_id":"moneris",
"api_token":"hurgle",
For console output:
echo json_encode($object, JSON_PRETTY_PRINT);
For html output:
<pre>
<?php echo nl2br(json_encode($yourArrayOrObject, JSON_PRETTY_PRINT)); ?> ></pre>
If you have an already json encoded string, then you need to use
json_decode to get an object and then encode the object to prettify the
json.
Health >Study","product_code":"AHS-1298","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}},{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Pesticide[{"store_id":"store3","api_token":"yesguy","checkout_id":"chkt23NGFtore3","txn_total":"126.00","environment":"qa","action":"preload"},[{"cart":[[[{"items":{"url":"https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png","description":"Agricultural
Applicator >Records","product_code":"PAR-1302","unit_cost":60,"quantity":"1"},"subtotal":60,"tax":{"amount":3,"description":"GST","rate":"0.05"}}]]]}],[{"contact_details":{"first_name":"Dave","last_name":"Yadallee","email":"dog@nk.ca","phone":"7809999999"}}],[{"billing_details":{"address_1":"","city":"","province":"","country":"CA","postal_code":""}}]]
How can I carefully strip unnecessary punctuation?
The unnecessary [] that you get is for you use an array to store things >inside, use a class object instead.
Here is a small example, where only the cart is an array in the json:
--- start of php ---
$a = new class{};
store_id = "123";// add item to cart that cast an array to object
api_token = "432";
cart = array();
cart[] = (object)[ "value" => "12.01", "item" => "banana" ];// add item to cat that is an undefined object
$itemObj = new class{};
$itemObj->value = "10.02";
$itemObj->item = "apple";
cart[] = $itemObj;echo json_encode($a, JSON_PRETTY_PRINT);
--- eof ---
Only use array when you are to have a collection of items, for example a >shopping cart, but do not use array when you have a single item, then
better to use an object of some sort, for your example I would actually >create classes that describes the json, you will of course have nested >objects in the end.
--
//Aho
And in the case of recurring items when being puleld from
a form getting parsed?
cart = (object)$_POST['cart']; // this may give you object you don'twant
cart = $validated_shopping_cart; // validated_shopping_cart is ajson object
On 06/02/2023 02:31, The Doctor wrote:
And in the case of recurring items when being puleld from
a form getting parsed?
If you are thinking of post value which is an array, then the simplest
would be:
cart = (object)$_POST['cart']; // this may give you object you don'twant
Just keep in mind that the data is unsafe to use, you should do the long
way and validate the data and as you validate you can then add the
values to a temp variable and if all the cart items passes validation,
then add it to the main json object (in this silly example the $a).
If you get a new cart posted (updates), then replace the current one
you have in the session, don't forget to validate the data before you
replace the cart section. Only have the latest validated one
cart = $validated_shopping_cart; // validated_shopping_cart is ajson object
for duplicate entries you have to decide what to do, cast an error or
merge them together, that is up to you, but do not have duplicate items
in your json object.
I hope that was the answer you was looking for.
--
//Aho
In article <k4bnmkFffdeU1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
On 06/02/2023 02:31, The Doctor wrote:
And in the case of recurring items when being puleld from
a form getting parsed?
If you are thinking of post value which is an array, then the simplest
would be:
cart = (object)$_POST['cart']; // this may give you object you don'twant
Just keep in mind that the data is unsafe to use, you should do the long
way and validate the data and as you validate you can then add the
values to a temp variable and if all the cart items passes validation,
then add it to the main json object (in this silly example the $a).
If you get a new cart posted (updates), then replace the current one
you have in the session, don't forget to validate the data before you
replace the cart section. Only have the latest validated one
cart = $validated_shopping_cart; // validated_shopping_cart is ajson object
for duplicate entries you have to decide what to do, cast an error or
merge them together, that is up to you, but do not have duplicate items
in your json object.
I hope that was the answer you was looking for.
The cart is being derived from a previous form being passed into PHP!
Just an update
The cart section is now an issue .
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
$subtotal = ($unit_cost * $value);
$quantity = ($value);
$cart['items'][] =array(
'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png",
'description' => $_POST['description'][$key],
'product_code' => $_POST['id'][$key],
'unit_cost' => $unit_cost,
'quantity' => $quantity,
),
$newtotal += $subtotal;
$items_count++;
array_push(items,itemsubarray);
}
}
'subtotal' => $newtotal,
if(isset($_POST['with_gst'][$key])){
'tax'=>array(
'amount' => ($newtotal * 0.05),
'description' => "GST",
'rate' => "5.00",
),
})
),
The cart is being derived from a previous form being passed into PHP!
$arr=array(
'store_id' => "store3",
'api_token' => "yesguy",
'checkout_id' => "chktGLFZQtore3",
'txn_total' => $_POST['charge_total'],
'environment' => "qa",
'action' => "preload",
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {
$cart['items'][] =array(
The Doctor, 2023-02-06 16:28:
[...]
The cart is being derived from a previous form being passed into PHP!
[...]
$arr=array(
'store_id' => "store3",
'api_token' => "yesguy",
'checkout_id' => "chktGLFZQtore3",
'txn_total' => $_POST['charge_total'],
'environment' => "qa",
'action' => "preload",
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {
Well - this will result in an array in the JSON named "cart".
$cart['items'][] =array(
And this will also become an array named "items" inside "cart".
So if you don't want "cart" to be an array in the JSON, then don't
create it this way.
Learn how to read JSON and that the "punctuation" are not just
characters but have a specific meaning. In this case you created an
array and the JSON will have an array as well - indicated by "[" and "]".
--
Arno Welzel
https://arnowelzel.de
On 2/6/23 16:28, The Doctor wrote:
In article <k4bnmkFffdeU1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
On 06/02/2023 02:31, The Doctor wrote:
And in the case of recurring items when being puleld from
a form getting parsed?
If you are thinking of post value which is an array, then the simplest
would be:
cart = (object)$_POST['cart']; // this may give you object you don't >>> want
Just keep in mind that the data is unsafe to use, you should do the long >>> way and validate the data and as you validate you can then add the
values to a temp variable and if all the cart items passes validation,
then add it to the main json object (in this silly example the $a).
If you get a new cart posted (updates), then replace the current one
you have in the session, don't forget to validate the data before you
replace the cart section. Only have the latest validated one
cart = $validated_shopping_cart; // validated_shopping_cart is ajson object
for duplicate entries you have to decide what to do, cast an error or
merge them together, that is up to you, but do not have duplicate items
in your json object.
I hope that was the answer you was looking for.
The cart is being derived from a previous form being passed into PHP!
Just an update
The cart section is now an issue .
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
$subtotal = ($unit_cost * $value);
$quantity = ($value);
$cart['items'][] =array(
'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png", >> 'description' => $_POST['description'][$key],
'product_code' => $_POST['id'][$key],
'unit_cost' => $unit_cost,
'quantity' => $quantity,
),
$newtotal += $subtotal;
$items_count++;
array_push(items,itemsubarray);
}
}
'subtotal' => $newtotal,
if(isset($_POST['with_gst'][$key])){
'tax'=>array(
'amount' => ($newtotal * 0.05),
'description' => "GST",
'rate' => "5.00",
),
})
),
It's messy and a lot of hard coded things and I'm just guessing what you
try to do, I think I would have done things differently, for example
posting all the data maybe as a serialized json object from the client
side, I would fetch the items value from the database together with >description, I would have the tax rate in the database too, easy to
change the the tax in the database when the the government changes it.
I made an small example that take the cart part, not sure if it's what
you want to have, but at least should give you some idea and the reason
I didn't use $_POST values is that it's easier to test things when you
can modify values based on what you want and fine tune things till they
are right, then you can modify the constructor to not take any
arguments, I would make the "cart" class to hold all the values you need
for your json.
If you need to use values between functions, then use private, for then
they will not be included when you use the json_encode()
--- simple example ---
<?php
class cart {
public $total = 0;
public $items = [];
private $uber = "man"; // this will not be included in the json output
public function __construct($quantityArray, $gstArray, $descArray,
$idArray) {
foreach($quantityArray as $key => $num_items)
{
if($num_items == 0)
continue;
$has_tax = isset($gstArray[$key]);
$unit_cost = $has_tax ? 63 : 60;
$sub_total = $num_items * $unit_cost;
$this->total = $sub_total;
$item = [
'url' =>
'https://www.pdsolutions.ca/images/newwhiteheader.png',
'description' => $descArray[$key],
'product_code' => $idArray[$key],
'unit_cost' => number_format($unit_cost, 2),
'quantity' => $num_items,
'subtotal' => number_format($sub_total, 2),
];
if($has_tax) {
$item['tax'] = (object)[ 'amount' =>
number_format($sub_total * 0.05), 'description' => "GST", 'rate' =>
'5.00' ];
}
$this->items[] = (object)$item;
}
}
}
$q = [1, 2, 0];
$g = [1, 1, 0];
$d = ['banana', 'apple', 'car'];
$i = [22, 11, 33];
$cart = new cart($q, $g, $d, $i);
echo json_encode($cart, JSON_PRETTY_PRINT);
--- eof ---
You can also see the use of number_format(), that just so we get the
right number of decimals, I haven't bothered about rounding which would
be sane. And it's the "items" that should be something similar to your cart.
--
//Aho
In article <k4d3dvFtd5nU1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
The Doctor, 2023-02-06 16:28:
[...]
The cart is being derived from a previous form being passed into PHP!
[...]
$arr=array(
'store_id' => "store3",
'api_token' => "yesguy",
'checkout_id' => "chktGLFZQtore3",
'txn_total' => $_POST['charge_total'],
'environment' => "qa",
'action' => "preload",
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {
Well - this will result in an array in the JSON named "cart".
$cart['items'][] =array(
And this will also become an array named "items" inside "cart".
So if you don't want "cart" to be an array in the JSON, then don't
create it this way.
Learn how to read JSON and that the "punctuation" are not just
characters but have a specific meaning. In this case you created an
array and the JSON will have an array as well - indicated by "[" and "]".
Again basing this on Moneris prereqs.
--
Arno Welzel
https://arnowelzel.de
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b >Extremism is for those who love judging, and care nothing for accuracy. >-unknown Beware https://mindspring.com
In article <k4d3dvFtd5nU1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
The Doctor, 2023-02-06 16:28:
[...]
The cart is being derived from a previous form being passed into PHP!
[...]
$arr=array(
'store_id' => "store3",
'api_token' => "yesguy",
'checkout_id' => "chktGLFZQtore3",
'txn_total' => $_POST['charge_total'],
'environment' => "qa",
'action' => "preload",
'cart' => array(
(foreach ($_POST['quantity'] as $key => $value) {
Well - this will result in an array in the JSON named "cart".
$cart['items'][] =array(
And this will also become an array named "items" inside "cart".
So if you don't want "cart" to be an array in the JSON, then don't
create it this way.
Learn how to read JSON and that the "punctuation" are not just
characters but have a specific meaning. In this case you created an
array and the JSON will have an array as well - indicated by "[" and "]".
Again basing this on Moneris prereqs.
The Doctor, 2023-02-07 02:28:
[...]
cart is subarray with the main array, added items in the cart
is a subarray of the cart.>
Source
https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
No! Cart is an OBJECT there:
"cart":{
...
}
Also contact details:
"contact_details":{
...
}
The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
As I said: learn how to read JSON and try to understand how that format works!
Also see: <https://www.json.org/json-en.html>
cart is subarray with the main array, added items in the cart
is a subarray of the cart.>
Source
https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
The Doctor, 2023-02-07 02:28:
[...]
cart is subarray with the main array, added items in the cart
is a subarray of the cart.>
Source
https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
No! Cart is an OBJECT there:
"cart":{
...
}
Also contact details:
"contact_details":{
...
}
The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
As I said: learn how to read JSON and try to understand how that format >works!
Also see: <https://www.json.org/json-en.html>
--
Arno Welzel
https://arnowelzel.de
Arno Welzel, 2023-02-07 09:16:
The Doctor, 2023-02-07 02:28:
[...]
cart is subarray with the main array, added items in the cart
is a subarray of the cart.>
Source
https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet
No! Cart is an OBJECT there:
"cart":{
...
}
Also contact details:
"contact_details":{
...
}
The "{" indicates the beginning of an OBJECT while "[" starts an ARRAY.
As I said: learn how to read JSON and try to understand how that format
works!
Also see: <https://www.json.org/json-en.html>
In addition:
To create an OBJECT in PHP use something like this - as a reduced example:
<?php
class CartItem
{
public $url;
public $description;
public $product_code;
public $unit_cost;
public $quantity;
}
class TaxItem
{
public $amount;
public $description;
public $rate;
}
class Cart
{
public $items;
public $subtotal;
public $tax;
};
$cart = new Cart();
$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item1.jpg"; >$cartItem->description = "One item";
$cartItem->product_code = "one_item";
$cartItem->unit_cost = "100.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;
$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item2.jpg"; >$cartItem->description = "Two item";
$cartItem->product_code = "two_item";
$cartItem->unit_cost = "200.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;
$cartItem = new CartItem();
$cartItem->url = "https:\/\/example.com\/examples\/item3.jpg"; >$cartItem->description = "Three item";
$cartItem->product_code = "three_item";
$cartItem->unit_cost = "100.00";
$cartItem->quantity = "1";
$cart->items[] = $cartItem;
$cart->subtotal = "400.00";
$taxItem = new TaxItem();
$taxItem->amount = "52.00";
$taxItem->description = "Taxes";
$taxItem->rate = "13.00";
$cart->tax = $taxItem;
echo json_encode($cart, JSON_PRETTY_PRINT);
Result of this as formatted output:
{
"items": [
{
"url": "https:\\\/\\\/example.com\\\/examples\\\/item1.jpg",
"description": "One item",
"product_code": "one_item",
"unit_cost": "100.00",
"quantity": "1"
},
{
"url": "https:\\\/\\\/example.com\\\/examples\\\/item2.jpg",
"description": "Two item",
"product_code": "two_item",
"unit_cost": "200.00",
"quantity": "1"
},
{
"url": "https:\\\/\\\/example.com\\\/examples\\\/item3.jpg",
"description": "Three item",
"product_code": "three_item",
"unit_cost": "100.00",
"quantity": "1"
}
],
"subtotal": "400.00",
"tax": {
"amount": "52.00",
"description": "Taxes",
"rate": "13.00"
}
}
Hopefully you understand the idea now - if you don't want an ARRAY in
the JSON then do not create one! If the specification asks for an OBJECT
then use an OBJECT based on a class with named members.
--
Arno Welzel
https://arnowelzel.de
In article <k4egigF59f9U3@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
Hopefully you understand the idea now - if you don't want an ARRAY in
the JSON then do not create one! If the specification asks for an OBJECT
then use an OBJECT based on a class with named members.
But The information is being pulled from a pre-filled hence you need, Something like
//$items=array(
if (isset($_POST["submit"])){
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
$newsubtotal = ($unit_cost * $value);
$quantity = ($value);
$itemssubarray[]= array(
$cartarray[] = array(
"cart"=>array( $items
),
'subtotal' => $subtotal,
"tax"=>array(
'amount' => ($subtotal * 0.05),
'description' => "GST",
'rate' => "5.00",
),
);
The Doctor, 2023-02-07 17:10:
In article <k4egigF59f9U3@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
[...]
Hopefully you understand the idea now - if you don't want an ARRAY in
the JSON then do not create one! If the specification asks for an OBJECT >>> then use an OBJECT based on a class with named members.
But The information is being pulled from a pre-filled hence you need,
Something like
So what? You can also create objects based on "pre-filled" data.
//$items=array(
if (isset($_POST["submit"])){
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
$newsubtotal = ($unit_cost * $value);
$quantity = ($value);
$itemssubarray[]= array(
CREATE AN OBJECT HERE!
First define a class for this above all the code:
class CartItem
{
public $url;
public $description;
public $product_code;
public $unit_cost;
public $quantity;
}
And then use THIS(!) to create the OBJECT(!) for it:
$item = new Item();
$item->url = "https://www.pdsolutions.ca/images/newwhiteheader.png"; >$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $quantity;
$itemssubarray[] = $item;
[...]
$cartarray[] = array(
"cart"=>array( $items
),
NO! Create an OBJECT!
'subtotal' => $subtotal,
"tax"=>array(
'amount' => ($subtotal * 0.05),
'description' => "GST",
'rate' => "5.00",
),
);
Sorry - but if you are really not able to understand what I write, you
should pay someone to do the job for you.
--
Arno Welzel
https://arnowelzel.de
In article <k4kvg1F6414U1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
Sorry - but if you are really not able to understand what I write, you
should pay someone to do the job for you.
The problem is the way the supplier wants to oush the information.
On 2/9/23 22:01, The Doctor wrote:
In article <k4kvg1F6414U1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
Sorry - but if you are really not able to understand what I write, you
should pay someone to do the job for you.
The problem is the way the supplier wants to oush the information.
You need to follow the api requierment which says that the json should
have an array of json objects, not an array of arrya with array.
Your task is to take the posted value convert it to be in the format
that the api requiers.
Using classes will make the code more readable and you can break things
up into smaller chunks when you are writing your code. I think it's
beter to transform things into a variable and then assing it to the
object's variable to make the assignment clear and simple. Don't forget
that the classes can include arrays, but only use those in the places
where you need it, IMHO it can be sometimes good to iniate the array in
the class constructor (this only can be done as long as the api don't
require the array to be omitted if no values).
Don't forget that the company providing the API also has a support team
which can help, sure it may come with a cost, depending on the deggree
of help and how much they think is out of topic. For them it's importnat
to earn money and if they think helpiing you will give them enough money
in return, they may help more than they normal support is mandated to do.
--
//Aho
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (2 / 14) |
Uptime: | 119:25:33 |
Calls: | 7,612 |
Files: | 12,787 |
Messages: | 5,684,032 |