Skip to content

Instantly share code, notes, and snippets.

@php-cpm
Last active August 25, 2023 10:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save php-cpm/d46e8cb40c30fb893ee48cb4992c1d8d to your computer and use it in GitHub Desktop.
Save php-cpm/d46e8cb40c30fb893ee48cb4992c1d8d to your computer and use it in GitHub Desktop.
apple iap App Store Server Notifications V2 parse code
<?php
$error = ['code'=>0,'msg'=>''];
$req = json_decode(file_get_contents("php://input"), true);
if (//https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv1
!isset($req['environment']) ||
//https://developer.apple.com/documentation/appstoreservernotifications/responsebodyv2
!isset($req['signedPayload']) {
$error = ['code' => 400, 'msg' => 'params error'];
return $error;
}
if(isset($req['environment'])) {
...
return ['code'=>0,'msg'=>''];
}
if(isset($req['signedPayload'])) {
list($header,$payload,$sign) = explode('.', $req['signedPayload']);
$decodePayload = base64_decode($payload);
$notificationType = $decodePayload['notificationType'];
$env = $decodePayload['data']['environment'];
$signedTransactionInfo = $decodePayload['data']['signedTransactionInfo'];
list($trans_header,$trans_payload,$trans_sign) = explode('.', $signedTransactionInfo);
$dtp = base64_decode($trans_payload);
$data = [
"transactionId"=> $dtp["transactionId"],
"originalTransactionId"=> $dtp["originalTransactionId"],
"bundleId"=> $dtp["bundleId"],
"productId"=> $dtp["productId"],
"purchaseDate"=> $dtp["purchaseDate"],
"originalPurchaseDate"=> $dtp["originalPurchaseDate"],
"quantity"=> $dtp["quantity"],
"type"=> $dtp["type"],
"inAppOwnershipType"=> $dtp["inAppOwnershipType"],
"signedDate"=> $dtp["signedDate"],
];
return ['code'=>0,'msg'=>'','data'=>$data];
}
@php-cpm
Copy link
Author

php-cpm commented Nov 8, 2021

App Store Server Notifications V2 diffs from App Store Server Notifications V1

you can only get the refund transaction Info this time

you need to check the verify api manually to get older one's status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment