• Re: Stripping a JSON of extra characters in PHP

    From Ben Bacarisse@21:1/5 to The Doctor on Wed Feb 1 16:09:00 2023
    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).

    But 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
    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 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?

    But that one is (a) valid and (b) has no unnecessary punctuation, so I
    don't know what it is you mean.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to All on Wed Feb 1 15:45:22 2023
    From https://developer.moneris.com/livedemo/checkout/preload_req/guide/dotnet

    I need a JSON as follows:

    {
    "store_id":"moneris",
    "api_token":"hurgle",
    "checkout_id":"chkt5BF66neris",
    "txn_total":"452.00",
    "environment":"qa",
    "action":"preload",
    "token": [
    {
    "data_key": "abc123datakey1",
    "issuer_id": "645sddfvdrt4tefd"
    },
    {
    "data_key": "abc123datakey2",
    "issuer_id": "645sddfvdrt4tefd"
    },
    {
    "data_key": "abc123datakey3",
    "issuer_id": "645sddfvdrt4tefd"
    }
    ],
    "ask_cvv":"Y"
    "order_no":"",
    "cust_id":"chkt - cust - 0303",
    "dynamic_descriptor":"dyndesc",
    "language":"en",
    "recur":{
    "bill_now":"true",
    "recur_amount":"1.00",
    "start_date":"2021-11-21",
    "recur_unit":"month",
    "recur_period":"1",
    "number_of_recurs":"10"
    },
    "cart":{
    "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"
    }
    },
    "contact_details":{
    "first_name":"bill",
    "last_name":"smith",
    "email":"test@moneris.com",
    "phone":"4165551234"
    },
    "shipping_details":{
    "address_1":"1 main st",
    "address_2":"Unit 2012",
    "city":"Toronto",
    "province":"ON",
    "country":"CA",
    "postal_code":"M1M1M1"
    },
    "billing_details":{
    "address_1":"1 main st",
    "address_2":"Unit 2000",
    "city":"Toronto",
    "province":"ON",
    "country":"CA",
    "postal_code":"M1M1M1"
    }
    }











    But 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
    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 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?
    --
    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 When they offer free stuff, demand to know how much it will cost. -unknown Beware https://mindspring.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Fri Feb 3 18:12:15 2023
    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. It helps a lot to understand the structure and differences
    between multiple JSON files.

    In the original sample was only one single comma missing. Otherwise it
    is ok:

    {
    "store_id":"moneris",
    "api_token":"hurgle",
    "checkout_id":"chkt5BF66neris",
    "txn_total":"452.00",
    "environment":"qa",
    "action":"preload",
    "token":[
    {
    "data_key":"abc123datakey1",
    "issuer_id":"645sddfvdrt4tefd"
    },
    {
    "data_key":"abc123datakey2",
    "issuer_id":"645sddfvdrt4tefd"
    },
    {
    "data_key":"abc123datakey3",
    "issuer_id":"645sddfvdrt4tefd"
    }
    ],
    "ask_cvv":"Y",
    "order_no":"",
    "cust_id":"chkt - cust - 0303",
    "dynamic_descriptor":"dyndesc",
    "language":"en",
    "recur":{
    "bill_now":"true",
    "recur_amount":"1.00",
    "start_date":"2021-11-21",
    "recur_unit":"month",
    "recur_period":"1",
    "number_of_recurs":"10"
    },
    "cart":{
    "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"
    }
    },
    "contact_details":{
    "first_name":"bill",
    "last_name":"smith",
    "email":"test@moneris.com",
    "phone":"4165551234"
    },
    "shipping_details":{
    "address_1":"1 main st",
    "address_2":"Unit 2012",
    "city":"Toronto",
    "province":"ON",
    "country":"CA",
    "postal_code":"M1M1M1"
    },
    "billing_details":{
    "address_1":"1 main st",
    "address_2":"Unit 2000",
    "city":"Toronto",
    "province":"ON",
    "country":"CA",
    "postal_code":"M1M1M1"
    }
    }

    But 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
    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 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?

    But that one is (a) valid and (b) has no unnecessary punctuation, so I
    don't know what it is you mean.

    The structure is completely different and not just with "unnecessary punctuation" - there is no simple way to "strip" anything, it has to be completely parsed and output again in the desired way:

    [
    {
    "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 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 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":""
    }
    }
    ]
    ]



    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Arno Welzel on Fri Feb 3 23:56:57 2023
    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? ;-)

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to Ben Bacarisse on Sat Feb 4 11:23:23 2023
    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/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.
    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.

    --
    //Aho

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to J.O. Aho on Sat Feb 4 23:44:51 2023
    "J.O. Aho" <user@example.net> writes:

    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/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.

    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.

    Weird. I didn't interpret a desire to "strip unnecessary punctuation"
    as a formatting question, but I suppose it could be: unnecessary for
    display even though necessary for valid syntax.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Sun Feb 5 00:28:48 2023
    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
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Sun Feb 5 00:30:16 2023
    J.O. Aho, 2023-02-04 11:23:

    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/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.
    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.

    The OP showed to examples of *similar* JSON data with many identical properties, but in a slightly different structure. So I am not sure if
    the question was onloy about formatting - but only the OP can tell.

    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Arno Welzel on Sun Feb 5 00:06:05 2023
    Arno Welzel <usenet@arnowelzel.de> writes:

    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.

    What a relief to know that you'd already imparted the first /and second
    thing/ we all need to learn. I feared I would not have the time to
    learn enough to keep posting!

    Then you could have seen, that the invalid example only
    missed a comma.

    Yes, I spotted that too. You'll never guess how...

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Sun Feb 5 14:17:33 2023
    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
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to The Doctor on Sun Feb 5 16:14:32 2023
    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.


    [{"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
    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 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";
    api_token = "432";
    cart = array();
    // add item to cart that cast an array to object
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Arno Welzel on Sun Feb 5 20:58:26 2023
    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?

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Sun Feb 5 23:38:57 2023
    Ben Bacarisse, 2023-02-05 21:58:

    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?

    Just read my other posts about this, maybe you get it. If not, it's ok
    as well.

    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to J.O. Aho on Mon Feb 6 01:31:00 2023
    In article <k49veoF1ne8U3@mid.individual.net>,
    J.O. Aho <user@example.net> wrote:
    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.


    [{"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
    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
    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";
    api_token = "432";
    cart = array();
    // add item to cart that cast an array to object
    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.

    --

    And in the case of recurring items when being puleld from
    a form getting parsed?

    //Aho




    --
    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 If their only strength is in enforcing weakness, then they will preside over ruin. -unknown Beware https://mindspring.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to The Doctor on Mon Feb 6 08:14:28 2023
    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 a
    json 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to J.O. Aho on Mon Feb 6 15:28:19 2023
    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 a
    json 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


    <?=session_start();
    error_reporting(E_ALL);

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    </head>
    <?php
    if(!empty($_SESSION['sessiondata'])){
    }

    <?php
    $myObj = [];
    $cart = [];
    $items = [];
    $itemssubarray = [];
    $storevalues= [];
    $contact_details=[];
    $shipping_details=[];
    $billing_details=[];
    $arr2 =array();

    $items_count = 0;
    $newtotal = 0;
    $subtotal = 0;
    $arr = array();
    if (isset($_POST["submit"])){

    $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) {

    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",
    ),
    })
    ),
    'contact_details'=>array(
    'first_name' =>$_POST['bill_first_name'],
    'last_name' => $_POST['bill_last_name'],
    'email' => $_POST['email'],
    'phone' => $_POST['bill_phone'],
    ),
    'billing_details'=>array(
    'address_1' => $_POST['bill_address_one'],
    'city' => $_POST['bill_city'],
    'province' => $_POST['bill_state_or_province'],
    'country' => "CA",
    'postal_code' => $_POST['bill_postal_code'],
    ),

    );

    }


    // $billing_details[] = array (
    // "billing_details"=>array(
    //'address_1' => $_POST['bill_address_one'],
    //'city' => $_POST['bill_city'],
    //'province' => $_POST['bill_state_or_province'],
    //'country' => "CA",
    //'postal_code' => $_POST['bill_postal_code'],

    // )



    $myObj = $arr;
    $myJSON = json_encode($myObj);

    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'];


    <body>
    <div id="outerDiv" style="width:400px;height:300px">
    <div id="monerisCheckout"></div>
    </div>

    <script src="https://gatewayt.moneris.com/chktv2/js/chkt_v2.00.js"></script>
    <script>
    let myCheckout = new monerisCheckout();
    myCheckout.setMode("qa");
    myCheckout.setCheckoutDiv("monerisCheckout");
    myCheckout.setCallback("page_loaded", testPageLoad);
    myCheckout.setCallback("payment_receipt", testPayReceipt);
    myCheckout.setCallback("payment_complete", testPayComplete);
    myCheckout.setCallback("cancel_transaction", testCancel);
    myCheckout.setCallback("error_event", testCancel);
    myCheckout.setCallback("payment_submitted", testPaymentSubmitted);
    myCheckout.startCheckout('<?php echo $token ?>');
    myCheckout.setCallback("page_closed", testCancel);

    function testPageLoad(res){

    console.log(res)

    }

    function testPaySubmit(res){

    console.log(res)

    }

    function testPayReceipt(res){

    console.log(res)

    }

    function testPayComplete(res){

    console.log(res)

    }

    function testPaymentSubmitted(res){

    console.log(res)

    }

    function testCancel(res){

    console.log(res)

    //myCheckout.closeCheckout(JSON.parse(res).ticket)

    }



    </script>
    </body>
    </html>

    75% is working properly.


    The cart section is now an issue .

    --
    //Aho



    --
    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 If their only strength is in enforcing weakness, then they will preside over ruin. -unknown Beware https://mindspring.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to The Doctor on Mon Feb 6 18:14:07 2023
    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 a
    json 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),
  • From Arno Welzel@21:1/5 to All on Mon Feb 6 20:40:47 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to usenet@arnowelzel.de on Tue Feb 7 00:57:36 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to J.O. Aho on Tue Feb 7 00:56:50 2023
    In article <k4cqqvFpoj5U1@mid.individual.net>,
    J.O. Aho <user@example.net> wrote:
    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 a
    json 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




    Will try. Basing this in the Moneris docs.
    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to The Doctor on Tue Feb 7 01:28:23 2023
    In article <trs7m0$2pkv$29@gallifrey.nk.ca>,
    The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
    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.


    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

    --
    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


    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Tue Feb 7 09:13:47 2023
    The Doctor, 2023-02-07 01:57:

    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.

    What is "Moneris prereqs"?

    Your OP was: "How can I carefully strip unnecessary punctuation?" I
    tried to explain to you, where these "punctuation" comes from. But if
    you don't accept the facts, then you have to live with it.


    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Tue Feb 7 09:31:14 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Tue Feb 7 09:16:52 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to usenet@arnowelzel.de on Tue Feb 7 16:05:37 2023
    In article <k4efniF59f9U2@mid.individual.net>,
    Arno Welzel <usenet@arnowelzel.de> wrote:
    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>



    Got you!


    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to usenet@arnowelzel.de on Tue Feb 7 16:10:55 2023
    In article <k4egigF59f9U3@mid.individual.net>,
    Arno Welzel <usenet@arnowelzel.de> wrote:
    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.


    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(
    'url' => "https://www.pdsolutions.ca/images/newwhiteheader.png",
    'description' => $_POST['description'][$key],
    'product_code' => $_POST['id'][$key],
    'unit_cost' => $unit_cost,
    'quantity' => $quantity,
    );

    }
    $subtotal = $subtotal+ $newsubtotal;
    $items_count++;
    }
    array_push($items, $itemssubarray);

    }
    //);

    $cartarray[] = array(
    "cart"=>array( $items
    ),
    'subtotal' => $subtotal,
    "tax"=>array(
    'amount' => ($subtotal * 0.05),
    'description' => "GST",
    'rate' => "5.00",
    ),
    );


    --
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Thu Feb 9 20:22:42 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to usenet@arnowelzel.de on Thu Feb 9 21:01:09 2023
    In article <k4kvg1F6414U1@mid.individual.net>,
    Arno Welzel <usenet@arnowelzel.de> wrote:
    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.


    The problem is the way the supplier wants to oush the information.


    --
    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 Sometimes what's billed as light is the darkness. -unknown Beware https://mindspring.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to The Doctor on Fri Feb 10 11:49:57 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Doctor@21:1/5 to J.O. Aho on Fri Feb 10 14:39:30 2023
    In article <k4mlqlFdtacU1@mid.individual.net>,
    J.O. Aho <user@example.net> wrote:
    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.


    There is no support from the providing company.

    --
    //Aho



    --
    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 We have been misled: there is only one Jesus. -unknown Beware https://mindspring.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)