How do I read and store the response data from an API?

0

I got the answer from API from CIELO below, now I'd like to understand how to read and store values.

If someone can help me with what key information should I store in the database?

  

object(stdClass)#2 (3) { ["MerchantOrderId"]=> string(16) "2014113245231706" ["Customer"]=> object(stdClass)#3 (1) { ["Name"]=> string(24) "Comprador rec programada" } ["Payment"]=> object(stdClass)#4 (15) { ["ServiceTaxAmount"]=> int(0) ["Installments"]=> int(1) ["Interest"]=> int(0) ["Capture"]=> bool(false) ["Authenticate"]=> bool(false) ["Recurrent"]=> bool(false) ["CreditCard"]=> object(stdClass)#5 (5) { ["CardNumber"]=> string(16) "123412******1231" ["Holder"]=> string(12) "Teste Holder" ["ExpirationDate"]=> string(7) "03/2019" ["SaveCard"]=> bool(false) ["Brand"]=> string(4) "Visa" } ["SoftDescriptor"]=> string(13) "123456789ABCD" ["Provider"]=> string(8) "Simulado" ["Type"]=> string(10) "CreditCard" ["Amount"]=> int(1500) ["Currency"]=> string(3) "BRL" ["Country"]=> string(3) "BRA" ["Status"]=> int(20) ["RecurrentPayment"]=> object(stdClass)#6 (9) { ["RecurrentPaymentId"]=> string(36) "85717927-b438-461b-908f-764772289cb5" ["ReasonCode"]=> int(0) ["ReasonMessage"]=> string(10) "Successful" ["NextRecurrency"]=> string(10) "2015-06-01" ["StartDate"]=> string(10) "2015-06-01" ["EndDate"]=> string(10) "2019-12-01" ["Interval"]=> int(6) ["Link"]=> object(stdClass)#7 (3) { ["Method"]=> string(3) "GET" ["Rel"]=> string(16) "recurrentPayment" ["Href"]=> string(107) "https://apiquerysandbox.cieloecommerce.cielo.com.br/1/RecurrentPayment/8 5717927-b438-461b-908f-764772289cb5" } ["AuthorizeNow"]=> bool(false) } } }

    
asked by anonymous 27.02.2017 / 19:00

1 answer

0

They have returned you a JSON, it seems. You read the data as a normal object. For example:

<?php echo $objeto->MerchantOrderId; // output: 2014113245231706

To save, it depends on what you are using for persistence and what you are going to do with this information. But overall it can save normally like any other information. Examples:

  • Save to a relational database, mapping the properties of this object to columns in some table, or saving the entire json (using json_encode($objeto) , which returns a string;
  • Save to a non-relational database, such as mongo or couchdb;
  • Save to file 'file_put_contents ("file.json", json_encode ($ object));

It's up to you to define how you want to save this data.

    
02.03.2017 / 17:39