PHP code example of chenkby / apple-pay
1. Go to this page and download the library: Download chenkby/apple-pay library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chenkby / apple-pay example snippets
// $orderId 本地订单号
// $storeProductId 苹果商店产品ID
// $tradeNo 苹果交易号
$order = findOrder($orderId);
$order->updateReceipt($data['receipt']);
$applePay = new ApplePay($_POST['receipt'], $orderId);
if ($applePay->verifyReceipt()) {
$result = $applePay->query($storeProductId, function ($tradeNo, $returnData) use ($order) {
// 检查此交易号是否被使用
if (!$order->checkTradeNoIsUsed($tradeNo)) {
// 更新本地订单状态等...
return $this->notify($order, $returnData, $tradeNo);
} else {
echo '此笔交易号已经被使用,这笔交易有可能是伪造的!';
return false;
}
});
if ($result) {
echo 'success';
} else {
echo $applePay->getError();
}
} else {
echo $applePay->getError();
}
bash
$ php composer.phar