Reputation: 127
I am unable to parse app store auto renewable purchase notification.I am only to get notification_type, but other fileds i am unable parse from server notification. my php code:
<?php
$input =json_decode(file_get_contents('php://input'), true);
$responseBody = $input['unified_receipt']['latest_receipt_info'][0]->original_transaction_id;
$notification_type = $input['notification_type'];
$sql="INSERT INTO testAppServerNotification (notification_type,notification) VALUES('$notification_type','$responseBody')";
$result=$conn->query($sql);
if($result){
echo "success";
}else{
error_log("fail" . $conn->error);
}
?>
Upvotes: 0
Views: 592
Reputation: 1540
The boolean in json_decode()
defines that json objects should be decoded as associative arrays instead of objects. Hence you access the orignal_transaction_id
wrong.
You have to do it like this:
$responseBody = $input['unified_receipt']['latest_receipt_info'][0]["original_transaction_id"];
This way, you should be able to parse the notification.
If you want to learn more about the structure of server notifications, here is the documentation from Apple.
Upvotes: 1