I am trying to take the POST fields and parse them without having to hard code the string elements (like find 'amount' find the next comma, pull out the value in between). The ....php code on the receiving end is using
$data = file_get_contents('php://input');
I try to parse simple strings with JSON and they work fine, but once i add those extra { } sections digging down deeper, it starts to break. This isn't JSON, as the people who sent me the below code do not have content-type assigned. So is this format with the { } something i can easily parse with a command into an easy to read array? Or am I stuck hard-coding each string I'm looking for?
curl_setopt_array($curl, array(
CURLOPT_URL => "https://....php"
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CAINFO => (getcwd() . "/certs/cacert.pem"),
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>
"\n{\n 'event_meta_data': {\n
'event_type': 'transaction_card_sale',\n
'version': '1.0',\n
},\n
'event_data': {\n
'request': {\n
'gateway_mid': '2122',\n
'payment_channel': 'TBD',\n
'amount': '1.80',\n
'amount_cents': 180,\n
'card_brand': 'MASTERCARD',\n
'card_expiration': '1020',\n
'card_last_four': '5100',\n
'card_name': 'foo bar',\n
'invoice_number': '123456',\n
'customer_id': '12349876',\n
...More... \n} \n} \n}",
));
(I know the { } may not line up, its not the whole section, but that should be enough to get started)
I've tried this with the values above being in single quotes ' and double quotes ". I feel like i've tried to internet search anything possibly related, but haven't come up with anything correct. Thanks.
On the receiving end:
$data = file_get_contents('php://input');
echo $data."<BR>";
prints:
{ 'event_meta_data': { 'event_type': 'transaction_card_sale', 'version': '1.0', }, 'event_data': { 'request': { 'gateway_mid': '2122', 'payment_channel': 'TBD', 'amount': '1.80', 'amount_cents': 180, 'card_brand': 'MASTERCARD', 'card_expiration': '1020', 'card_last_four': '5100', 'card_name': 'foo bar', 'invoice_number': '123456', 'customer_id': '12349876', 'custom_fields': { 'AccountID': '', 'AccountIDList': '', 'AmountList': '', 'CorrespondenceUUID': '', 'MerchantID': '', 'PaymentTakenBy': '', 'FacilityName': '', } }, 'timestamp': '2016-08-05T00:15:31.769049', 'result': { 'result_code': '0', 'pn_ref': '12345', 'auth_code': 'VTLMC1', 'host_code': '12345', 'host_url': '', 'message': 'APPROVAL VTLMC1', 'message1': '', 'message2': '', 'resp_msg': 'Approved', 'get_avs_result': '0', 'get_avs_result_txt': 'Issuer did not perform AVS', 'get_commercial_card': 'False', 'get_cv_result': 'M', 'get_cv_result_txt': 'Match', 'get_get_orig_result': '', 'get_street_match_txt': 'Service Not Requested', 'get_zip_match_txt': 'Service Not Requested', } } }
credit card company~ 3rd party tell you about the data they return? Do they claim to return json?