Pass two variables concatenated into a Json object of a PHP POST Curl

Asked

Viewed 170 times

0

I’m sending this json request in the Curl POST with PHP.

Here the json of the POST:

"Payment" => [
    "Type" => "Vendor",
    "Amount" => 100,
    "CreditCard" => [
    "CardNumber" =>  "$card",
    "ExpirationDate" =>   "$dataexp"     


    ]

The default for receiving in the Expirationdate api is 20/2021 XX/XXXX .

Within the "Experationdate" => "",I want to concatenate the two variables ($month and $year) with the / (bar). $mes+/+$ano or this logic in a single variable. When I submit Expirationdate content should be 12/2021 XX/XXXX.

They come from other variables in the script. $mes and $ano.

Returns this pattern by sending in Experationdata to the api in the post.

I tried something like:

"ExperationDate" => "'.$mes.'/'.$ano.'"

"ExperationDate" => "$mes/$ano.'"

"ExperationDate" => "$mes./.$ano.'"

None of the three possibilities I got. $mes and $ano did not concatenate with /.Thus the pattern ex: 10/2021 was not correctly passed in the object POST in json Experationdate => ""

I have an error in Experationdate in api, the error is exactly at the crossing point of two variables plus / concatenated in Experationdate.

Could someone help me make this pattern I showed you? It would be possible to pass two variables and concatenated inside a post json object ?

Sincerely yours Thank you

1 answer

0


I managed to solve it in a simple way. I created a second variable that stores $mes / $ano and then set the variable to "Expirationdate" => "$dataexp" . Concatenating as follows:

$dataexp = $mes.'/'.$ano ;

So I was able to solve the problem by sending the correct date standard XX/XXXX ex 12/2021 to the API.

Sincerely yours Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.