我尝试为clickbank创建一个小类,从clickbank获取收据信息。我想,这可能对某人有帮助。在函数get_payment_info($尝试,$ receipt)尝试已被使用,因为clickbank在发生后不立即识别事务。
<?php
define('CLICKBANK_DEV_KEY','DEV-KEY');
define('CLICKBANK_API_KEY','API-KEY');
Class ClickBank
{
/*
* $tries how many times to check for receipt
* because when you come back from clicbank it sometimes shows it invalid
*
* $receipt
*
* @return empty array if receipt not valid
* receipt info array if receipt is valid
*/
function get_payment_info($tries, $receipt){
$receipt_info = array();
while($tries>0 && count($receipt_info)==0){
$receipt_info = $this->get_receipt_info($receipt);
$tries--;
}
return $receipt_info;
}
function get_receipt_info($receipt){
$receipt_info = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/orders/$receipt");
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Authorization:".CLICKBANK_DEV_KEY.":".CLICKBANK_API_KEY));
$result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
if($curl_info['http_code']==200){
$receipt_info = json_decode($result);
}
return $receipt_info;
}
}
$clickbank = new ClickBank();
$receipt = $_GET['cbreceipt'];
// it will return you transaction details
$transaction_info = $clickbank->get_payment_info(10, $receipt);