Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #19389

Re: Replace punctuation in an associative array

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Replace punctuation in an associative array
Date 2023-03-07 18:56 +0100
Message-ID <k6pc5tFj8geU1@mid.individual.net> (permalink)
References (3 earlier) <k6i6l8FksscU2@mid.individual.net> <tu0p47$29gl$4@gallifrey.nk.ca> <k6jc0rFpvrcU1@mid.individual.net> <tu27ov$2dt5$126@gallifrey.nk.ca> <tu7pim$1i39$55@gallifrey.nk.ca>

Show all headers | View raw


On 3/7/23 17:43, The Doctor wrote:
> The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
> : J.O. Aho <user@example.net> wrote:
> : : On 3/5/23 01:52, The Doctor wrote:
> : : > In article <k6i6l8FksscU2@mid.individual.net>,
> : : > J.O. Aho <user@example.net> wrote:
> : : >> On 3/5/23 00:58, The Doctor wrote:
> : : >>> J.O. Aho <user@example.net> wrote:
> : : >>
> : : >>> : https://pastebin.com/bF6bZseu
> : : >>> : Keep in mind nothin is a 100% solution for your issue as I haven't
> : : >>> : bothered really go into the API that is used but just a bit based on
> : : >>> : your posts in this group.
> : : >>>
> : : >>> : And please, what ever you do, don't go with the str_replace, it's not
> : : >>> : the solution to your issue, it will just make things a lot harder to
> : : >>> : maintain.
> : : >>>
> : : >>>
> : : >>> Actually the class approach works better.
> : : >>
> : : >> That's good, just tweak it to fit your user case, just don't forget
> : : >> validate the input data.
> : : >>
> : : >>
> : : >>> Too bad Google does not pick that up
> : : >>> in their searches for JSON>
> : : >>
> : : >> Much depends on the requirements and what the json is used for, say
> : : >> sending data between angular and php, then the coder is usually in
> : : >> control of both front end and backend and can use what ever json format
> : : >> they want, but it's different when you have to follow an API, but
> : : >> usually you can get support from the API owner and payment services tend
> : : >> to also do a verification round before letting you to use production
> : : >> grade transactions.
> : : >>
> : : >
> : : > A good article can be written about this.
> 
> : : Great, post the link when you have written it ;)
> 
> : : It's about time, to write a good example that make sense without bad
> : : coding and then host and promote the page, not everyone is prepared to
> : : do that.
> 
> : : Sadly we see a lot of cheap cut the corner stuff out on the net, much
> : : for people have sample with simple structures so arrays works ok, but
> : : that is much based on the quality of the education they had. For example
> : : there is a country that spits out 2 million CS each year, many of them
> : : have a skills level not much than general high school students
> : : programing knowledge level. Should also note that there are really good
> : : programmers from that country too.
> 
> : : The main thing is that you get forward on your project.
> 
> 
> : Wait until you see the nightmare in bureaucracy.
> 
> Other nightmare, I might have to write a preview page.

I would make a function that can update an existing item in the orders 
cart, similar to the one AddItem, with the tweak that if the quantity is 
0 then it removes the item. Lets call the function for UpdateItem.

In the overview page you do as before, create the order object, 
serialize it and store in the session.

On the overview page you have to have some ajax calls, so that you can 
increase and decrease the quantity of items and of course delete. In the 
ajax call you need to send the project_code and also the new quantity.

  The php script will unserailize the order from session, do the 
changes, serialize the order and store it in session before sending 
response with the new order->txn_total, order->cart->subtotal, and 
order->cart->tax->amount

You will then use javascript on the overview page to remove items and 
also update the values.

When the customer want to proceed, you just go to the next page and you 
unserialize the order and use it as you did before to send it to the 
payment service.

With help of Ajax, you can make things quite neat and maybe even avoid 
many unnecessary load of "full php pages". Use some framework if 
possible, I would give you just one advice, avoid angular, as you need 
to keep on updating it quite frequently.

- - - - -

if we have the order object we had in the examples earlier in the thread 
then you just serialize it with: $serialized_order = serialize($order);
and the string would look like:

O:5:"order":20:{s:16:"order_tax_rate";d:0.13;s:16:"order_subtotal";d:400;s:16:"order_taxtotal";d:52;s:8:"store_id";N;s:9:"api_token";N;s:11:"checkout_id";N;s:9:"txn_total";s:6:"452.00";s:11:"environment";N;s:6:"action";N;s:5:"token";a:2:{i:0;O:5:"token":2:{s:8:"data_key";s:4:"1234";s:9:"issuer_id";s:16:"645sddfvdrt4tefd";}i:1;O:5:"token":2:{s:8:"data_key";s:4:"5678";s:9:"issuer_id";s:16:"645sddfvdrt4tefd";}}s:7:"ask_cvv";N;s:8:"order_no";N;s:7:"cust_id";N;s:18:"dynamic_descriptor";N;s:8:"language";N;s:5:"recur";O:5:"recur":6:{s:8:"bill_now";N;s:12:"recur_amount";N;s:10:"start_date";N;s:10:"recur_unit";N;s:12:"recur_period";N;s:16:"number_of_recurs";N;}s:4:"cart";O:4:"cart":3:{s:5:"items";a:3:{i:0;O:4:"item":5:{s:3:"url";s:29:"https://example.net/item?id=1";s:11:"description";s:6:"item 
1";s:12:"product_code";s:1:"1";s:9:"unit_cost";s:3:"100";s:8:"quantity";s:1:"1";}i:1;O:4:"item":5:{s:3:"url";s:29:"https://example.net/item?id=2";s:11:"description";s:6:"item 
2";s:12:"product_code";s:1:"2";s:9:"unit_cost";s:3:"200";s:8:"quantity";s:1:"1";}i:2;O:4:"item":5:{s:3:"url";s:41:"https://custom.url.exmple.net/olditems/33";s:11:"description";s:6:"item 
3";s:12:"product_code";s:1:"3";s:9:"unit_cost";s:2:"50";s:8:"quantity";s:1:"2";}}s:8:"subtotal";s:6:"400.00";s:3:"tax";O:3:"tax":3:{s:6:"amount";s:5:"52.00";s:11:"description";s:3:"Tax";s:4:"rate";s:5:"13.00";}}s:15:"contact_details";O:14:"contactdetails":4:{s:10:"first_name";N;s:9:"last_name";N;s:5:"email";N;s:5:"phone";N;}s:16:"shipping_details";O:7:"address":6:{s:9:"address_1";N;s:9:"address_2";N;s:4:"city";N;s:8:"province";N;s:7:"country";N;s:11:"postal_code";N;}s:15:"billing_details";O:7:"address":6:{s:9:"address_1";N;s:9:"address_2";N;s:4:"city";N;s:8:"province";N;s:7:"country";N;s:11:"postal_code";N;}}

when you need it again as an object you just run:
$order = unserialize($_SESSION['serialized_order']);

as the customer won't be able to modify the serialized data, you don't 
need to think about validating the incoming data, it's a completely 
different history if the serialized data had been posted.

-- 
  //Aho


Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-02 12:44 +0000
  Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-02 14:23 +0100
    Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-03 01:03 +0000
      Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-03 10:36 +0100
    Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <techfan55555@hotmail.com> - 2023-03-08 09:22 -0800
      Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:24 +0000
  Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-03 08:14 +0100
    Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 05:19 +0000
      Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 11:07 +0100
      Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-04 14:42 +0100
        Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 14:57 +0000
          Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 16:38 +0100
            Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 00:41 +0100
              Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 23:58 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 01:39 +0100
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-03-05 00:52 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 12:16 +0100
                Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-05 14:08 +0000
                Re: Bureaucracy (Was: Replace punctuation in an associative array) "J.O. Aho" <user@example.net> - 2023-03-06 09:30 +0100
                Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 16:43 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-07 18:56 +0100
                Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 22:53 +0000
                Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-08 23:44 +0100
                Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:25 +0000
                Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-10 09:08 +0100
                Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-10 15:20 +0000
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-01 14:08 +0000
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-06 00:26 +0000
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-12 22:45 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 07:41 +0200
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 11:50 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 14:26 +0200
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 22:37 +0000
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 01:12 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-14 19:34 +0200
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 22:21 +0000
                Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-16 12:40 +0000
                Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-16 22:03 +0200
  Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <yyyyyeeeee00000@writeme.com> - 2023-03-06 03:23 -0800
    Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-06 16:21 +0000
  Re: Replace punctuation in an associative array V <vvvvvvvvvvvvvvvvvvvv11111@mail.ee> - 2023-04-03 06:55 -0700
    Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-03 14:18 +0000
  Re: Replace punctuation in an associative array Angel <heyeeeeeeeeeeeeeeeeeee@gmail.com> - 2023-04-15 05:33 -0700
    Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-15 13:52 +0000

csiph-web